Skip to contentSkip to conversation

s390/dasd: fix double module refcount decrement

PATCH In review Miroslav Franc 2 participants 4 messages Jan 10, 2024 – Jan 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/dasd: fix double module refcount decrement

Once the discipline is associated with the device, deleting the device takes care of decrementing the module's refcount. Doing it manually on this error path causes refcount to artificially decrease on each error while it should just stay the same.

Fixes c020d722b110 ("s390/dasd: fix panic during offline processing")
---
 drivers/s390/block/dasd.c | 2 --
 1 file changed, 2 deletions(-)
drivers/s390/block/dasd.c +0 -2
index 833cfab7d877..739da1c2b71f 100644
@@ -3546,8 +3546,6 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 	if (rc) {
 		pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
 			dev_name(&cdev->dev), discipline->name, rc);
-		module_put(discipline->owner);
-		module_put(base_discipline->owner);
 		dasd_delete_device(device);
 		return rc;
 	}
maintainer
#1 lore raw
Quoted 16 lines · Miroslav Franc

Once the discipline is associated with the device, deleting the device takes care of decrementing the module's refcount. Doing it manually on this error path causes refcount to artificially decrease on each error while it should just stay the same.

Fixes c020d722b110 ("s390/dasd: fix panic during offline processing")
---
 drivers/s390/block/dasd.c | 2 --
 1 file changed, 2 deletions(-)
drivers/s390/block/dasd.c +0 -0
index 833cfab7d877..739da1c2b71f 100644

drivers/s390/block/dasd.c int dasd_generic_set_online(struct ccw_device *cdev, · line 3550

Quoted 5 lines
drivers/s390/block/dasd.c +0 -2
@@ -3546,8 +3546,6 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 	if (rc) {
 		pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
 			dev_name(&cdev->dev), discipline->name, rc);
-		module_put(discipline->owner);
-		module_put(base_discipline->owner);

Good catch. I think there is one more line above this part that should also be removed:

if (!try_module_get(discipline->owner)) {
        module_put(base_discipline->owner); <---
        dasd_delete_device(device);
        return -EINVAL;
}

Can you add it to the patch? Thanks!

Quoted 4 lines
drivers/s390/block/dasd.c +0 -0
 		dasd_delete_device(device);
 		return rc;
 	}
#2 lore raw
Quoted 26 lines · Jan Höppner
Quoted 16 lines · Miroslav Franc

Once the discipline is associated with the device, deleting the device takes care of decrementing the module's refcount. Doing it manually on this error path causes refcount to artificially decrease on each error while it should just stay the same.

Fixes c020d722b110 ("s390/dasd: fix panic during offline processing")
---
 drivers/s390/block/dasd.c | 2 --
 1 file changed, 2 deletions(-)
drivers/s390/block/dasd.c +0 -0
index 833cfab7d877..739da1c2b71f 100644

drivers/s390/block/dasd.c int dasd_generic_set_online(struct ccw_device *cdev, · line 3550

Quoted 5 lines
drivers/s390/block/dasd.c +0 -2
@@ -3546,8 +3546,6 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 	if (rc) {
 		pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
 			dev_name(&cdev->dev), discipline->name, rc);
-		module_put(discipline->owner);
-		module_put(base_discipline->owner);

Good catch. I think there is one more line above this part that should also be removed:

Quoted 5 lines
if (!try_module_get(discipline->owner)) {
        module_put(base_discipline->owner); <---
        dasd_delete_device(device);
        return -EINVAL;
}

Oh, I was under impression that the following line is necessary for dasd_delete_device to work that way.

device->base_discipline = base_discipline;

I could move it before the if statement before removing module_put from it. Does it make sense?

Quoted 7 lines

Can you add it to the patch? Thanks!

Quoted 4 lines
drivers/s390/block/dasd.c +0 -0
 		dasd_delete_device(device);
 		return rc;
 	}

Once the discipline is associated with the device, deleting the device takes care of decrementing the module's refcount. Doing it manually on this error path causes refcount to artificially decrease on each error while it should just stay the same.

Fixes c020d722b110 ("s390/dasd: fix panic during offline processing")
---
 drivers/s390/block/dasd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/s390/block/dasd.c +1 -4
index 833cfab7d877..8e453454c271 100644
@@ -3533,12 +3533,11 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 		dasd_delete_device(device);
 		return -EINVAL;
 	}
+	device->base_discipline = base_discipline;
 	if (!try_module_get(discipline->owner)) {
-		module_put(base_discipline->owner);
 		dasd_delete_device(device);
 		return -EINVAL;
 	}
-	device->base_discipline = base_discipline;
 	device->discipline = discipline;
 
 	/* check_device will allocate block device if necessary */
@@ -3546,8 +3545,6 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 	if (rc) {
 		pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
 			dev_name(&cdev->dev), discipline->name, rc);
-		module_put(discipline->owner);
-		module_put(base_discipline->owner);
 		dasd_delete_device(device);
 		return rc;
 	}
maintainer
#3 lore raw
Quoted 28 lines · Miroslav Franc
Quoted 26 lines · Jan Höppner
Quoted 16 lines · Miroslav Franc

Once the discipline is associated with the device, deleting the device takes care of decrementing the module's refcount. Doing it manually on this error path causes refcount to artificially decrease on each error while it should just stay the same.

Fixes c020d722b110 ("s390/dasd: fix panic during offline processing")
---
 drivers/s390/block/dasd.c | 2 --
 1 file changed, 2 deletions(-)
drivers/s390/block/dasd.c +0 -0
index 833cfab7d877..739da1c2b71f 100644

drivers/s390/block/dasd.c int dasd_generic_set_online(struct ccw_device *cdev, · line 3550

Quoted 5 lines
drivers/s390/block/dasd.c +0 -2
@@ -3546,8 +3546,6 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 	if (rc) {
 		pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
 			dev_name(&cdev->dev), discipline->name, rc);
-		module_put(discipline->owner);
-		module_put(base_discipline->owner);

Good catch. I think there is one more line above this part that should also be removed:

Quoted 8 lines
Quoted 5 lines
if (!try_module_get(discipline->owner)) {
        module_put(base_discipline->owner); <---
        dasd_delete_device(device);
        return -EINVAL;
}

Oh, I was under impression that the following line is necessary for dasd_delete_device to work that way.

You're absolutely right, I've missed that part, sorry.

Quoted 5 lines

device->base_discipline = base_discipline;

I could move it before the if statement before removing module_put from it. Does it make sense?

Yes that makes sense. That way the (decrement) refcounting is entirely done via the dasd_delete_device() function. I'll take your patch as suggested below. Thanks a lot!

Quoted 47 lines
Quoted 8 lines

Can you add it to the patch? Thanks!

Quoted 4 lines
drivers/s390/block/dasd.c +0 -0
 		dasd_delete_device(device);
 		return rc;
 	}

Once the discipline is associated with the device, deleting the device takes care of decrementing the module's refcount. Doing it manually on this error path causes refcount to artificially decrease on each error while it should just stay the same.

Fixes c020d722b110 ("s390/dasd: fix panic during offline processing")
---
 drivers/s390/block/dasd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/s390/block/dasd.c +1 -4
index 833cfab7d877..8e453454c271 100644
@@ -3533,12 +3533,11 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 		dasd_delete_device(device);
 		return -EINVAL;
 	}
+	device->base_discipline = base_discipline;
 	if (!try_module_get(discipline->owner)) {
-		module_put(base_discipline->owner);
 		dasd_delete_device(device);
 		return -EINVAL;
 	}
-	device->base_discipline = base_discipline;
 	device->discipline = discipline;
 
 	/* check_device will allocate block device if necessary */
@@ -3546,8 +3545,6 @@ int dasd_generic_set_online(struct ccw_device *cdev,
 	if (rc) {
 		pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
 			dev_name(&cdev->dev), discipline->name, rc);
-		module_put(discipline->owner);
-		module_put(base_discipline->owner);
 		dasd_delete_device(device);
 		return rc;
 	}