Skip to contentSkip to conversation

gpio: lock device when calling device_is_bound()

PATCH Applied Bartosz Golaszewski 1 participant 5 messages May 18 – May 21

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

cover gpio: lock device when calling device_is_bound()

The kerneldoc for device_is_bound() says it must be called with the device lock taken. Add missing synchronization to GPIO modules using it.

---
Bartosz Golaszewski (3):
gpio: sim: lock device when calling device_is_bound()
gpio: aggregator: lock device when calling device_is_bound()
gpio: virtuser: lock device when calling device_is_bound()

 drivers/gpio/gpio-aggregator.c |  9 ++++++---
 drivers/gpio/gpio-sim.c        | 11 +++++++----
 drivers/gpio/gpio-virtuser.c   |  9 ++++++---
 3 files changed, 19 insertions(+), 10 deletions(-)

---
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
change-id: 20260518-gpio-dev-lock-827253e58535

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#1 lore raw

PATCH 1/3 gpio: sim: lock device when calling device_is_bound()

The kerneldoc for device_is_bound() says it must be called with the device lock taken. Add missing synchronization to this driver.

Fixes 7fb3287946f9 ("gpio: sim: stop using dev-sync-probe")
---
 drivers/gpio/gpio-sim.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpio/gpio-sim.c +7 -4
index e19701c2ed673f8ec5a2475e632388197a78339c..0da2c5a45843ea22ef39273c2e39dc128664f0b2 100644
@@ -901,7 +901,7 @@ static int gpio_sim_device_activate(struct gpio_sim_device *dev)
 	struct platform_device *pdev;
 	struct fwnode_handle *swnode;
 	struct gpio_sim_bank *bank;
-	int ret;
+	int ret = 0;
 
 	lockdep_assert_held(&dev->lock);
 
@@ -945,9 +945,12 @@ static int gpio_sim_device_activate(struct gpio_sim_device *dev)
 	}
 
 	wait_for_device_probe();
-	if (!device_is_bound(&pdev->dev)) {
-		ret = -ENXIO;
-		goto err_unregister_pdev;
+
+	scoped_guard(device, &pdev->dev) {
+		if (!device_is_bound(&pdev->dev)) {
+			ret = -ENXIO;
+			goto err_unregister_pdev;
+		}
 	}
 
 	dev->pdev = pdev;
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/3 gpio: aggregator: lock device when calling device_is_bound()

In reply to Bartosz Golaszewski

The kerneldoc for device_is_bound() says it must be called with the device lock taken. Add missing synchronization to this driver.

Fixes 3a27f40b4570 ("gpio: aggregator: stop using dev-sync-probe")
---
 drivers/gpio/gpio-aggregator.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-aggregator.c +6 -3
index 5915209e1e2168b0932de4d16aff38074b889c2b..3dbccb14216f8450ac0f68abaab693e52b9d1bf4 100644
@@ -968,9 +968,12 @@ static int gpio_aggregator_activate(struct gpio_aggregator *aggr)
 	}
 
 	wait_for_device_probe();
-	if (!device_is_bound(&pdev->dev)) {
-		ret = -ENXIO;
-		goto err_unregister_pdev;
+
+	scoped_guard(device, &pdev->dev) {
+		if (!device_is_bound(&pdev->dev)) {
+			ret = -ENXIO;
+			goto err_unregister_pdev;
+		}
 	}
 
 	aggr->pdev = pdev;
Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/3 gpio: virtuser: lock device when calling device_is_bound()

In reply to Bartosz Golaszewski

The kerneldoc for device_is_bound() says it must be called with the device lock taken. Add missing synchronization to this driver.

Fixes c3e2a8aef28c ("gpio: virtuser: stop using dev-sync-probe")
---
 drivers/gpio/gpio-virtuser.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-virtuser.c +6 -3
index fe0eac920ced323926b2bc83ca0a2eb5f85c2154..128520d340d46cbaa36b492cbdcb996bade93d77 100644
@@ -1477,9 +1477,12 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev)
 	}
 
 	wait_for_device_probe();
-	if (!device_is_bound(&pdev->dev)) {
-		ret = -ENXIO;
-		goto err_unregister_pdev;
+
+	scoped_guard(device, &pdev->dev) {
+		if (!device_is_bound(&pdev->dev)) {
+			ret = -ENXIO;
+			goto err_unregister_pdev;
+		}
 	}
 
 	dev->pdev = pdev;
Signature · 1 line
2.47.3
author Applied
#4 lore raw
In reply to Bartosz Golaszewski
Quoted 4 lines · Bartosz Golaszewski

The kerneldoc for device_is_bound() says it must be called with the device lock taken. Add missing synchronization to GPIO modules using it.

Applied, thanks!

[1/3] gpio: sim: lock device when calling device_is_bound()

      https://git.kernel.org/brgl/c/e70ae40d6660c5428c790c329318c570b4d038ab
[2/3] gpio: aggregator: lock device when calling device_is_bound()
      https://git.kernel.org/brgl/c/598a2b3e2e0e6aa2e9f7843c96c45b5ea11e0411
[3/3] gpio: virtuser: lock device when calling device_is_bound()
      https://git.kernel.org/brgl/c/a4fa45c1d980bc2b9837f469119af24a9304a1fc

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>