* [bug report] btrfs: error out if btrfs_attach_transaction() fails
@ 2017-10-12 20:39 Dan Carpenter
2017-10-13 1:59 ` Anand Jain
2017-10-13 2:16 ` [PATCH] btrfs: fix call to btrfs_end_transaction without a transaction handler Anand Jain
0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2017-10-12 20:39 UTC (permalink / raw)
To: anand.jain; +Cc: linux-btrfs
Hello Anand Jain,
The patch 1eea2715ca9b: "btrfs: error out if
btrfs_attach_transaction() fails" from Sep 28, 2017, leads to the
following static checker warning:
fs/btrfs/volumes.c:2502 btrfs_init_new_device()
error: 'trans' dereferencing possible ERR_PTR()
fs/btrfs/volumes.c
2479 ret = btrfs_relocate_sys_chunks(fs_info);
2480 if (ret < 0)
2481 btrfs_handle_fs_error(fs_info, ret,
2482 "Failed to relocate sys chunks after device initialization. This can be fixed using the \"btrfs balance\" command.");
2483 trans = btrfs_attach_transaction(root);
2484 if (IS_ERR(trans)) {
2485 if (PTR_ERR(trans) == -ENOENT)
2486 return 0;
2487 ret = PTR_ERR(trans);
2488 goto error_sysfs;
^^^^^^^^^^^^^^^^
We used to have a direct return here.
2489 }
2490 ret = btrfs_commit_transaction(trans);
2491 }
2492
2493 /* Update ctime/mtime for libblkid */
2494 update_dev_time(device_path);
2495 return ret;
2496
2497 error_sysfs:
2498 btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
2499 error_trans:
2500 if (seeding_dev)
2501 sb->s_flags |= MS_RDONLY;
2502 btrfs_end_transaction(trans);
^^^^^^
But now it's dereferencing an error pointer inside this function.
2503 rcu_string_free(device->name);
2504 kfree(device);
2505 error:
2506 blkdev_put(bdev, FMODE_EXCL);
2507 if (seeding_dev && !unlocked) {
2508 mutex_unlock(&uuid_mutex);
2509 up_write(&sb->s_umount);
2510 }
2511 return ret;
2512 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [bug report] btrfs: error out if btrfs_attach_transaction() fails
2017-10-12 20:39 [bug report] btrfs: error out if btrfs_attach_transaction() fails Dan Carpenter
@ 2017-10-13 1:59 ` Anand Jain
2017-10-13 2:16 ` [PATCH] btrfs: fix call to btrfs_end_transaction without a transaction handler Anand Jain
1 sibling, 0 replies; 4+ messages in thread
From: Anand Jain @ 2017-10-13 1:59 UTC (permalink / raw)
To: Dan Carpenter; +Cc: linux-btrfs
Thanks Dan! You are right. Will fix it.
Anand
On 10/13/2017 04:39 AM, Dan Carpenter wrote:
> Hello Anand Jain,
>
> The patch 1eea2715ca9b: "btrfs: error out if
> btrfs_attach_transaction() fails" from Sep 28, 2017, leads to the
> following static checker warning:
>
> fs/btrfs/volumes.c:2502 btrfs_init_new_device()
> error: 'trans' dereferencing possible ERR_PTR()
>
> fs/btrfs/volumes.c
> 2479 ret = btrfs_relocate_sys_chunks(fs_info);
> 2480 if (ret < 0)
> 2481 btrfs_handle_fs_error(fs_info, ret,
> 2482 "Failed to relocate sys chunks after device initialization. This can be fixed using the \"btrfs balance\" command.");
> 2483 trans = btrfs_attach_transaction(root);
> 2484 if (IS_ERR(trans)) {
> 2485 if (PTR_ERR(trans) == -ENOENT)
> 2486 return 0;
> 2487 ret = PTR_ERR(trans);
> 2488 goto error_sysfs;
> ^^^^^^^^^^^^^^^^
> We used to have a direct return here.
>
> 2489 }
> 2490 ret = btrfs_commit_transaction(trans);
> 2491 }
> 2492
> 2493 /* Update ctime/mtime for libblkid */
> 2494 update_dev_time(device_path);
> 2495 return ret;
> 2496
> 2497 error_sysfs:
> 2498 btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
> 2499 error_trans:
> 2500 if (seeding_dev)
> 2501 sb->s_flags |= MS_RDONLY;
> 2502 btrfs_end_transaction(trans);
> ^^^^^^
> But now it's dereferencing an error pointer inside this function.
>
> 2503 rcu_string_free(device->name);
> 2504 kfree(device);
> 2505 error:
> 2506 blkdev_put(bdev, FMODE_EXCL);
> 2507 if (seeding_dev && !unlocked) {
> 2508 mutex_unlock(&uuid_mutex);
> 2509 up_write(&sb->s_umount);
> 2510 }
> 2511 return ret;
> 2512 }
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] btrfs: fix call to btrfs_end_transaction without a transaction handler
2017-10-12 20:39 [bug report] btrfs: error out if btrfs_attach_transaction() fails Dan Carpenter
2017-10-13 1:59 ` Anand Jain
@ 2017-10-13 2:16 ` Anand Jain
2017-10-16 14:07 ` David Sterba
1 sibling, 1 reply; 4+ messages in thread
From: Anand Jain @ 2017-10-13 2:16 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
In btrfs_init_new_device() when btrfs_attach_transaction() fails we
shouldn't call btrfs_end_transaction(). Fix it.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Fixes:
btrfs: error out if btrfs_attach_transaction() fails
---
Hi David,
Can you pls squash this changes to the patch which it
fixes. OR if its better to send the original the with
the fix, pls let me know I will do it.
Thanks.
fs/btrfs/volumes.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 90805581ea10..efd502176915 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2477,6 +2477,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
if (PTR_ERR(trans) == -ENOENT)
return 0;
ret = PTR_ERR(trans);
+ trans = NULL;
goto error_sysfs;
}
ret = btrfs_commit_transaction(trans);
@@ -2491,7 +2492,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
error_trans:
if (seeding_dev)
sb->s_flags |= MS_RDONLY;
- btrfs_end_transaction(trans);
+ if (trans)
+ btrfs_end_transaction(trans);
rcu_string_free(device->name);
kfree(device);
error:
--
2.13.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: fix call to btrfs_end_transaction without a transaction handler
2017-10-13 2:16 ` [PATCH] btrfs: fix call to btrfs_end_transaction without a transaction handler Anand Jain
@ 2017-10-16 14:07 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2017-10-16 14:07 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs, dsterba
On Fri, Oct 13, 2017 at 10:16:54AM +0800, Anand Jain wrote:
> In btrfs_init_new_device() when btrfs_attach_transaction() fails we
> shouldn't call btrfs_end_transaction(). Fix it.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> Fixes:
> btrfs: error out if btrfs_attach_transaction() fails
> ---
> Hi David,
> Can you pls squash this changes to the patch which it
> fixes. OR if its better to send the original the with
> the fix, pls let me know I will do it.
I have squashed the incremental change, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-16 14:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-12 20:39 [bug report] btrfs: error out if btrfs_attach_transaction() fails Dan Carpenter
2017-10-13 1:59 ` Anand Jain
2017-10-13 2:16 ` [PATCH] btrfs: fix call to btrfs_end_transaction without a transaction handler Anand Jain
2017-10-16 14:07 ` David Sterba
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).