diff mbox series

i2c: Switch to using the new API kobj_to_dev()

Message ID 1600133898-35883-1-git-send-email-tiantao6@hisilicon.com
State Accepted
Commit b1d4dc15b2f430a4f541ab6c91e63a71cf230b7d
Headers show
Series i2c: Switch to using the new API kobj_to_dev() | expand

Commit Message

Tian Tao Sept. 15, 2020, 1:38 a.m. UTC
Switch to using the new API kobj_to_dev().

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---
 include/linux/i2c.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Wolfram Sang Sept. 18, 2020, 9:09 p.m. UTC | #1
>  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?
tiantao (H) Sept. 19, 2020, 1:01 a.m. UTC | #2
在 2020/9/19 5:09, wsa@kernel.org 写道:
> 

>>   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!
Wolfram Sang Sept. 19, 2020, 6:32 a.m. UTC | #3
On Sat, Sep 19, 2020 at 09:01:12AM +0800, tiantao (H) wrote:
> 
> 
> 在 2020/9/19 5:09, wsa@kernel.org 写道:
> > 
> > >   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!
Wolfram Sang Sept. 21, 2020, 9:14 a.m. UTC | #4
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 <tiantao6@hisilicon.com>


Applied to for-next, thanks!
diff mbox series

Patch

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);
 }