2020-09-15 01:43:26

by Tian Tao

[permalink] [raw]
Subject: [PATCH] i2c: Switch to using the new API kobj_to_dev()

Switch to using the new API kobj_to_dev().

Signed-off-by: Tian Tao <[email protected]>
---
include/linux/i2c.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index fc55ea4..5662265 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -344,7 +344,7 @@ const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,

static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
{
- struct device * const dev = container_of(kobj, struct device, kobj);
+ struct device * const dev = kobj_to_dev(kobj);
return to_i2c_client(dev);
}

--
2.7.4


2020-09-18 21:10:52

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: Switch to using the new API kobj_to_dev()


> static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
> {
> - struct device * const dev = container_of(kobj, struct device, kobj);
> + struct device * const dev = kobj_to_dev(kobj);
> return to_i2c_client(dev);

Can't we make this a oneliner then merging the last two lines?


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

2020-09-19 01:03:41

by tiantao (H)

[permalink] [raw]
Subject: Re: [PATCH] i2c: Switch to using the new API kobj_to_dev()



在 2020/9/19 5:09, [email protected] 写道:
>
>> static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
>> {
>> - struct device * const dev = container_of(kobj, struct device, kobj);
>> + struct device * const dev = kobj_to_dev(kobj);
>> return to_i2c_client(dev);
>
> Can't we make this a oneliner then merging the last two lines?
>
I think two lines have better readability, and if you prefer one line, I
can send v2 to fix that!

2020-09-19 06:34:33

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: Switch to using the new API kobj_to_dev()

On Sat, Sep 19, 2020 at 09:01:12AM +0800, tiantao (H) wrote:
>
>
> 在 2020/9/19 5:09, [email protected] 写道:
> >
> > > static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
> > > {
> > > - struct device * const dev = container_of(kobj, struct device, kobj);
> > > + struct device * const dev = kobj_to_dev(kobj);
> > > return to_i2c_client(dev);
> >
> > Can't we make this a oneliner then merging the last two lines?
> >
> I think two lines have better readability, and if you prefer one line, I can
> send v2 to fix that!

I just found d75d53cd571c ("i2c: Fix sparse warning in i2c.h"), so we
should leave the two lines. Thanks!


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

2020-09-21 09:17:59

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: Switch to using the new API kobj_to_dev()

On Tue, Sep 15, 2020 at 09:38:18AM +0800, Tian Tao wrote:
> Switch to using the new API kobj_to_dev().
>
> Signed-off-by: Tian Tao <[email protected]>

Applied to for-next, thanks!


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