diff mbox series

btrfs: fix warning on PTR_ERR() against NULL device at btrfs_control_ioctl()

Message ID 5bbe65395fcb54fd561cc17a705ce6d50d0cc5c0.1730898948.git.fdmanana@suse.com (mailing list archive)
State New
Headers show
Series btrfs: fix warning on PTR_ERR() against NULL device at btrfs_control_ioctl() | expand

Commit Message

Filipe Manana Nov. 6, 2024, 1:17 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

Smatch complains about calling PTR_ERR() against a NULL pointer:

  fs/btrfs/super.c:2272 btrfs_control_ioctl() warn: passing zero to 'PTR_ERR'

Fix this by calling PTR_ERR() against the device pointer only if it
contains an error.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/super.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

David Sterba Nov. 6, 2024, 5:59 p.m. UTC | #1
On Wed, Nov 06, 2024 at 01:17:39PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Smatch complains about calling PTR_ERR() against a NULL pointer:
> 
>   fs/btrfs/super.c:2272 btrfs_control_ioctl() warn: passing zero to 'PTR_ERR'
> 
> Fix this by calling PTR_ERR() against the device pointer only if it
> contains an error.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: David Sterba <dsterba@suse.com>
Qu Wenruo Nov. 6, 2024, 9:29 p.m. UTC | #2
在 2024/11/6 23:47, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> Smatch complains about calling PTR_ERR() against a NULL pointer:
>
>    fs/btrfs/super.c:2272 btrfs_control_ioctl() warn: passing zero to 'PTR_ERR'
>
> Fix this by calling PTR_ERR() against the device pointer only if it
> contains an error.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/super.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 6cc9291c4552..9a09a1251057 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -2269,7 +2269,10 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
>   		device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false);
>   		if (IS_ERR_OR_NULL(device)) {
>   			mutex_unlock(&uuid_mutex);
> -			ret = PTR_ERR(device);
> +			if (IS_ERR(device))
> +				ret = PTR_ERR(device);
> +			else
> +				ret = 0;
>   			break;
>   		}
>   		ret = !(device->fs_devices->num_devices ==
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 6cc9291c4552..9a09a1251057 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2269,7 +2269,10 @@  static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
 		device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false);
 		if (IS_ERR_OR_NULL(device)) {
 			mutex_unlock(&uuid_mutex);
-			ret = PTR_ERR(device);
+			if (IS_ERR(device))
+				ret = PTR_ERR(device);
+			else
+				ret = 0;
 			break;
 		}
 		ret = !(device->fs_devices->num_devices ==