2020-08-20 03:05:17

by Tian Tao

[permalink] [raw]
Subject: [PATCH] iio: adc: adi-axi-adc: Use kobj_to_dev() instead of container_of()

Use kobj_to_dev() instead of container_of()

Signed-off-by: Tian Tao <[email protected]>
---
drivers/iio/adc/adi-axi-adc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 86b6b65..9109da2 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -276,7 +276,7 @@ static struct attribute *adi_axi_adc_attributes[] = {
static umode_t axi_adc_attr_is_visible(struct kobject *kobj,
struct attribute *attr, int n)
{
- struct device *dev = container_of(kobj, struct device, kobj);
+ struct device *dev = kobj_to_dev(kobj);
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct adi_axi_adc_state *st = iio_priv(indio_dev);
struct adi_axi_adc_conv *conv = &st->client->conv;
--
2.7.4


2020-08-20 09:13:04

by Alexandru Ardelean

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: adi-axi-adc: Use kobj_to_dev() instead of container_of()

On Thu, Aug 20, 2020 at 6:04 AM Tian Tao <[email protected]> wrote:
>
> Use kobj_to_dev() instead of container_of()
>

Good point.

Acked-by: Alexandru Ardelean <[email protected]>

> Signed-off-by: Tian Tao <[email protected]>
> ---
> drivers/iio/adc/adi-axi-adc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
> index 86b6b65..9109da2 100644
> --- a/drivers/iio/adc/adi-axi-adc.c
> +++ b/drivers/iio/adc/adi-axi-adc.c
> @@ -276,7 +276,7 @@ static struct attribute *adi_axi_adc_attributes[] = {
> static umode_t axi_adc_attr_is_visible(struct kobject *kobj,
> struct attribute *attr, int n)
> {
> - struct device *dev = container_of(kobj, struct device, kobj);
> + struct device *dev = kobj_to_dev(kobj);
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct adi_axi_adc_state *st = iio_priv(indio_dev);
> struct adi_axi_adc_conv *conv = &st->client->conv;
> --
> 2.7.4
>

2020-08-20 13:07:23

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: adi-axi-adc: Use kobj_to_dev() instead of container_of()

On Thu, Aug 20, 2020 at 12:10 PM Alexandru Ardelean
<[email protected]> wrote:
> On Thu, Aug 20, 2020 at 6:04 AM Tian Tao <[email protected]> wrote:
> >
> > Use kobj_to_dev() instead of container_of()

> Good point.
>
> Acked-by: Alexandru Ardelean <[email protected]>

...

> > - struct device *dev = container_of(kobj, struct device, kobj);
> > + struct device *dev = kobj_to_dev(kobj);
> > struct iio_dev *indio_dev = dev_to_iio_dev(dev);

And now this can be one line since dev is not used separately.

> > struct adi_axi_adc_state *st = iio_priv(indio_dev);
> > struct adi_axi_adc_conv *conv = &st->client->conv;

--
With Best Regards,
Andy Shevchenko

2020-08-20 13:10:53

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: adi-axi-adc: Use kobj_to_dev() instead of container_of()

On Thu, Aug 20, 2020 at 4:05 PM Andy Shevchenko
<[email protected]> wrote:
> On Thu, Aug 20, 2020 at 12:10 PM Alexandru Ardelean
> <[email protected]> wrote:
> > On Thu, Aug 20, 2020 at 6:04 AM Tian Tao <[email protected]> wrote:

> > > - struct device *dev = container_of(kobj, struct device, kobj);
> > > + struct device *dev = kobj_to_dev(kobj);

> And now this can be one line since dev is not used separately.

On the other hand perhaps one object per line is better to read.

--
With Best Regards,
Andy Shevchenko

2020-08-22 10:48:14

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH] iio: adc: adi-axi-adc: Use kobj_to_dev() instead of container_of()

On Thu, 20 Aug 2020 16:07:04 +0300
Andy Shevchenko <[email protected]> wrote:

> On Thu, Aug 20, 2020 at 4:05 PM Andy Shevchenko
> <[email protected]> wrote:
> > On Thu, Aug 20, 2020 at 12:10 PM Alexandru Ardelean
> > <[email protected]> wrote:
> > > On Thu, Aug 20, 2020 at 6:04 AM Tian Tao <[email protected]> wrote:
>
> > > > - struct device *dev = container_of(kobj, struct device, kobj);
> > > > + struct device *dev = kobj_to_dev(kobj);
>
> > And now this can be one line since dev is not used separately.
>
> On the other hand perhaps one object per line is better to read.
>

Indeed, not clear one way or the others, so I'm going with the path of
least resistance. Applied as is.

Thanks,

Jonathan