diff mbox series

[v6,3/4] i2c: Enhance i2c_get_match_data()

Message ID 20230804070915.117829-4-biju.das.jz@bp.renesas.com
State Handled Elsewhere
Headers show
Series Extend device_get_match_data() to struct bus_type | expand

Commit Message

Biju Das Aug. 4, 2023, 7:09 a.m. UTC
Enhance i2c_get_match_data() for a faster path for device_get_
match_data().

While at it, add const to struct i2c_driver to prevent overriding
the driver pointer.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v6:
 * Separate patch to prepare for better difference for
   i2c_match_id() changes.
---
 drivers/i2c/i2c-core-base.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Andy Shevchenko Aug. 4, 2023, 2:50 p.m. UTC | #1
On Fri, Aug 04, 2023 at 08:09:14AM +0100, Biju Das wrote:
> Enhance i2c_get_match_data() for a faster path for device_get_
> match_data().

Strange wrap, the function name shouldn't have a new line in between :-)

> While at it, add const to struct i2c_driver to prevent overriding
> the driver pointer.

...

> v6:
>  * Separate patch to prepare for better difference for
>    i2c_match_id() changes.

With this it actually should be patch 2 and patch 2 become 3
(there is not much difference code wise, but logically this
 can be applied even without the rest).

With the above addressed
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Biju Das Aug. 4, 2023, 3:20 p.m. UTC | #2
Hi Andy Shevchenko,

Thanks for the feedback.

> Subject: Re: [PATCH v6 3/4] i2c: Enhance i2c_get_match_data()
> 
> On Fri, Aug 04, 2023 at 08:09:14AM +0100, Biju Das wrote:
> > Enhance i2c_get_match_data() for a faster path for device_get_
> > match_data().
> 
> Strange wrap, the function name shouldn't have a new line in between :-)

OK. Wrapping is not required, as it is fitting to chars

scripts/checkpatch.pl --strict 0002-i2c-Enhance-i2c_get_match_data.patch 
total: 0 errors, 0 warnings, 0 checks, 27 lines checked

0002-i2c-Enhance-i2c_get_match_data.patch has no obvious style problems and is ready for submission.

> 
> > While at it, add const to struct i2c_driver to prevent overriding the
> > driver pointer.
> 
> ...
> 
> > v6:
> >  * Separate patch to prepare for better difference for
> >    i2c_match_id() changes.
> 
> With this it actually should be patch 2 and patch 2 become 3 (there is not
> much difference code wise, but logically this  can be applied even without
> the rest).

OK will move to patch#2.

Cheers,
Biju

> 
> With the above addressed
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> --
> With Best Regards,
> Andy Shevchenko
>
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 60746652fd52..7005dfe64066 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -116,20 +116,19 @@  EXPORT_SYMBOL_GPL(i2c_match_id);
 
 const void *i2c_get_match_data(const struct i2c_client *client)
 {
-	struct i2c_driver *driver = to_i2c_driver(client->dev.driver);
+	const struct i2c_driver *driver = to_i2c_driver(client->dev.driver);
 	const struct i2c_device_id *match;
 	const void *data;
 
 	data = device_get_match_data(&client->dev);
-	if (!data) {
-		match = i2c_match_id(driver->id_table, client);
-		if (!match)
-			return NULL;
+	if (data)
+		return data;
 
-		data = (const void *)match->driver_data;
-	}
+	match = i2c_match_id(driver->id_table, client);
+	if (!match)
+		return NULL;
 
-	return data;
+	return (const void *)match->driver_data;
 }
 EXPORT_SYMBOL(i2c_get_match_data);