Skip to content

Commit c4386c8

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: stop ISOFS from using read_inode()
Stop the ISOFS filesystem from using read_inode(). Make isofs_read_inode() return an error code, and make isofs_iget() pass it on. Signed-off-by: David Howells <[email protected]> Cc: Jan Kara <[email protected]> Acked-by: Christoph Hellwig <[email protected]> Cc: "Dave Young" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6352539 commit c4386c8

File tree

4 files changed

+58
-32
lines changed

4 files changed

+58
-32
lines changed

fs/isofs/export.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ isofs_export_iget(struct super_block *sb,
2626
if (block == 0)
2727
return ERR_PTR(-ESTALE);
2828
inode = isofs_iget(sb, block, offset);
29-
if (inode == NULL)
30-
return ERR_PTR(-ENOMEM);
31-
if (is_bad_inode(inode)
32-
|| (generation && inode->i_generation != generation))
33-
{
29+
if (IS_ERR(inode))
30+
return ERR_CAST(inode);
31+
if (generation && inode->i_generation != generation) {
3432
iput(inode);
3533
return ERR_PTR(-ESTALE);
3634
}
@@ -110,8 +108,10 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
110108
parent_inode = isofs_iget(child_inode->i_sb,
111109
parent_block,
112110
parent_offset);
113-
if (parent_inode == NULL) {
114-
rv = ERR_PTR(-EACCES);
111+
if (IS_ERR(parent_inode)) {
112+
rv = ERR_CAST(parent_inode);
113+
if (rv != ERR_PTR(-ENOMEM))
114+
rv = ERR_PTR(-EACCES);
115115
goto out;
116116
}
117117

fs/isofs/inode.c

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void isofs_put_super(struct super_block *sb)
5454
return;
5555
}
5656

57-
static void isofs_read_inode(struct inode *);
57+
static int isofs_read_inode(struct inode *);
5858
static int isofs_statfs (struct dentry *, struct kstatfs *);
5959

6060
static struct kmem_cache *isofs_inode_cachep;
@@ -107,7 +107,6 @@ static int isofs_remount(struct super_block *sb, int *flags, char *data)
107107
static const struct super_operations isofs_sops = {
108108
.alloc_inode = isofs_alloc_inode,
109109
.destroy_inode = isofs_destroy_inode,
110-
.read_inode = isofs_read_inode,
111110
.put_super = isofs_put_super,
112111
.statfs = isofs_statfs,
113112
.remount_fs = isofs_remount,
@@ -552,7 +551,7 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
552551
int joliet_level = 0;
553552
int iso_blknum, block;
554553
int orig_zonesize;
555-
int table;
554+
int table, error = -EINVAL;
556555
unsigned int vol_desc_start;
557556

558557
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
@@ -810,6 +809,8 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
810809
* we then decide whether to use the Joliet descriptor.
811810
*/
812811
inode = isofs_iget(s, sbi->s_firstdatazone, 0);
812+
if (IS_ERR(inode))
813+
goto out_no_root;
813814

814815
/*
815816
* If this disk has both Rock Ridge and Joliet on it, then we
@@ -829,6 +830,8 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
829830
"ISOFS: changing to secondary root\n");
830831
iput(inode);
831832
inode = isofs_iget(s, sbi->s_firstdatazone, 0);
833+
if (IS_ERR(inode))
834+
goto out_no_root;
832835
}
833836
}
834837

@@ -842,8 +845,6 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
842845
sbi->s_joliet_level = joliet_level;
843846

844847
/* check the root inode */
845-
if (!inode)
846-
goto out_no_root;
847848
if (!inode->i_op)
848849
goto out_bad_root;
849850

@@ -876,11 +877,14 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
876877
*/
877878
out_bad_root:
878879
printk(KERN_WARNING "%s: root inode not initialized\n", __func__);
879-
goto out_iput;
880-
out_no_root:
881-
printk(KERN_WARNING "%s: get root inode failed\n", __func__);
882880
out_iput:
883881
iput(inode);
882+
goto out_no_inode;
883+
out_no_root:
884+
error = PTR_ERR(inode);
885+
if (error != -ENOMEM)
886+
printk(KERN_WARNING "%s: get root inode failed\n", __func__);
887+
out_no_inode:
884888
#ifdef CONFIG_JOLIET
885889
if (sbi->s_nls_iocharset)
886890
unload_nls(sbi->s_nls_iocharset);
@@ -908,7 +912,7 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
908912
kfree(opt.iocharset);
909913
kfree(sbi);
910914
s->s_fs_info = NULL;
911-
return -EINVAL;
915+
return error;
912916
}
913917

914918
static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
@@ -930,7 +934,7 @@ static int isofs_statfs (struct dentry *dentry, struct kstatfs *buf)
930934
/*
931935
* Get a set of blocks; filling in buffer_heads if already allocated
932936
* or getblk() if they are not. Returns the number of blocks inserted
933-
* (0 == error.)
937+
* (-ve == error.)
934938
*/
935939
int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
936940
struct buffer_head **bh, unsigned long nblocks)
@@ -940,11 +944,12 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
940944
unsigned int firstext;
941945
unsigned long nextblk, nextoff;
942946
long iblock = (long)iblock_s;
943-
int section, rv;
947+
int section, rv, error;
944948
struct iso_inode_info *ei = ISOFS_I(inode);
945949

946950
lock_kernel();
947951

952+
error = -EIO;
948953
rv = 0;
949954
if (iblock < 0 || iblock != iblock_s) {
950955
printk(KERN_DEBUG "%s: block number too large\n", __func__);
@@ -983,8 +988,10 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
983988

984989
offset += sect_size;
985990
ninode = isofs_iget(inode->i_sb, nextblk, nextoff);
986-
if (!ninode)
991+
if (IS_ERR(ninode)) {
992+
error = PTR_ERR(ninode);
987993
goto abort;
994+
}
988995
firstext = ISOFS_I(ninode)->i_first_extent;
989996
sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode);
990997
nextblk = ISOFS_I(ninode)->i_next_section_block;
@@ -1015,9 +1022,10 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
10151022
rv++;
10161023
}
10171024

1025+
error = 0;
10181026
abort:
10191027
unlock_kernel();
1020-
return rv;
1028+
return rv != 0 ? rv : error;
10211029
}
10221030

10231031
/*
@@ -1026,12 +1034,15 @@ int isofs_get_blocks(struct inode *inode, sector_t iblock_s,
10261034
static int isofs_get_block(struct inode *inode, sector_t iblock,
10271035
struct buffer_head *bh_result, int create)
10281036
{
1037+
int ret;
1038+
10291039
if (create) {
10301040
printk(KERN_DEBUG "%s: Kernel tries to allocate a block\n", __func__);
10311041
return -EROFS;
10321042
}
10331043

1034-
return isofs_get_blocks(inode, iblock, &bh_result, 1) ? 0 : -EIO;
1044+
ret = isofs_get_blocks(inode, iblock, &bh_result, 1);
1045+
return ret < 0 ? ret : 0;
10351046
}
10361047

10371048
static int isofs_bmap(struct inode *inode, sector_t block)
@@ -1186,7 +1197,7 @@ static int isofs_read_level3_size(struct inode *inode)
11861197
goto out;
11871198
}
11881199

1189-
static void isofs_read_inode(struct inode *inode)
1200+
static int isofs_read_inode(struct inode *inode)
11901201
{
11911202
struct super_block *sb = inode->i_sb;
11921203
struct isofs_sb_info *sbi = ISOFS_SB(sb);
@@ -1199,6 +1210,7 @@ static void isofs_read_inode(struct inode *inode)
11991210
unsigned int de_len;
12001211
unsigned long offset;
12011212
struct iso_inode_info *ei = ISOFS_I(inode);
1213+
int ret = -EIO;
12021214

12031215
block = ei->i_iget5_block;
12041216
bh = sb_bread(inode->i_sb, block);
@@ -1216,6 +1228,7 @@ static void isofs_read_inode(struct inode *inode)
12161228
tmpde = kmalloc(de_len, GFP_KERNEL);
12171229
if (tmpde == NULL) {
12181230
printk(KERN_INFO "%s: out of memory\n", __func__);
1231+
ret = -ENOMEM;
12191232
goto fail;
12201233
}
12211234
memcpy(tmpde, bh->b_data + offset, frag1);
@@ -1259,8 +1272,10 @@ static void isofs_read_inode(struct inode *inode)
12591272

12601273
ei->i_section_size = isonum_733(de->size);
12611274
if (de->flags[-high_sierra] & 0x80) {
1262-
if(isofs_read_level3_size(inode))
1275+
ret = isofs_read_level3_size(inode);
1276+
if (ret < 0)
12631277
goto fail;
1278+
ret = -EIO;
12641279
} else {
12651280
ei->i_next_section_block = 0;
12661281
ei->i_next_section_offset = 0;
@@ -1346,16 +1361,16 @@ static void isofs_read_inode(struct inode *inode)
13461361
/* XXX - parse_rock_ridge_inode() had already set i_rdev. */
13471362
init_special_inode(inode, inode->i_mode, inode->i_rdev);
13481363

1364+
ret = 0;
13491365
out:
13501366
kfree(tmpde);
13511367
if (bh)
13521368
brelse(bh);
1353-
return;
1369+
return ret;
13541370

13551371
out_badread:
13561372
printk(KERN_WARNING "ISOFS: unable to read i-node block\n");
13571373
fail:
1358-
make_bad_inode(inode);
13591374
goto out;
13601375
}
13611376

@@ -1394,9 +1409,10 @@ struct inode *isofs_iget(struct super_block *sb,
13941409
unsigned long hashval;
13951410
struct inode *inode;
13961411
struct isofs_iget5_callback_data data;
1412+
long ret;
13971413

13981414
if (offset >= 1ul << sb->s_blocksize_bits)
1399-
return NULL;
1415+
return ERR_PTR(-EINVAL);
14001416

14011417
data.block = block;
14021418
data.offset = offset;
@@ -1406,9 +1422,17 @@ struct inode *isofs_iget(struct super_block *sb,
14061422
inode = iget5_locked(sb, hashval, &isofs_iget5_test,
14071423
&isofs_iget5_set, &data);
14081424

1409-
if (inode && (inode->i_state & I_NEW)) {
1410-
sb->s_op->read_inode(inode);
1411-
unlock_new_inode(inode);
1425+
if (!inode)
1426+
return ERR_PTR(-ENOMEM);
1427+
1428+
if (inode->i_state & I_NEW) {
1429+
ret = isofs_read_inode(inode);
1430+
if (ret < 0) {
1431+
iget_failed(inode);
1432+
inode = ERR_PTR(ret);
1433+
} else {
1434+
unlock_new_inode(inode);
1435+
}
14121436
}
14131437

14141438
return inode;

fs/isofs/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ struct dentry *isofs_lookup(struct inode *dir, struct dentry *dentry, struct nam
179179
inode = NULL;
180180
if (found) {
181181
inode = isofs_iget(dir->i_sb, block, offset);
182-
if (!inode) {
182+
if (IS_ERR(inode)) {
183183
unlock_kernel();
184-
return ERR_PTR(-EACCES);
184+
return ERR_CAST(inode);
185185
}
186186
}
187187
unlock_kernel();

fs/isofs/rock.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,10 @@ parse_rock_ridge_inode_internal(struct iso_directory_record *de,
474474
isofs_iget(inode->i_sb,
475475
ISOFS_I(inode)->i_first_extent,
476476
0);
477-
if (!reloc)
477+
if (IS_ERR(reloc)) {
478+
ret = PTR_ERR(reloc);
478479
goto out;
480+
}
479481
inode->i_mode = reloc->i_mode;
480482
inode->i_nlink = reloc->i_nlink;
481483
inode->i_uid = reloc->i_uid;

0 commit comments

Comments
 (0)