Commit 78cc9120003d7847ef1abebb771a708c7ae51ffd

Authored by David Howells
Committed by Linus Torvalds
1 parent 2b7e5bcbd9

iget: stop ROMFS from using iget() and read_inode()

Stop the ROMFS filesystem from using iget() and read_inode().  Replace
romfs_read_inode() with romfs_iget(), and call that instead of iget().
romfs_iget() then uses iget_locked() directly and returns a proper error code
instead of an inode in the event of an error.

romfs_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>
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>

Showing 1 changed file with 32 additions and 14 deletions Side-by-side Diff

... ... @@ -84,6 +84,8 @@
84 84 struct inode vfs_inode;
85 85 };
86 86  
  87 +static struct inode *romfs_iget(struct super_block *, unsigned long);
  88 +
87 89 /* instead of private superblock data */
88 90 static inline unsigned long romfs_maxsize(struct super_block *sb)
89 91 {
... ... @@ -117,7 +119,7 @@
117 119 struct buffer_head *bh;
118 120 struct romfs_super_block *rsb;
119 121 struct inode *root;
120   - int sz;
  122 + int sz, ret = -EINVAL;
121 123  
122 124 /* I would parse the options here, but there are none.. :) */
123 125  
124 126  
125 127  
... ... @@ -157,10 +159,13 @@
157 159 & ROMFH_MASK;
158 160  
159 161 s->s_op = &romfs_ops;
160   - root = iget(s, sz);
161   - if (!root)
  162 + root = romfs_iget(s, sz);
  163 + if (IS_ERR(root)) {
  164 + ret = PTR_ERR(root);
162 165 goto out;
  166 + }
163 167  
  168 + ret = -ENOMEM;
164 169 s->s_root = d_alloc_root(root);
165 170 if (!s->s_root)
166 171 goto outiput;
... ... @@ -173,7 +178,7 @@
173 178 out:
174 179 brelse(bh);
175 180 outnobh:
176   - return -EINVAL;
  181 + return ret;
177 182 }
178 183  
179 184 /* That's simple too. */
... ... @@ -389,8 +394,11 @@
389 394 if ((be32_to_cpu(ri.next) & ROMFH_TYPE) == ROMFH_HRD)
390 395 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
391 396  
392   - if ((inode = iget(dir->i_sb, offset)))
393   - goto outi;
  397 + inode = romfs_iget(dir->i_sb, offset);
  398 + if (IS_ERR(inode)) {
  399 + res = PTR_ERR(inode);
  400 + goto out;
  401 + }
394 402  
395 403 /*
396 404 * it's a bit funky, _lookup needs to return an error code
... ... @@ -402,7 +410,7 @@
402 410 */
403 411  
404 412 out0: inode = NULL;
405   -outi: res = 0;
  413 + res = 0;
406 414 d_add (dentry, inode);
407 415  
408 416 out: unlock_kernel();
409 417  
410 418  
411 419  
412 420  
... ... @@ -478,20 +486,29 @@
478 486 S_IFBLK+0600, S_IFCHR+0600, S_IFSOCK+0644, S_IFIFO+0644
479 487 };
480 488  
481   -static void
482   -romfs_read_inode(struct inode *i)
  489 +static struct inode *
  490 +romfs_iget(struct super_block *sb, unsigned long ino)
483 491 {
484   - int nextfh, ino;
  492 + int nextfh;
485 493 struct romfs_inode ri;
  494 + struct inode *i;
486 495  
487   - ino = i->i_ino & ROMFH_MASK;
  496 + ino &= ROMFH_MASK;
  497 + i = iget_locked(sb, ino);
  498 + if (!i)
  499 + return ERR_PTR(-ENOMEM);
  500 + if (!(i->i_state & I_NEW))
  501 + return i;
  502 +
488 503 i->i_mode = 0;
489 504  
490 505 /* Loop for finding the real hard link */
491 506 for(;;) {
492 507 if (romfs_copyfrom(i, &ri, ino, ROMFH_SIZE) <= 0) {
493   - printk("romfs: read error for inode 0x%x\n", ino);
494   - return;
  508 + printk(KERN_ERR "romfs: read error for inode 0x%lx\n",
  509 + ino);
  510 + iget_failed(i);
  511 + return ERR_PTR(-EIO);
495 512 }
496 513 /* XXX: do romfs_checksum here too (with name) */
497 514  
... ... @@ -548,6 +565,8 @@
548 565 init_special_inode(i, ino,
549 566 MKDEV(nextfh>>16,nextfh&0xffff));
550 567 }
  568 + unlock_new_inode(i);
  569 + return i;
551 570 }
552 571  
553 572 static struct kmem_cache * romfs_inode_cachep;
... ... @@ -599,7 +618,6 @@
599 618 static const struct super_operations romfs_ops = {
600 619 .alloc_inode = romfs_alloc_inode,
601 620 .destroy_inode = romfs_destroy_inode,
602   - .read_inode = romfs_read_inode,
603 621 .statfs = romfs_statfs,
604 622 .remount_fs = romfs_remount,
605 623 };