Skip to content

Commit 0242632

Browse files
Demon000Wolfram Sang
authored andcommitted
i2c: atr: deduplicate logic in attach_addr()
This is the same logic as in i2c_atr_create_mapping_by_addr(). Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Reviewed-by: Romain Gantois <romain.gantois@bootlin.com> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 5efe815 commit 0242632

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

drivers/i2c/i2c-atr.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -538,38 +538,20 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter,
538538
struct i2c_atr_chan *chan = adapter->algo_data;
539539
struct i2c_atr *atr = chan->atr;
540540
struct i2c_atr_alias_pair *c2a;
541-
u16 alias;
542-
int ret;
543-
544-
ret = i2c_atr_reserve_alias(chan->alias_pool);
545-
if (ret < 0) {
546-
dev_err(atr->dev, "failed to find a free alias\n");
547-
return ret;
548-
}
549-
550-
alias = ret;
541+
int ret = 0;
551542

552543
mutex_lock(&chan->alias_pairs_lock);
553544

554-
c2a = i2c_atr_create_c2a(chan, alias, addr);
545+
c2a = i2c_atr_create_mapping_by_addr(chan, addr);
555546
if (!c2a) {
556-
ret = -ENOMEM;
557-
goto err_release_alias;
547+
dev_err(atr->dev, "failed to find a free alias\n");
548+
ret = -EBUSY;
549+
goto out_unlock;
558550
}
559551

560-
ret = atr->ops->attach_addr(atr, chan->chan_id, addr, alias);
561-
if (ret)
562-
goto err_del_c2a;
563-
564552
dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n",
565-
chan->chan_id, alias, addr);
566-
567-
goto out_unlock;
553+
chan->chan_id, c2a->alias, addr);
568554

569-
err_del_c2a:
570-
i2c_atr_destroy_c2a(&c2a);
571-
err_release_alias:
572-
i2c_atr_release_alias(chan->alias_pool, alias);
573555
out_unlock:
574556
mutex_unlock(&chan->alias_pairs_lock);
575557
return ret;

0 commit comments

Comments
 (0)