diff options
author | David Howells <dhowells@redhat.com> | 2008-03-19 20:00:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-03-19 21:53:36 -0400 |
commit | 4ebf89845bea44a164d1fbb8fa319379ec7132de (patch) | |
tree | f5b87ddbf858ee0a1d9f0177a0c058b81f352c45 /fs | |
parent | c587f0c0a69227587baaa12e75815b6644457c0a (diff) |
ROMFS: Fix up an error in iget removal
Fix up an error in iget removal in which romfs_lookup() making a successful
call to romfs_iget() continues through the negative/error handling (previously
the successful case jumped around the negative/error handling case):
(1) inode is initialised to NULL at the top of the function, eliminating the
need for specific negative-inode handling. This means the positive
success handling now flows straight through.
(2) Rename the labels to be clearer about what they mean.
Also make romfs_lookup()'s result variable of type long so as to avoid
32-bit/64-bit conversions with PTR_ERR() and friends.
Based upon a report and patch from Adam Richter.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: "Adam J. Richter" <adam@yggdrasil.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/romfs/inode.c | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/fs/romfs/inode.c b/fs/romfs/inode.c index 00b6f0a518c8..3f13d491c7c7 100644 --- a/fs/romfs/inode.c +++ b/fs/romfs/inode.c | |||
@@ -340,8 +340,9 @@ static struct dentry * | |||
340 | romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | 340 | romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
341 | { | 341 | { |
342 | unsigned long offset, maxoff; | 342 | unsigned long offset, maxoff; |
343 | int fslen, res; | 343 | long res; |
344 | struct inode *inode; | 344 | int fslen; |
345 | struct inode *inode = NULL; | ||
345 | char fsname[ROMFS_MAXFN]; /* XXX dynamic? */ | 346 | char fsname[ROMFS_MAXFN]; /* XXX dynamic? */ |
346 | struct romfs_inode ri; | 347 | struct romfs_inode ri; |
347 | const char *name; /* got from dentry */ | 348 | const char *name; /* got from dentry */ |
@@ -351,7 +352,7 @@ romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | |||
351 | offset = dir->i_ino & ROMFH_MASK; | 352 | offset = dir->i_ino & ROMFH_MASK; |
352 | lock_kernel(); | 353 | lock_kernel(); |
353 | if (romfs_copyfrom(dir, &ri, offset, ROMFH_SIZE) <= 0) | 354 | if (romfs_copyfrom(dir, &ri, offset, ROMFH_SIZE) <= 0) |
354 | goto out; | 355 | goto error; |
355 | 356 | ||
356 | maxoff = romfs_maxsize(dir->i_sb); | 357 | maxoff = romfs_maxsize(dir->i_sb); |
357 | offset = be32_to_cpu(ri.spec) & ROMFH_MASK; | 358 | offset = be32_to_cpu(ri.spec) & ROMFH_MASK; |
@@ -364,9 +365,9 @@ romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | |||
364 | 365 | ||
365 | for(;;) { | 366 | for(;;) { |
366 | if (!offset || offset >= maxoff) | 367 | if (!offset || offset >= maxoff) |
367 | goto out0; | 368 | goto success; /* negative success */ |
368 | if (romfs_copyfrom(dir, &ri, offset, ROMFH_SIZE) <= 0) | 369 | if (romfs_copyfrom(dir, &ri, offset, ROMFH_SIZE) <= 0) |
369 | goto out; | 370 | goto error; |
370 | 371 | ||
371 | /* try to match the first 16 bytes of name */ | 372 | /* try to match the first 16 bytes of name */ |
372 | fslen = romfs_strnlen(dir, offset+ROMFH_SIZE, ROMFH_SIZE); | 373 | fslen = romfs_strnlen(dir, offset+ROMFH_SIZE, ROMFH_SIZE); |
@@ -397,23 +398,14 @@ romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | |||
397 | inode = romfs_iget(dir->i_sb, offset); | 398 | inode = romfs_iget(dir->i_sb, offset); |
398 | if (IS_ERR(inode)) { | 399 | if (IS_ERR(inode)) { |
399 | res = PTR_ERR(inode); | 400 | res = PTR_ERR(inode); |
400 | goto out; | 401 | goto error; |
401 | } | 402 | } |
402 | 403 | ||
403 | /* | 404 | success: |
404 | * it's a bit funky, _lookup needs to return an error code | 405 | d_add(dentry, inode); |
405 | * (negative) or a NULL, both as a dentry. ENOENT should not | ||
406 | * be returned, instead we need to create a negative dentry by | ||
407 | * d_add(dentry, NULL); and return 0 as no error. | ||
408 | * (Although as I see, it only matters on writable file | ||
409 | * systems). | ||
410 | */ | ||
411 | |||
412 | out0: inode = NULL; | ||
413 | res = 0; | 406 | res = 0; |
414 | d_add (dentry, inode); | 407 | error: |
415 | 408 | unlock_kernel(); | |
416 | out: unlock_kernel(); | ||
417 | return ERR_PTR(res); | 409 | return ERR_PTR(res); |
418 | } | 410 | } |
419 | 411 | ||