Move the lookup of the inode table block that holds an inode out of ext2_get_inode() into a helper. ext2_sync_inode_metadata() is going to use it to find the block without reading it from disk. No functional changes. Cc: stable@vger.kernel.org # v7.3 Reviewed-by: Jan Kara Signed-off-by: Christian Brauner (Amutable) --- fs/ext2/inode.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 12ac4cfe1500..aecd8528ea36 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -1272,46 +1272,59 @@ static int ext2_setsize(struct inode *inode, loff_t newsize) return 0; } -static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino, - struct buffer_head **p) +/* + * Find the inode table block that holds inode @ino and the offset of the + * inode in that block. + */ +static int ext2_inode_block(struct super_block *sb, ino_t ino, + unsigned long *block, unsigned long *offset) { - struct buffer_head * bh; unsigned long block_group; - unsigned long block; - unsigned long offset; struct ext2_group_desc * gdp; - *p = NULL; if ((ino != EXT2_ROOT_INO && ino < EXT2_FIRST_INO(sb)) || - ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count)) - goto Einval; + ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count)) { + ext2_error(sb, __func__, "bad inode number: %lu", + (unsigned long) ino); + return -EINVAL; + } block_group = (ino - 1) / EXT2_INODES_PER_GROUP(sb); gdp = ext2_get_group_desc(sb, block_group, NULL); if (!gdp) - goto Egdp; + return -EIO; /* * Figure out the offset within the block group inode table */ - offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb); - block = le32_to_cpu(gdp->bg_inode_table) + - (offset >> EXT2_BLOCK_SIZE_BITS(sb)); + *offset = ((ino - 1) % EXT2_INODES_PER_GROUP(sb)) * EXT2_INODE_SIZE(sb); + *block = le32_to_cpu(gdp->bg_inode_table) + + (*offset >> EXT2_BLOCK_SIZE_BITS(sb)); + *offset &= (EXT2_BLOCK_SIZE(sb) - 1); + return 0; +} + +static struct ext2_inode *ext2_get_inode(struct super_block *sb, ino_t ino, + struct buffer_head **p) +{ + struct buffer_head *bh; + unsigned long block; + unsigned long offset; + int err; + + *p = NULL; + err = ext2_inode_block(sb, ino, &block, &offset); + if (err) + return ERR_PTR(err); if (!(bh = sb_bread(sb, block))) goto Eio; *p = bh; - offset &= (EXT2_BLOCK_SIZE(sb) - 1); return (struct ext2_inode *) (bh->b_data + offset); -Einval: - ext2_error(sb, "ext2_get_inode", "bad inode number: %lu", - (unsigned long) ino); - return ERR_PTR(-EINVAL); Eio: ext2_error(sb, "ext2_get_inode", "unable to read inode block - inode=%lu, block=%lu", (unsigned long) ino, block); -Egdp: return ERR_PTR(-EIO); } -- 2.53.0