RE: [PATCH] i2c: Add i2c_get_match_data()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Geert,

Thanks for the feedback.

> -----Original Message-----
> From: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Sent: Monday, May 22, 2023 12:29 PM
> To: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> Cc: Wolfram Sang <wsa@xxxxxxxxxx>; linux-i2c@xxxxxxxxxxxxxxx; Alessandro
> Zummo <a.zummo@xxxxxxxxxxxx>; Alexandre Belloni
> <alexandre.belloni@xxxxxxxxxxx>; Prabhakar Mahadev Lad
> <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>; linux-renesas-
> soc@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH] i2c: Add i2c_get_match_data()
> 
> Hi Biju,
> 
> On Mon, May 22, 2023 at 12:42 PM Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> wrote:
> > Add i2c_get_match_data() similar to of_device_get_match_data(), so
> > that we can optimize the driver code that uses both I2C and DT-based
> > matching.
> >
> > Suggested-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
> > Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> 
> Thanks for your patch!
> 
> > --- a/drivers/i2c/i2c-core-base.c
> > +++ b/drivers/i2c/i2c-core-base.c
> > @@ -99,8 +99,8 @@ const char *i2c_freq_mode_string(u32 bus_freq_hz)  }
> > EXPORT_SYMBOL_GPL(i2c_freq_mode_string);
> >
> > -const struct i2c_device_id *i2c_match_id(const struct i2c_device_id
> *id,
> > -                                               const struct
> i2c_client *client)
> > +static const struct i2c_device_id *i2c_match_device_id(const struct
> i2c_device_id *id,
> > +                                                      const struct
> > +i2c_client *client)
> >  {
> >         if (!(id && client))
> >                 return NULL;
> > @@ -110,10 +110,30 @@ const struct i2c_device_id *i2c_match_id(const
> struct i2c_device_id *id,
> >                         return id;
> >                 id++;
> >         }
> > +
> >         return NULL;
> >  }
> > +
> > +const struct i2c_device_id *i2c_match_id(const struct i2c_device_id
> *id,
> > +                                        const struct i2c_client
> > +*client) {
> > +       return i2c_match_device_id(id, client); }
> >  EXPORT_SYMBOL_GPL(i2c_match_id);
> 
> Is there any reason why you're adding a new intermediate?

The same code is shared between below function.
As discussed below, it is not required.

> 
> >
> > +const void *i2c_get_match_data(const struct i2c_device_id *id,
> > +                              const struct i2c_client *client)
> 
> I think this should take the id table from the i2c_driver, as pointed to
> by client->dev.driver, instead of from an explicitly passed parameter.

You mean const void *i2c_get_match_data(const struct i2c_client *client)??

struct i2c_driver	*driver = client->dev.driver;

And then call

match = i2c_match_id(driver->id_table, client)??

> 
> > +{
> > +       const struct i2c_device_id *match;
> > +
> > +       match = i2c_match_device_id(id, client);
> > +       if (!match)
> > +               return NULL;
> > +
> > +       return (const void *)match->driver_data;
> 
> One can discuss about the returned type: personally, I won't mind "const
> void *" for consistency with other subsystems (e.g. DT), but as
> i2c_device_id.driver_data has type "kernel_ulong_t", other people might
> prefer the latter.

The advantage of void*, is upper layer don't need casting.

eg: with kernel_ulong_t as return parameter:

isl1208->config = (struct isl1208_config *)i2c_get_match_data;

Cheers,
Biju



> 
> > +}
> > +EXPORT_SYMBOL(i2c_get_match_data);
> 




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux