[PATCH v2 1/2] i2c: i2c-gpio: Release a shared SCL before it can be requested again

From: Anatoliy Oleinikov via B4 Relay

Date: Wed Dec 02 2026 - 08:16:47 EST


From: Anatoliy Oleinikov <admin@xxxxxxxxxx>

Releasing the last reference to a shared SCL removes it from the list
and drops the list lock before it releases the GPIO. An adapter sharing
the pin that probes in between finds no entry and requests the GPIO,
which is still held, so its probe fails with -EBUSY instead of deferring.

Release the GPIO while the list lock is still held.

Fixes: 645c3d7d07fa ("i2c: i2c-gpio: Enhance driver for buses with shared SCL")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Anatoliy Oleinikov <admin@xxxxxxxxxx>
---
drivers/i2c/busses/i2c-gpio.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 56d6847cbf6d..552fcbb1eaed 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -512,8 +512,9 @@ static void i2c_gpio_cleanup_scl(struct i2c_gpio_scl_data *scl)
return;

list_del(&scl->list);
- mutex_unlock(&i2c_gpio_scl_list_lock);
+ /* An adapter that finds no entry requests the pin, so it must be free by then */
gpiod_put(scl->gpio);
+ mutex_unlock(&i2c_gpio_scl_list_lock);
i2c_gpio_free_scl(scl);
}


--
Git-157)