Message ID | 20250225113939.49811-7-demonsingur@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | i2c: atr: allow usage of nested ATRs | expand |
On mardi 25 février 2025 12:39:34 heure normale d’Europe centrale Cosmin Tanislav wrote: > This is the same logic as in i2c_atr_create_mapping_by_addr(). > > Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com> > --- > drivers/i2c/i2c-atr.c | 30 ++++++------------------------ > 1 file changed, 6 insertions(+), 24 deletions(-) > > diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c > index b62aa6ae452e..5b53eaee0408 100644 > --- a/drivers/i2c/i2c-atr.c > +++ b/drivers/i2c/i2c-atr.c > @@ -538,38 +538,20 @@ static int i2c_atr_attach_addr(struct i2c_adapter > *adapter, struct i2c_atr_chan *chan = adapter->algo_data; > struct i2c_atr *atr = chan->atr; > struct i2c_atr_alias_pair *c2a; > - u16 alias; > - int ret; > - > - ret = i2c_atr_reserve_alias(chan->alias_pool); > - if (ret < 0) { > - dev_err(atr->dev, "failed to find a free alias\n"); > - return ret; > - } > - > - alias = ret; > + int ret = 0; > > mutex_lock(&chan->alias_pairs_lock); A mutex guard could be used here. > > - c2a = i2c_atr_create_c2a(chan, alias, addr); > + c2a = i2c_atr_create_mapping_by_addr(chan, addr); > if (!c2a) { > - ret = -ENOMEM; > - goto err_release_alias; > + dev_err(atr->dev, "failed to find a free alias\n"); > + ret = -EBUSY; > + goto out_unlock; > } > > - ret = atr->ops->attach_addr(atr, chan->chan_id, addr, alias); > - if (ret) > - goto err_del_c2a; > - > dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n", > - chan->chan_id, alias, addr); > + chan->chan_id, c2a->alias, addr); > > - goto out_unlock; > - > -err_del_c2a: > - i2c_atr_destroy_c2a(&c2a); > -err_release_alias: > - i2c_atr_release_alias(chan->alias_pool, alias); > out_unlock: > mutex_unlock(&chan->alias_pairs_lock); > return ret; Best Regards,
On 2/27/25 3:36 PM, Romain Gantois wrote: > On mardi 25 février 2025 12:39:34 heure normale d’Europe centrale Cosmin > Tanislav wrote: >> This is the same logic as in i2c_atr_create_mapping_by_addr(). >> >> Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com> >> --- >> drivers/i2c/i2c-atr.c | 30 ++++++------------------------ >> 1 file changed, 6 insertions(+), 24 deletions(-) >> >> diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c >> index b62aa6ae452e..5b53eaee0408 100644 >> --- a/drivers/i2c/i2c-atr.c >> +++ b/drivers/i2c/i2c-atr.c >> @@ -538,38 +538,20 @@ static int i2c_atr_attach_addr(struct i2c_adapter >> *adapter, struct i2c_atr_chan *chan = adapter->algo_data; >> struct i2c_atr *atr = chan->atr; >> struct i2c_atr_alias_pair *c2a; >> - u16 alias; >> - int ret; >> - >> - ret = i2c_atr_reserve_alias(chan->alias_pool); >> - if (ret < 0) { >> - dev_err(atr->dev, "failed to find a free alias\n"); >> - return ret; >> - } >> - >> - alias = ret; >> + int ret = 0; >> >> mutex_lock(&chan->alias_pairs_lock); > > A mutex guard could be used here. > Should we be using it in other places in the driver too then? We could leave that conversion for a separate commit. >> >> - c2a = i2c_atr_create_c2a(chan, alias, addr); >> + c2a = i2c_atr_create_mapping_by_addr(chan, addr); >> if (!c2a) { >> - ret = -ENOMEM; >> - goto err_release_alias; >> + dev_err(atr->dev, "failed to find a free alias\n"); >> + ret = -EBUSY; >> + goto out_unlock; >> } >> >> - ret = atr->ops->attach_addr(atr, chan->chan_id, addr, alias); >> - if (ret) >> - goto err_del_c2a; >> - >> dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n", >> - chan->chan_id, alias, addr); >> + chan->chan_id, c2a->alias, addr); >> >> - goto out_unlock; >> - >> -err_del_c2a: >> - i2c_atr_destroy_c2a(&c2a); >> -err_release_alias: >> - i2c_atr_release_alias(chan->alias_pool, alias); >> out_unlock: >> mutex_unlock(&chan->alias_pairs_lock); >> return ret; > > Best Regards, >
diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index b62aa6ae452e..5b53eaee0408 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -538,38 +538,20 @@ static int i2c_atr_attach_addr(struct i2c_adapter *adapter, struct i2c_atr_chan *chan = adapter->algo_data; struct i2c_atr *atr = chan->atr; struct i2c_atr_alias_pair *c2a; - u16 alias; - int ret; - - ret = i2c_atr_reserve_alias(chan->alias_pool); - if (ret < 0) { - dev_err(atr->dev, "failed to find a free alias\n"); - return ret; - } - - alias = ret; + int ret = 0; mutex_lock(&chan->alias_pairs_lock); - c2a = i2c_atr_create_c2a(chan, alias, addr); + c2a = i2c_atr_create_mapping_by_addr(chan, addr); if (!c2a) { - ret = -ENOMEM; - goto err_release_alias; + dev_err(atr->dev, "failed to find a free alias\n"); + ret = -EBUSY; + goto out_unlock; } - ret = atr->ops->attach_addr(atr, chan->chan_id, addr, alias); - if (ret) - goto err_del_c2a; - dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n", - chan->chan_id, alias, addr); + chan->chan_id, c2a->alias, addr); - goto out_unlock; - -err_del_c2a: - i2c_atr_destroy_c2a(&c2a); -err_release_alias: - i2c_atr_release_alias(chan->alias_pool, alias); out_unlock: mutex_unlock(&chan->alias_pairs_lock); return ret;
This is the same logic as in i2c_atr_create_mapping_by_addr(). Signed-off-by: Cosmin Tanislav <demonsingur@gmail.com> --- drivers/i2c/i2c-atr.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-)