Skip to contentSkip to conversation

null_blk: Fix return value of nullb_device_power_store()

PATCH Applied Damien Le Moal 4 participants 4 messages May 27, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 null_blk: Fix return value of nullb_device_power_store()

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'")
---
 drivers/block/null_blk/main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/null_blk/main.c +1 -0
index eb023d267369..631dca2e4e84 100644
@@ -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;
Signature · 1 line
2.45.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Damien Le Moal

Hi,

Quoted 5 lines · 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.

Quoted 20 lines
Fixes a2db328b0839 ("null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'")
---
  drivers/block/null_blk/main.c | 1 +
  1 file changed, 1 insertion(+)
drivers/block/null_blk/main.c +1 -0
index eb023d267369..631dca2e4e84 100644
@@ -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;
maintainer Applied
#3 lore raw
In reply to Damien Le Moal
Quoted 8 lines · 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.

[...]

Applied, thanks!

[1/1] null_blk: Fix return value of nullb_device_power_store()

      commit: d9ff882b54f99f96787fa3df7cd938966843c418

Best regards,

Signature · 1 line
Jens Axboe