Skip to contentSkip to conversation

media: ipu3-cio2: Fix referece counting when looping over ACPI devices

PATCH In review Andy Shevchenko 3 participants 5 messages Apr 4, 2021 – Apr 21, 2021

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

PATCH 1/1 media: ipu3-cio2: Fix referece counting when looping over ACPI devices

When we continue, due to device is disabled, loop we have to drop reference count. When we have an array full of devices we have to also drop the reference count. Note, in this case the cio2_bridge_unregister_sensors() is called by the caller.

Fixes 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver")
Cc Daniel Scally <[email protected]>
Cc Sakari Ailus <[email protected]>
---
 drivers/media/pci/intel/ipu3/cio2-bridge.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ipu3/cio2-bridge.c +5 -5
index c2199042d3db..85f8b587405e 100644
@@ -173,14 +173,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 	int ret;
 
 	for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
-		if (!adev->status.enabled)
+		if (!adev->status.enabled) {
+			acpi_dev_put(adev);
 			continue;
+		}
 
 		if (bridge->n_sensors >= CIO2_NUM_PORTS) {
+			acpi_dev_put(adev);
 			dev_err(&cio2->dev, "Exceeded available CIO2 ports\n");
-			cio2_bridge_unregister_sensors(bridge);
-			ret = -EINVAL;
-			goto err_out;
+			return -EINVAL;
 		}
 
 		sensor = &bridge->sensors[bridge->n_sensors];
@@ -228,7 +229,6 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 	software_node_unregister_nodes(sensor->swnodes);
 err_put_adev:
 	acpi_dev_put(sensor->adev);
-err_out:
 	return ret;
 }
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Andy

Quoted 8 lines · Andy Shevchenko

When we continue, due to device is disabled, loop we have to drop reference count. When we have an array full of devices we have to also drop the reference count. Note, in this case the cio2_bridge_unregister_sensors() is called by the caller.

Fixes 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver")
Cc Daniel Scally <[email protected]>
Cc Sakari Ailus <[email protected]>

Ah; thanks for catching those, I'm annoyed to have missed the acpi_dev_put() calls in particular

#2 lore raw
Quoted 10 lines · Daniel Scally
Quoted 8 lines · Andy Shevchenko

When we continue, due to device is disabled, loop we have to drop reference count. When we have an array full of devices we have to also drop the reference count. Note, in this case the cio2_bridge_unregister_sensors() is called by the caller.

Fixes 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver")
Cc Daniel Scally <[email protected]>
Cc Sakari Ailus <[email protected]>
Quoted 4 lines

Ah; thanks for catching those, I'm annoyed to have missed the acpi_dev_put() calls in particular

Sakari, Mauro, can this be applied as v5.12 material, please?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
In reply to Andy Shevchenko

Hi Andy,

Thanks for the patch.

Quoted 3 lines · Andy Shevchenko

When we continue, due to device is disabled, loop we have to drop reference count. When we have an array full of devices we have to also drop the reference count. Note, in this case the cio2_bridge_unregister_sensors() is called by the caller.

Please limit the commit message to 75 chars, at least if there's no reason to do otherwise.

I can wrap it this time.

Quoted 41 lines
Fixes 803abec64ef9 ("media: ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver")
Cc Daniel Scally <[email protected]>
Cc Sakari Ailus <[email protected]>
---
 drivers/media/pci/intel/ipu3/cio2-bridge.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ipu3/cio2-bridge.c +5 -5
index c2199042d3db..85f8b587405e 100644
@@ -173,14 +173,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 	int ret;
 
 	for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
-		if (!adev->status.enabled)
+		if (!adev->status.enabled) {
+			acpi_dev_put(adev);
 			continue;
+		}
 
 		if (bridge->n_sensors >= CIO2_NUM_PORTS) {
+			acpi_dev_put(adev);
 			dev_err(&cio2->dev, "Exceeded available CIO2 ports\n");
-			cio2_bridge_unregister_sensors(bridge);
-			ret = -EINVAL;
-			goto err_out;
+			return -EINVAL;
 		}
 
 		sensor = &bridge->sensors[bridge->n_sensors];
@@ -228,7 +229,6 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 	software_node_unregister_nodes(sensor->swnodes);
 err_put_adev:
 	acpi_dev_put(sensor->adev);
-err_out:
 	return ret;
 }
 
Signature · 3 lines
Regards,

Sakari Ailus
#4 lore raw
Quoted 7 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko

When we continue, due to device is disabled, loop we have to drop reference count. When we have an array full of devices we have to also drop the reference count. Note, in this case the cio2_bridge_unregister_sensors() is called by the caller.

Please limit the commit message to 75 chars, at least if there's no reason to do otherwise.

OK.

Quoted 1 line

I can wrap it this time.

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko