Skip to content

Commit 96eb541

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop BEFS from using iget() and read_inode()
Stop the BEFS filesystem from using iget() and read_inode(). Replace befs_read_inode() with befs_iget(), and call that instead of iget(). befs_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. befs_fill_super() returns any error incurred when getting the root inode instead of EINVAL. Signed-off-by: David Howells <[email protected]> Acked-by: Will Dyson <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 62328a0 commit 96eb541

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

fs/befs/linuxvfs.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int befs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3535
static int befs_readpage(struct file *file, struct page *page);
3636
static sector_t befs_bmap(struct address_space *mapping, sector_t block);
3737
static struct dentry *befs_lookup(struct inode *, struct dentry *, struct nameidata *);
38-
static void befs_read_inode(struct inode *ino);
38+
static struct inode *befs_iget(struct super_block *, unsigned long);
3939
static struct inode *befs_alloc_inode(struct super_block *sb);
4040
static void befs_destroy_inode(struct inode *inode);
4141
static int befs_init_inodecache(void);
@@ -52,7 +52,6 @@ static int befs_statfs(struct dentry *, struct kstatfs *);
5252
static int parse_options(char *, befs_mount_options *);
5353

5454
static const struct super_operations befs_sops = {
55-
.read_inode = befs_read_inode, /* initialize & read inode */
5655
.alloc_inode = befs_alloc_inode, /* allocate a new inode */
5756
.destroy_inode = befs_destroy_inode, /* deallocate an inode */
5857
.put_super = befs_put_super, /* uninit super */
@@ -198,9 +197,9 @@ befs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
198197
return ERR_PTR(-ENODATA);
199198
}
200199

201-
inode = iget(dir->i_sb, (ino_t) offset);
202-
if (!inode)
203-
return ERR_PTR(-EACCES);
200+
inode = befs_iget(dir->i_sb, (ino_t) offset);
201+
if (IS_ERR(inode))
202+
return ERR_CAST(inode);
204203

205204
d_add(dentry, inode);
206205

@@ -296,17 +295,23 @@ static void init_once(struct kmem_cache *cachep, void *foo)
296295
inode_init_once(&bi->vfs_inode);
297296
}
298297

299-
static void
300-
befs_read_inode(struct inode *inode)
298+
static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
301299
{
302300
struct buffer_head *bh = NULL;
303301
befs_inode *raw_inode = NULL;
304302

305-
struct super_block *sb = inode->i_sb;
306303
befs_sb_info *befs_sb = BEFS_SB(sb);
307304
befs_inode_info *befs_ino = NULL;
305+
struct inode *inode;
306+
long ret = -EIO;
308307

309-
befs_debug(sb, "---> befs_read_inode() " "inode = %lu", inode->i_ino);
308+
befs_debug(sb, "---> befs_read_inode() " "inode = %lu", ino);
309+
310+
inode = iget_locked(sb, ino);
311+
if (IS_ERR(inode))
312+
return inode;
313+
if (!(inode->i_state & I_NEW))
314+
return inode;
310315

311316
befs_ino = BEFS_I(inode);
312317

@@ -402,15 +407,16 @@ befs_read_inode(struct inode *inode)
402407

403408
brelse(bh);
404409
befs_debug(sb, "<--- befs_read_inode()");
405-
return;
410+
unlock_new_inode(inode);
411+
return inode;
406412

407413
unacquire_bh:
408414
brelse(bh);
409415

410416
unacquire_none:
411-
make_bad_inode(inode);
417+
iget_failed(inode);
412418
befs_debug(sb, "<--- befs_read_inode() - Bad inode");
413-
return;
419+
return ERR_PTR(ret);
414420
}
415421

416422
/* Initialize the inode cache. Called at fs setup.
@@ -752,6 +758,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
752758
befs_sb_info *befs_sb;
753759
befs_super_block *disk_sb;
754760
struct inode *root;
761+
long ret = -EINVAL;
755762

756763
const unsigned long sb_block = 0;
757764
const off_t x86_sb_off = 512;
@@ -833,7 +840,11 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
833840
/* Set real blocksize of fs */
834841
sb_set_blocksize(sb, (ulong) befs_sb->block_size);
835842
sb->s_op = (struct super_operations *) &befs_sops;
836-
root = iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
843+
root = befs_iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
844+
if (IS_ERR(root)) {
845+
ret = PTR_ERR(root);
846+
goto unacquire_priv_sbp;
847+
}
837848
sb->s_root = d_alloc_root(root);
838849
if (!sb->s_root) {
839850
iput(root);
@@ -868,7 +879,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
868879

869880
unacquire_none:
870881
sb->s_fs_info = NULL;
871-
return -EINVAL;
882+
return ret;
872883
}
873884

874885
static int

0 commit comments

Comments
 (0)