[PATCH v2 2/9] i2c: atr: unlock mutex after c2a access

Cosmin Tanislav posted 9 patches 11 months, 2 weeks ago
There is a newer version of this series
[PATCH v2 2/9] i2c: atr: unlock mutex after c2a access
Posted by Cosmin Tanislav 11 months, 2 weeks ago
i2c_atr_release_alias(), i2c_atr_destroy_c2a(), and c2a access, are
protected everywhere with alias_pairs_lock, use it here too.

i2c_atr_destroy_c2a() accesses the elements inside alias_pairs, which
needs to be mutex protected.

Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>
---
 drivers/i2c/i2c-atr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
index 39b3b95c6842..f6033c99f474 100644
--- a/drivers/i2c/i2c-atr.c
+++ b/drivers/i2c/i2c-atr.c
@@ -544,8 +544,6 @@ static void i2c_atr_detach_addr(struct i2c_adapter *adapter,
 		return;
 	}
 
-	mutex_unlock(&chan->alias_pairs_lock);
-
 	i2c_atr_release_alias(chan->alias_pool, c2a->alias);
 
 	dev_dbg(atr->dev,
@@ -553,6 +551,8 @@ static void i2c_atr_detach_addr(struct i2c_adapter *adapter,
 		chan->chan_id, c2a->alias, addr);
 
 	i2c_atr_destroy_c2a(&c2a);
+
+	mutex_unlock(&chan->alias_pairs_lock);
 }
 
 static int i2c_atr_bus_notifier_call(struct notifier_block *nb,
-- 
2.48.1
Re: [PATCH v2 2/9] i2c: atr: unlock mutex after c2a access
Posted by Romain Gantois 11 months, 2 weeks ago
Hello Cosmin,

On mardi 25 février 2025 12:39:30 heure normale d’Europe centrale Cosmin 
Tanislav wrote:
> i2c_atr_release_alias(), i2c_atr_destroy_c2a(), and c2a access, are
> protected everywhere with alias_pairs_lock, use it here too.
> 
> i2c_atr_destroy_c2a() accesses the elements inside alias_pairs, which
> needs to be mutex protected.

This looks like something that should be fixed in my FPC202 series. I'll fix it 
in v9 so that you don't have to do it in your series. FYI here's the link to 
v8 of my FPC202 series: 

https://lore.kernel.org/all/20250227-fpc202-v8-0-b7994117fbe2@bootlin.com/

I'll put you in Cc of v9.

Thanks,

-- 
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com