public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Biju Das <biju.das.jz@bp.renesas.com>,
	Wolfram Sang <wsa@kernel.org>,
	linux-i2c@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v3 2/2] i2c: Add i2c_device_get_match_data() callback
Date: Tue, 1 Aug 2023 13:41:09 -0700	[thread overview]
Message-ID: <ZMlt5SpEgawlWHoB@google.com> (raw)
In-Reply-To: <ZMlc5jHfSf/bOCe3@smile.fi.intel.com>

On Tue, Aug 01, 2023 at 10:28:38PM +0300, Andy Shevchenko wrote:
> On Tue, Aug 01, 2023 at 06:03:18PM +0100, Biju Das wrote:
> > Add i2c_device_get_match_data() callback to struct bus_type().
> > 
> > While at it, introduced i2c_get_match_data_helper() to avoid code
> > duplication with i2c_get_match_data().
> 
> Have you used --patience when prepared the patch for sending?
> 
> ...
> 
> > -const void *i2c_get_match_data(const struct i2c_client *client)
> > +static const void *i2c_get_match_data_helper(const struct i2c_driver *driver,
> > +					     const struct i2c_client *client)
> >  {
> 
> > -	struct i2c_driver *driver = to_i2c_driver(client->dev.driver);
> 
> Does it make sense to remove and add an additional parameter? In one case it's
> a copy, in another it probably the same, just hidden in the code.
> 
> >  	const struct i2c_device_id *match;
> > +
> > +	match = i2c_match_id(driver->id_table, client);
> > +	if (!match)
> > +		return NULL;
> > +
> > +	return (const void *)match->driver_data;
> > +}
> > +
> > +static const void *i2c_device_get_match_data(const struct device *dev)
> > +{
> > +	/* TODO: use i2c_verify_client() when it accepts const pointer */
> > +	const struct i2c_client *client = (dev->type == &i2c_client_type) ?
> > +					  to_i2c_client(dev) : NULL;
> >  	const void *data;
> 
> > +	if (!dev->driver)
> > +		return NULL;
> 
> When can this be true?

It is not guaranteed that the function is always called on a device
bound to a driver (even though we normally expect this to be the case).

> 
> > +	data = i2c_get_match_data_helper(to_i2c_driver(dev->driver), client);
> > +	if (data)
> > +		return data;
> >  
> > -		data = (const void *)match->driver_data;
> > +	if (dev->driver->of_match_table) {
> > +		const struct of_device_id *match;
> > +
> > +		match = i2c_of_match_device_sysfs(dev->driver->of_match_table,
> > +						  (struct i2c_client *)client);

Can we make i2c_of_match_device_sysfs() take a const pointer to a
client? Casting away constness is something that we should avoid.

> > +		if (match)
> > +			data = match->data;
> >  	}
> >  
> >  	return data;
> >  }
> 
> ...
> 
> > -static const struct of_device_id*
> > +const struct of_device_id*
> 
> While here, add a missing space after of_device_id.
> 
> ...
> 
> > +const struct of_device_id*
> 
> Ditto.
> 
> Or use below (weird) style in case it occurs more often than usual one.
> 
> > +i2c_of_match_device_sysfs(const struct of_device_id *matches,
> > +			  struct i2c_client *client);
> > +
> >  const struct of_device_id
> >  *i2c_of_match_device(const struct of_device_id *matches,
> >  		     struct i2c_client *client);
> 
> ...
> 
> > +static inline const struct of_device_id
> > +*i2c_of_match_device(const struct of_device_id *matches,
> 
> As per above.

Was it supposed to be i2c_of_match_device_sysfs()? Also, this should be
in drivers/i2c/i2c-core.h, not in public header.

Thanks.

-- 
Dmitry

  reply	other threads:[~2023-08-01 20:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 17:03 [PATCH v3 0/2] Extend device_get_match_data() to struct bus_type Biju Das
2023-08-01 17:03 ` [PATCH v3 2/2] i2c: Add i2c_device_get_match_data() callback Biju Das
2023-08-01 19:28   ` Andy Shevchenko
2023-08-01 20:41     ` Dmitry Torokhov [this message]
2023-08-02  9:34       ` Biju Das
2023-08-02 14:23         ` Andy Shevchenko
2023-08-02  7:59     ` Biju Das
2023-08-02 14:41       ` Andy Shevchenko
2023-08-01 19:29   ` Andy Shevchenko
2023-08-02  6:34     ` Biju Das
2023-08-02 14:44       ` Andy Shevchenko
2023-08-02  4:12   ` kernel test robot
2023-08-02 11:04     ` Biju Das
2023-08-02  4:22   ` kernel test robot
2023-08-02  4:22   ` kernel test robot
2023-08-02  5:25   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZMlt5SpEgawlWHoB@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox