Re: [PATCH v5 2/8] i2c: add I2C Address Translator (ATR) support

Andy Shevchenko
2022-12-08T18:09:26Z

On Thu, Dec 08, 2022 at 06:01:19PM +0200, Tomi Valkeinen wrote:
> On 08/12/2022 14:53, Andy Shevchenko wrote:
> > On Thu, Dec 08, 2022 at 12:40:00PM +0200, Tomi Valkeinen wrote:

...

> > > + if (bus_handle) {
> > > + device_set_node(&chan->adap.dev, fwnode_handle_get(bus_handle));
> >
> > I believe the correct way, while above still works, is
> >
> > device_set_node(&chan->adap.dev, bus_handle);
> > fwnode_handle_get(dev_fwnode(&chan->adap.dev));
>
> Hmm, why is that correct? Shouldn't you give device_set_node() an fwnode
> that has been referenced?

You take a reference on the adap->dev and not on input. It's just a logical,
But as I said your variant still works.

> > But I agree that this looks a bit verbose. And...
> >
> > > + } else {
> > > + struct fwnode_handle *atr_node;
> > > + struct fwnode_handle *child;
> > > + u32 reg;
> > > +
> > > + atr_node = device_get_named_child_node(dev, "i2c-atr");
> > > +
> > > + fwnode_for_each_child_node(atr_node, child) {
> > > + ret = fwnode_property_read_u32(child, "reg", &reg);
> > > + if (ret)
> > > + continue;
> > > + if (chan_id == reg)
> > > + break;
> > > + }
> > > +
> > > + device_set_node(&chan->adap.dev, child);
> >
> > ...OTOH, you set node with bumped reference here. So I leave all this to
> > the maintainers.
> >
> > > + fwnode_handle_put(atr_node);
> > > + }

...

> > > +static inline void i2c_atr_set_clientdata(struct i2c_atr *atr, void *data)
> > > +{
> > > + atr->priv = data;
> > > +}
> > > +
> > > +static inline void *i2c_atr_get_clientdata(struct i2c_atr *atr)
> > > +{
> > > + return atr->priv;
> > > +}
> >
> > The function names are misleading, because I would think this is about driver
> > data that has been set.
> >
> > I would rather use name like
> >
> > i2c_atr_get_priv()
> > i2c_atr_set_priv()
>
> Indeed, set_clientdata is probably wrong. But i2c_atr_set_priv() sounds like
> it's private to the i2c-atr itself. Maybe i2c_atr_set_driver_data?

Works for me.

--
With Best Regards,
Andy Shevchenko