* passing positive numbers to ERR_PTR()
@ 2012-02-08 9:18 Dan Carpenter
2012-02-08 15:01 ` [PATCH] Btrfs: avoid positive number with ERR_PTR Jan Schmidt
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-02-08 9:18 UTC (permalink / raw)
To: Jan Schmidt; +Cc: linux-btrfs
Hi Jan,
Smatch complains when you pass positive numbers to ERR_PTR(). There
is a warning triggered in iref_to_path().
fs/btrfs/backref.c +920 iref_to_path()
918
919 if (ret)
920 return ERR_PTR(ret);
^^^
"ret" can be either a negative error code, zero, or one here.
921
I looked at the code, but couldn't tell if it was intentional or not.
It really is pretty unusual to do that, so maybe there should be a
comment or something.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] Btrfs: avoid positive number with ERR_PTR
2012-02-08 9:18 passing positive numbers to ERR_PTR() Dan Carpenter
@ 2012-02-08 15:01 ` Jan Schmidt
0 siblings, 0 replies; 2+ messages in thread
From: Jan Schmidt @ 2012-02-08 15:01 UTC (permalink / raw)
To: dan.carpenter, chris.mason; +Cc: linux-btrfs
inode_ref_info() returns 1 when the element wasn't found and < 0 on error,
just like btrfs_search_slot(). In iref_to_path() it's an error when the
inode ref can't be found, thus we return ERR_PTR(ret) in that case. In order
to avoid ERR_PTR(1), we now set ret to -ENOENT in that case.
Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
---
On 08.02.2012 10:18, Dan Carpenter wrote:
> I looked at the code, but couldn't tell if it was intentional or not.
It wasn't :-)
Thank you,
-Jan
---
fs/btrfs/backref.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
---
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 633c701..98f6bf10 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -892,6 +892,8 @@ static char *iref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
if (eb != eb_in)
free_extent_buffer(eb);
ret = inode_ref_info(parent, 0, fs_root, path, &found_key);
+ if (ret > 0)
+ ret = -ENOENT;
if (ret)
break;
next_inum = found_key.offset;
--
1.7.3.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-08 15:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08 9:18 passing positive numbers to ERR_PTR() Dan Carpenter
2012-02-08 15:01 ` [PATCH] Btrfs: avoid positive number with ERR_PTR Jan Schmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).