2022-11-25 08:19:42

by ye.xingchen

[permalink] [raw]
Subject: [PATCH] i2c: Use device_match_of_node()

From: ye xingchen <[email protected]>

Replace the open-code with device_match_of_node().

Signed-off-by: ye xingchen <[email protected]>
---
drivers/i2c/i2c-core-of.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index 3ed74aa4b44b..307a0adf6bc1 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -115,11 +115,11 @@ void of_i2c_register_devices(struct i2c_adapter *adap)

static int of_dev_or_parent_node_match(struct device *dev, const void *data)
{
- if (dev->of_node == data)
+ if (device_match_of_node(dev, data))
return 1;

if (dev->parent)
- return dev->parent->of_node == data;
+ return device_match_of_node(dev->parent, data);

return 0;
}
--
2.25.1


2022-11-25 09:08:16

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: Use device_match_of_node()

Hi,

On Fri, Nov 25, 2022 at 03:51:03PM +0800, [email protected] wrote:
> From: ye xingchen <[email protected]>
>
> Replace the open-code with device_match_of_node().

Frankly, I don't like it. It doesn't look more readable and it doesn't
prevent from subtle bugs. device_match_of_node() was introduced when you
are *iterating* over a list of devices, see the commit which introduced
it. I think replacing every 'open coded' version with this helper is a
bad idea.

Happy hacking,

Wolfram

>
> Signed-off-by: ye xingchen <[email protected]>
> ---
> drivers/i2c/i2c-core-of.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
> index 3ed74aa4b44b..307a0adf6bc1 100644
> --- a/drivers/i2c/i2c-core-of.c
> +++ b/drivers/i2c/i2c-core-of.c
> @@ -115,11 +115,11 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
>
> static int of_dev_or_parent_node_match(struct device *dev, const void *data)
> {
> - if (dev->of_node == data)
> + if (device_match_of_node(dev, data))
> return 1;
>
> if (dev->parent)
> - return dev->parent->of_node == data;
> + return device_match_of_node(dev->parent, data);
>
> return 0;
> }
> --
> 2.25.1


Attachments:
(No filename) (1.26 kB)
signature.asc (849.00 B)
Download all attachments