[PATCH v5 6/9] i2c: atr: allow replacing mappings in attach_addr()

Cosmin Tanislav posted 9 patches 7 months, 1 week ago
[PATCH v5 6/9] i2c: atr: allow replacing mappings in attach_addr()
Posted by Cosmin Tanislav 7 months, 1 week ago
It is possible for aliases to be exhausted while we are still attaching
children.

Allow replacing mapping on attach by calling
i2c_atr_replace_mapping_by_addr() if i2c_atr_create_mapping_by_addr()
fails.

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

diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c
index ae5c2ee629f0..91aabfb4379b 100644
--- a/drivers/i2c/i2c-atr.c
+++ b/drivers/i2c/i2c-atr.c
@@ -543,6 +543,9 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter,
 	mutex_lock(&chan->alias_pairs_lock);
 
 	c2a = i2c_atr_create_mapping_by_addr(chan, addr);
+	if (!c2a)
+		c2a = i2c_atr_replace_mapping_by_addr(chan, addr);
+
 	if (!c2a) {
 		dev_err(atr->dev, "failed to find a free alias\n");
 		ret = -EBUSY;
-- 
2.49.0
Re: [PATCH v5 6/9] i2c: atr: allow replacing mappings in attach_addr()
Posted by Luca Ceresoli 6 months, 4 weeks ago
On Wed,  7 May 2025 15:19:12 +0300
Cosmin Tanislav <demonsingur@gmail.com> wrote:

> It is possible for aliases to be exhausted while we are still attaching
> children.
> 
> Allow replacing mapping on attach by calling
> i2c_atr_replace_mapping_by_addr() if i2c_atr_create_mapping_by_addr()
> fails.
> 
> Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com>

Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com