* [PATCH] null_blk: Fix return value of nullb_device_power_store()
@ 2024-05-27 4:34 ` Damien Le Moal
2024-05-27 5:33 ` Kanchan Joshi
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Damien Le Moal @ 2024-05-27 4:34 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Yu Kuai
When powering on a null_blk device that is not already on, the return
value ret that is initialized to be count is reused to check the return
value of null_add_dev(), leading to nullb_device_power_store() to return
null_add_dev() return value (0 on success) instead of "count".
So make sure to set ret to be equal to count when there are no errors.
Fixes: a2db328b0839 ("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
drivers/block/null_blk/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index eb023d267369..631dca2e4e84 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -494,6 +494,7 @@ static ssize_t nullb_device_power_store(struct config_item *item,
set_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags);
dev->power = newp;
+ ret = count;
} else if (dev->power && !newp) {
if (test_and_clear_bit(NULLB_DEV_FL_UP, &dev->flags)) {
dev->power = newp;
--
2.45.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: Fix return value of nullb_device_power_store()
2024-05-27 4:34 ` [PATCH] null_blk: Fix return value of nullb_device_power_store() Damien Le Moal
@ 2024-05-27 5:33 ` Kanchan Joshi
2024-05-27 6:32 ` Yu Kuai
2024-05-27 19:57 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Kanchan Joshi @ 2024-05-27 5:33 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe, linux-block; +Cc: Yu Kuai
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: Fix return value of nullb_device_power_store()
2024-05-27 4:34 ` [PATCH] null_blk: Fix return value of nullb_device_power_store() Damien Le Moal
2024-05-27 5:33 ` Kanchan Joshi
@ 2024-05-27 6:32 ` Yu Kuai
2024-05-27 19:57 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Yu Kuai @ 2024-05-27 6:32 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe, linux-block, yukuai (C)
Hi,
在 2024/05/27 12:34, Damien Le Moal 写道:
> When powering on a null_blk device that is not already on, the return
> value ret that is initialized to be count is reused to check the return
> value of null_add_dev(), leading to nullb_device_power_store() to return
> null_add_dev() return value (0 on success) instead of "count".
> So make sure to set ret to be equal to count when there are no errors.
Yes, thanks for the patch!
And the reason test did't find this problem is that the "echo" cmd will
write again to the configfs entry, and nullb_device_power_store() will
found the allocated nullb_device.
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
>
> Fixes: a2db328b0839 ("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
> drivers/block/null_blk/main.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index eb023d267369..631dca2e4e84 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -494,6 +494,7 @@ static ssize_t nullb_device_power_store(struct config_item *item,
>
> set_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags);
> dev->power = newp;
> + ret = count;
> } else if (dev->power && !newp) {
> if (test_and_clear_bit(NULLB_DEV_FL_UP, &dev->flags)) {
> dev->power = newp;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: Fix return value of nullb_device_power_store()
2024-05-27 4:34 ` [PATCH] null_blk: Fix return value of nullb_device_power_store() Damien Le Moal
2024-05-27 5:33 ` Kanchan Joshi
2024-05-27 6:32 ` Yu Kuai
@ 2024-05-27 19:57 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2024-05-27 19:57 UTC (permalink / raw)
To: linux-block, Damien Le Moal; +Cc: Yu Kuai
On Mon, 27 May 2024 13:34:45 +0900, Damien Le Moal wrote:
> When powering on a null_blk device that is not already on, the return
> value ret that is initialized to be count is reused to check the return
> value of null_add_dev(), leading to nullb_device_power_store() to return
> null_add_dev() return value (0 on success) instead of "count".
> So make sure to set ret to be equal to count when there are no errors.
>
>
> [...]
Applied, thanks!
[1/1] null_blk: Fix return value of nullb_device_power_store()
commit: d9ff882b54f99f96787fa3df7cd938966843c418
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-27 19:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20240527043455epcas5p18a6d514da1e203726501570b07fc8d19@epcas5p1.samsung.com>
2024-05-27 4:34 ` [PATCH] null_blk: Fix return value of nullb_device_power_store() Damien Le Moal
2024-05-27 5:33 ` Kanchan Joshi
2024-05-27 6:32 ` Yu Kuai
2024-05-27 19:57 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox