Skip to content

Commit 210f855

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop AFFS from using iget() and read_inode()
Stop the AFFS filesystem from using iget() and read_inode(). Replace affs_read_inode() with affs_iget(), and call that instead of iget(). affs_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. affs_fill_super() returns any error incurred when getting the root inode instead of EINVAL. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: David Howells <dhowells@redhat.com> Cc: Roman Zippel <zippel@linux-m68k.org> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 69840b0 commit 210f855

5 files changed

Lines changed: 32 additions & 19 deletions

File tree

‎fs/affs/affs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ extern void affs_put_inode(struct inode *inode);
174174
extern void affs_drop_inode(struct inode *inode);
175175
extern void affs_delete_inode(struct inode *inode);
176176
extern void affs_clear_inode(struct inode *inode);
177-
extern void affs_read_inode(struct inode *inode);
177+
extern struct inode *affs_iget(struct super_block *sb,
178+
unsigned long ino);
178179
extern int affs_write_inode(struct inode *inode, int);
179180
extern int affs_add_entry(struct inode *dir, struct inode *inode, struct dentry *dentry, s32 type);
180181

‎fs/affs/amigaffs.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ affs_remove_link(struct dentry *dentry)
170170
if (!link_bh)
171171
goto done;
172172

173-
dir = iget(sb, be32_to_cpu(AFFS_TAIL(sb, link_bh)->parent));
174-
if (!dir)
173+
dir = affs_iget(sb, be32_to_cpu(AFFS_TAIL(sb, link_bh)->parent));
174+
if (IS_ERR(dir)) {
175+
retval = PTR_ERR(dir);
175176
goto done;
177+
}
176178

177179
affs_lock_dir(dir);
178180
affs_fix_dcache(dentry, link_ino);

‎fs/affs/inode.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@
1515
extern const struct inode_operations affs_symlink_inode_operations;
1616
extern struct timezone sys_tz;
1717

18-
void
19-
affs_read_inode(struct inode *inode)
18+
struct inode *affs_iget(struct super_block *sb, unsigned long ino)
2019
{
21-
struct super_block *sb = inode->i_sb;
2220
struct affs_sb_info *sbi = AFFS_SB(sb);
2321
struct buffer_head *bh;
2422
struct affs_head *head;
2523
struct affs_tail *tail;
24+
struct inode *inode;
2625
u32 block;
2726
u32 size;
2827
u32 prot;
2928
u16 id;
3029

31-
pr_debug("AFFS: read_inode(%lu)\n",inode->i_ino);
30+
inode = iget_locked(sb, ino);
31+
if (!inode)
32+
return ERR_PTR(-ENOMEM);
33+
if (!(inode->i_state & I_NEW))
34+
return inode;
35+
36+
pr_debug("AFFS: affs_iget(%lu)\n", inode->i_ino);
3237

3338
block = inode->i_ino;
3439
bh = affs_bread(sb, block);
@@ -154,12 +159,13 @@ affs_read_inode(struct inode *inode)
154159
sys_tz.tz_minuteswest * 60;
155160
inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = inode->i_atime.tv_nsec = 0;
156161
affs_brelse(bh);
157-
return;
162+
unlock_new_inode(inode);
163+
return inode;
158164

159165
bad_inode:
160-
make_bad_inode(inode);
161166
affs_brelse(bh);
162-
return;
167+
iget_failed(inode);
168+
return ERR_PTR(-EIO);
163169
}
164170

165171
int

‎fs/affs/namei.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ affs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
208208
affs_lock_dir(dir);
209209
bh = affs_find_entry(dir, dentry);
210210
affs_unlock_dir(dir);
211-
if (IS_ERR(bh)) {
211+
if (IS_ERR(bh))
212212
return ERR_CAST(bh);
213-
}
214213
if (bh) {
215214
u32 ino = bh->b_blocknr;
216215

@@ -223,10 +222,9 @@ affs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
223222
ino = be32_to_cpu(AFFS_TAIL(sb, bh)->original);
224223
}
225224
affs_brelse(bh);
226-
inode = iget(sb, ino);
227-
if (!inode) {
228-
return ERR_PTR(-EACCES);
229-
}
225+
inode = affs_iget(sb, ino);
226+
if (IS_ERR(inode))
227+
return ERR_PTR(PTR_ERR(inode));
230228
}
231229
dentry->d_op = AFFS_SB(sb)->s_flags & SF_INTL ? &affs_intl_dentry_operations : &affs_dentry_operations;
232230
d_add(dentry, inode);

‎fs/affs/super.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ static void destroy_inodecache(void)
113113
static const struct super_operations affs_sops = {
114114
.alloc_inode = affs_alloc_inode,
115115
.destroy_inode = affs_destroy_inode,
116-
.read_inode = affs_read_inode,
117116
.write_inode = affs_write_inode,
118117
.put_inode = affs_put_inode,
119118
.drop_inode = affs_drop_inode,
@@ -271,6 +270,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
271270
unsigned long mount_flags;
272271
int tmp_flags; /* fix remount prototype... */
273272
u8 sig[4];
273+
int ret = -EINVAL;
274274

275275
pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options");
276276

@@ -444,7 +444,12 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
444444

445445
/* set up enough so that it can read an inode */
446446

447-
root_inode = iget(sb, root_block);
447+
root_inode = affs_iget(sb, root_block);
448+
if (IS_ERR(root_inode)) {
449+
ret = PTR_ERR(root_inode);
450+
goto out_error_noinode;
451+
}
452+
448453
sb->s_root = d_alloc_root(root_inode);
449454
if (!sb->s_root) {
450455
printk(KERN_ERR "AFFS: Get root inode failed\n");
@@ -461,12 +466,13 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
461466
out_error:
462467
if (root_inode)
463468
iput(root_inode);
469+
out_error_noinode:
464470
kfree(sbi->s_bitmap);
465471
affs_brelse(root_bh);
466472
kfree(sbi->s_prefix);
467473
kfree(sbi);
468474
sb->s_fs_info = NULL;
469-
return -EINVAL;
475+
return ret;
470476
}
471477

472478
static int

0 commit comments

Comments
 (0)