error handling of ERR_PTR() returns
PATCH 1/1 error handling of ERR_PTR() returns
There are a couple functions which return ERR_PTR as well as NULL. The caller needs to handle both.
Smatch also complains about the handling of alloc_extent_map() but as far as I can see that doesn't actually return an ERR_PTR.
Compile tested on 2.6.29.
regards,
dan carpenter
fs/btrfs/disk-io.c +4 -4
@@ -123,7 +123,7 @@spin_lock (&em_tree->lock); em =lookup_extent_mapping (em_tree, start, len); -if (em) { +if (!IS_ERR (em) && em) { em->bdev =BTRFS_I (inode)->root->fs_info->fs_devices->latest_bdev;spin_unlock (&em_tree->lock);
@@ -1216,8 +1216,8 @@int ret; root =btrfs_read_fs_root_no_name (fs_info, location); -if (!root) -return NULL ; +if (!root ||IS_ERR (root)) +return root;if (root->in_sysfs)return root;
@@ -1324,7 +1324,7 @@spin_lock (&em_tree->lock); em =lookup_extent_mapping (em_tree, offset,PAGE_CACHE_SIZE );spin_unlock (&em_tree->lock); -if (!em) { +if (!em ||IS_ERR (em)) {__unplug_io_fn (bdi, page);return ; }
Since both NULL ptr and IS_ERR(ptr) are treated as error, why not redefine IS_ERR to handle both, simplifying caller's life?
Regards,
Andrey
On Tue, Apr 7, 2009 at 5:38 PM, Dan Carpenter <[email protected]> wrote= :
Quoted 1 line
There are a couple functions which return
ERR_PTRas well as NULL. =C2=
=A0The
Quoted 3 lines
caller needs to handle both.
Smatch also complains about the handling of
alloc_extent_map()but as=
far
Quoted 8 lines
as I can see that doesn't actually return an
ERR_PTR.Compile tested on 2.6.29.
regards,
dan carpenter---
orig/fs/btrfs/disk-io.c=C2=A0 =C2=A0 2009-04-07 16:15:36.0000000=
00 +0300
Quoted 1 line
+++
devel/fs/btrfs/disk-io.c=C2=A0 =C2=A02009-04-07 16:23:33.0000000=
00 +0300
Quoted 4 lines
(quoted diff) +0
-0@@ -123,7 +123,7 @@ =C2=A0 =C2=A0 =C2=A0 =C2=A0spin_lock(&em_tree->lock);=C2=A0 =C2=A0 =C2=A0 =C2=A0em =3D lookup_extent_mapping(em_tree, star=
t, len);
Quoted 4 lines
- =C2=A0 =C2=A0 =C2=A0 if (em) {
+ =C2=A0 =C2=A0 =C2=A0 if (!IS_ERR(em) && em) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0em->bdev =3D =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev;
Quoted 1 line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0spin_unlock(&e=
m_tree->lock);
Quoted 4 lines
(quoted diff) +0
-0@@ -1216,8 +1216,8 @@ =C2=A0 =C2=A0 =C2=A0 =C2=A0int ret;=C2=A0 =C2=A0 =C2=A0 =C2=A0root =3D btrfs_read_fs_root_no_name(fs_inf=
o, location);
Quoted 10 lines
- =C2=A0 =C2=A0 =C2=A0 if (!root)
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
+ =C2=A0 =C2=A0 =C2=A0 if (!root ||IS_ERR(root))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return root;=C2=A0 =C2=A0 =C2=A0 =C2=A0if (
root->in_sysfs)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return root;(quoted diff) +0
-0@@ -1324,7 +1324,7 @@ =C2=A0 =C2=A0 =C2=A0 =C2=A0spin_lock(&em_tree->lock);=C2=A0 =C2=A0 =C2=A0 =C2=A0em =3D lookup_extent_mapping(em_tree, offs=
et, PAGE_CACHE_SIZE);
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0spin_unlock(&em_tree->lock);
- =C2=A0 =C2=A0 =C2=A0 if (!em) {
+ =C2=A0 =C2=A0 =C2=A0 if (!em ||IS_ERR(em)) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0__unplug_io_fn=
(bdi, page);
Quoted 4 lines
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; =C2=A0 =C2=A0 =C2=A0 =C2=A0}
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=
" in
Quoted 2 lines
the body of a message to [email protected]
More majordomo info at =C2=A0http://vger.kernel.org/majordomo-info.ht=
ml
Quoted 1 line
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 2 lines · Andrey Kuzmin
Since both NULL ptr and
IS_ERR(ptr)are treated as error, why not redefineIS_ERRto handle both, simplifying caller's life?
IS_ERR is a global kernel function, and NULL isn't always an error.
- -Jeff
Quoted 44 lines · Dan Carpenter
Quoted 43 lines
There are a couple functions which return
ERR_PTRas well as NULL. The caller needs to handle both.Smatch also complains about the handling of
alloc_extent_map()but as far as I can see that doesn't actually return anERR_PTR.Compile tested on 2.6.29.
regards,
dan carpenterfs/btrfs/disk-io.c 2009-04-07 16:23:33.000000000 +0300 renamed from fs/btrfs/disk-io.c 2009-04-07 16:15:36.000000000 +0300 +4
-5@@ -123,7 +123,7 @@ spin_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, start, len); - if (em) { + if (!IS_ERR(em) && em) { em->bdev = BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev; spin_unlock(&em_tree->lock);@@ -1216,8 +1216,8 @@ int ret; root = btrfs_read_fs_root_no_name(fs_info, location); - if (!root) - return NULL; + if (!root || IS_ERR(root)) + return root; if (root->in_sysfs) return root;@@ -1324,7 +1324,7 @@ spin_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, offset, PAGE_CACHE_SIZE); spin_unlock(&em_tree->lock); - if (!em) { + if (!em || IS_ERR(em)) { __unplug_io_fn(bdi, page); return; } --
Quoted 8 lines
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iEYEARECAAYFAknbZysACgkQLPWxlyuTD7K0IQCgiZSrwJWtZCG3uRDAKjEPTBeT qX8AnjaMRgZ9mqw6icQlGNCfOeYGHvO7
=d73O
-----END PGP SIGNATURE-----