I am a newbie trying to study about filesystem, when i am reviewing code with minix filesystem, i think the function 'alloc_branch' in the file 'itree_common.c' lack the necessary check about IO ERROR. As we know 'sb_getblk' may fail,but it dosen't do necessary check with it. Signed-off-by: Wang shilong <wangshilong1991@xxxxxxxxx> --- fs/minix/itree_common.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/minix/itree_common.c b/fs/minix/itree_common.c index a731cab..e5a61f8 100644 --- a/fs/minix/itree_common.c +++ b/fs/minix/itree_common.c @@ -73,17 +73,28 @@ static int alloc_branch(struct inode *inode, { int n = 0; int i; + int err = 0; int parent = minix_new_block(inode); + if (!parent) { + err = -ENOSPC; + goto failed; + } branch[0].key = cpu_to_block(parent); - if (parent) for (n = 1; n < num; n++) { + for (n = 1; n < num; n++) { struct buffer_head *bh; /* Allocate the next block */ int nr = minix_new_block(inode); - if (!nr) - break; + if (!nr) { + err = -ENOSPC; + goto failed; + } branch[n].key = cpu_to_block(nr); bh = sb_getblk(inode->i_sb, parent); + if (!bh) { + err = -EIO; + goto failed; + } lock_buffer(bh); memset(bh->b_data, 0, bh->b_size); branch[n].bh = bh; @@ -95,14 +106,14 @@ static int alloc_branch(struct inode *inode, parent = nr; } if (n == num) - return 0; - + return err; +failed: /* Allocation failed, free what we already allocated */ for (i = 1; i < n; i++) bforget(branch[i].bh); for (i = 0; i < n; i++) minix_free_block(inode, block_to_cpu(branch[i].key)); - return -ENOSPC; + return err; } static inline int splice_branch(struct inode *inode, -- 1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html