linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
@ 2022-06-30 23:01 Nishanth Menon
  2022-07-01  3:38 ` Nishanth Menon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nishanth Menon @ 2022-06-30 23:01 UTC (permalink / raw)
  To: Javier Martinez Canillas, Nishanth Menon, Nuno Sá,
	Christophe JAILLET, Alexandru Ardelean, Lars-Peter Clausen,
	Jonathan Cameron
  Cc: linux-kernel, linux-iio, stable

When device_match_data is called - with device tree, of_match list is
looked up to find the data, which by default is 0. So, no matter which
kind of device compatible we use, we match with config 0 which implies
we enable 8 channels even on devices that do not have 8 channels.

Solve it by providing the match data similar to what we do with the ACPI
lookup information.

Fixes: 9e611c9e5a20 ("iio: adc128s052: Add OF match table")
Cc: <stable@vger.kernel.org> # 5.0+
Signed-off-by: Nishanth Menon <nm@ti.com>
---

Side note: commits 9e611c9e5a20c ("iio: adc128s052: Add OF match table"),
37cd3c8768edc ("iio: adc128s052: Add pin-compatible IDs"),
b41fa86b67bd3 ("iio:adc128s052: add support for adc124s021") introduce
code that is fixed by this patch, but it makes no real sense to go and
split this patch to apply to versions older than 5.0 - which seems to be
the earliest the patch would apply. I picked the "Add OF match table" as
the patch that set the precedence which follow on patches followed.

 drivers/iio/adc/ti-adc128s052.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
index 622fd384983c..21a7764cbb93 100644
--- a/drivers/iio/adc/ti-adc128s052.c
+++ b/drivers/iio/adc/ti-adc128s052.c
@@ -181,13 +181,13 @@ static int adc128_probe(struct spi_device *spi)
 }
 
 static const struct of_device_id adc128_of_match[] = {
-	{ .compatible = "ti,adc128s052", },
-	{ .compatible = "ti,adc122s021", },
-	{ .compatible = "ti,adc122s051", },
-	{ .compatible = "ti,adc122s101", },
-	{ .compatible = "ti,adc124s021", },
-	{ .compatible = "ti,adc124s051", },
-	{ .compatible = "ti,adc124s101", },
+	{ .compatible = "ti,adc128s052", .data = 0},
+	{ .compatible = "ti,adc122s021", .data = 1},
+	{ .compatible = "ti,adc122s051", .data = 1},
+	{ .compatible = "ti,adc122s101", .data = 1},
+	{ .compatible = "ti,adc124s021", .data = 2},
+	{ .compatible = "ti,adc124s051", .data = 2},
+	{ .compatible = "ti,adc124s101", .data = 2},
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, adc128_of_match);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
  2022-06-30 23:01 [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used Nishanth Menon
@ 2022-07-01  3:38 ` Nishanth Menon
  2022-07-01 10:08   ` Andy Shevchenko
  2022-07-01 10:13 ` Andy Shevchenko
  2022-07-05 17:47 ` kernel test robot
  2 siblings, 1 reply; 6+ messages in thread
From: Nishanth Menon @ 2022-07-01  3:38 UTC (permalink / raw)
  To: Javier Martinez Canillas, Nuno Sá,
	Christophe JAILLET, Alexandru Ardelean, Lars-Peter Clausen,
	Jonathan Cameron
  Cc: linux-kernel, linux-iio, stable

On 18:01-20220630, Nishanth Menon wrote:
[...]

> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> index 622fd384983c..21a7764cbb93 100644
> --- a/drivers/iio/adc/ti-adc128s052.c
> +++ b/drivers/iio/adc/ti-adc128s052.c
> @@ -181,13 +181,13 @@ static int adc128_probe(struct spi_device *spi)
>  }
>  
>  static const struct of_device_id adc128_of_match[] = {
> -	{ .compatible = "ti,adc128s052", },
> -	{ .compatible = "ti,adc122s021", },
> -	{ .compatible = "ti,adc122s051", },
> -	{ .compatible = "ti,adc122s101", },
> -	{ .compatible = "ti,adc124s021", },
> -	{ .compatible = "ti,adc124s051", },
> -	{ .compatible = "ti,adc124s101", },
> +	{ .compatible = "ti,adc128s052", .data = 0},

I should probably cast these as .data = (void *)0 thoughts?

[...]

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
  2022-07-01  3:38 ` Nishanth Menon
@ 2022-07-01 10:08   ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-07-01 10:08 UTC (permalink / raw)
  To: Nishanth Menon
  Cc: Javier Martinez Canillas, Nuno Sá,
	Christophe JAILLET, Alexandru Ardelean, Lars-Peter Clausen,
	Jonathan Cameron, Linux Kernel Mailing List, linux-iio, Stable

On Fri, Jul 1, 2022 at 5:41 AM Nishanth Menon <nm@ti.com> wrote:
> On 18:01-20220630, Nishanth Menon wrote:

...

> >  static const struct of_device_id adc128_of_match[] = {
> > -     { .compatible = "ti,adc128s052", },
> > -     { .compatible = "ti,adc122s021", },
> > -     { .compatible = "ti,adc122s051", },
> > -     { .compatible = "ti,adc122s101", },
> > -     { .compatible = "ti,adc124s021", },
> > -     { .compatible = "ti,adc124s051", },
> > -     { .compatible = "ti,adc124s101", },
> > +     { .compatible = "ti,adc128s052", .data = 0},
>
> I should probably cast these as .data = (void *)0 thoughts?

The 0 is default. You shouldn't use that in the first place for
something meaningful rather than "no, we have no driver data for this
chip).

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
  2022-06-30 23:01 [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used Nishanth Menon
  2022-07-01  3:38 ` Nishanth Menon
@ 2022-07-01 10:13 ` Andy Shevchenko
  2022-07-01 16:31   ` Jonathan Cameron
  2022-07-05 17:47 ` kernel test robot
  2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2022-07-01 10:13 UTC (permalink / raw)
  To: Nishanth Menon
  Cc: Javier Martinez Canillas, Nuno Sá,
	Christophe JAILLET, Alexandru Ardelean, Lars-Peter Clausen,
	Jonathan Cameron, Linux Kernel Mailing List, linux-iio, Stable

On Fri, Jul 1, 2022 at 1:02 AM Nishanth Menon <nm@ti.com> wrote:
>
> When device_match_data is called - with device tree, of_match list is

device_get_match_data() ?

> looked up to find the data, which by default is 0. So, no matter which
> kind of device compatible we use, we match with config 0 which implies
> we enable 8 channels even on devices that do not have 8 channels.
>
> Solve it by providing the match data similar to what we do with the ACPI
> lookup information.
>
> Fixes: 9e611c9e5a20 ("iio: adc128s052: Add OF match table")
> Cc: <stable@vger.kernel.org> # 5.0+
> Signed-off-by: Nishanth Menon <nm@ti.com>

...

> +       { .compatible = "ti,adc128s052", .data = 0},

No assignment, 0 _is_ the default here.

> +       { .compatible = "ti,adc122s021", .data = 1},
> +       { .compatible = "ti,adc122s051", .data = 1},
> +       { .compatible = "ti,adc122s101", .data = 1},
> +       { .compatible = "ti,adc124s021", .data = 2},
> +       { .compatible = "ti,adc124s051", .data = 2},
> +       { .compatible = "ti,adc124s101", .data = 2},

What you need _ideally_ is rather use pointers to data structure where
each of that chip is defined, then it will be as simple as


const struct my_custom_drvdata *data;

data = device_get_match_data(dev);

Where my_custom_drvdata::num_of_channels will be already assigned to
whatever you want on a per chip basis.

If the number of channels is the only data you have, then yes, cast it
to void * in the OF ID table and

num = (uintptr_t)device_get_match_data(dev);

will suffice.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
  2022-07-01 10:13 ` Andy Shevchenko
@ 2022-07-01 16:31   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2022-07-01 16:31 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Nishanth Menon, Javier Martinez Canillas, Nuno Sá,
	Christophe JAILLET, Alexandru Ardelean, Lars-Peter Clausen,
	Linux Kernel Mailing List, linux-iio, Stable

On Fri, 1 Jul 2022 12:13:24 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Fri, Jul 1, 2022 at 1:02 AM Nishanth Menon <nm@ti.com> wrote:
> >
> > When device_match_data is called - with device tree, of_match list is  
> 
> device_get_match_data() ?
> 
> > looked up to find the data, which by default is 0. So, no matter which
> > kind of device compatible we use, we match with config 0 which implies
> > we enable 8 channels even on devices that do not have 8 channels.
> >
> > Solve it by providing the match data similar to what we do with the ACPI
> > lookup information.
> >
> > Fixes: 9e611c9e5a20 ("iio: adc128s052: Add OF match table")
> > Cc: <stable@vger.kernel.org> # 5.0+
> > Signed-off-by: Nishanth Menon <nm@ti.com>  
> 
> ...
> 
> > +       { .compatible = "ti,adc128s052", .data = 0},  
> 
> No assignment, 0 _is_ the default here.
> 
> > +       { .compatible = "ti,adc122s021", .data = 1},
> > +       { .compatible = "ti,adc122s051", .data = 1},
> > +       { .compatible = "ti,adc122s101", .data = 1},
> > +       { .compatible = "ti,adc124s021", .data = 2},
> > +       { .compatible = "ti,adc124s051", .data = 2},
> > +       { .compatible = "ti,adc124s101", .data = 2},  
> 
> What you need _ideally_ is rather use pointers to data structure where
> each of that chip is defined, then it will be as simple as
> 
> 
> const struct my_custom_drvdata *data;
> 
> data = device_get_match_data(dev);
> 
> Where my_custom_drvdata::num_of_channels will be already assigned to
> whatever you want on a per chip basis.

Agreed. That's much nicer and a not a lot larger change so still suitable as a fix.

> 
> If the number of channels is the only data you have, then yes, cast it
> to void * in the OF ID table and

It's not just the number of channels.  This is an index into an array of chip
type specific structures. Hence the driver is half way to what you suggested.
Using a pointer for the ACPI and DT paths is the right way to do this.
For the spi_device_id table, you could stick with an index, or move to casting
a pointer to an integer, I don't really mind.

Thanks,

Jonathan

> 
> num = (uintptr_t)device_get_match_data(dev);
> 
> will suffice.
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used
  2022-06-30 23:01 [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used Nishanth Menon
  2022-07-01  3:38 ` Nishanth Menon
  2022-07-01 10:13 ` Andy Shevchenko
@ 2022-07-05 17:47 ` kernel test robot
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-07-05 17:47 UTC (permalink / raw)
  To: Nishanth Menon, Javier Martinez Canillas, Nuno Sá,
	Christophe JAILLET, Alexandru Ardelean, Lars-Peter Clausen,
	Jonathan Cameron
  Cc: kbuild-all, linux-kernel, linux-iio, stable

Hi Nishanth,

I love your patch! Perhaps something to improve:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v5.19-rc5 next-20220705]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Nishanth-Menon/iio-adc-ti-adc128s052-Fix-number-of-channels-when-device-tree-is-used/20220701-070342
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: nios2-randconfig-r036-20220703 (https://download.01.org/0day-ci/archive/20220706/202207060155.zkacpxjc-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/d5184722ec9ae186da9bed1497e4804297f2040b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Nishanth-Menon/iio-adc-ti-adc128s052-Fix-number-of-channels-when-device-tree-is-used/20220701-070342
        git checkout d5184722ec9ae186da9bed1497e4804297f2040b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=nios2 SHELL=/bin/bash drivers/iio/adc/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/iio/adc/ti-adc128s052.c:185:50: warning: initialization of 'const void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     185 |         { .compatible = "ti,adc122s021", .data = 1},
         |                                                  ^
   drivers/iio/adc/ti-adc128s052.c:185:50: note: (near initialization for 'adc128_of_match[1].data')
   drivers/iio/adc/ti-adc128s052.c:186:50: warning: initialization of 'const void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     186 |         { .compatible = "ti,adc122s051", .data = 1},
         |                                                  ^
   drivers/iio/adc/ti-adc128s052.c:186:50: note: (near initialization for 'adc128_of_match[2].data')
   drivers/iio/adc/ti-adc128s052.c:187:50: warning: initialization of 'const void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     187 |         { .compatible = "ti,adc122s101", .data = 1},
         |                                                  ^
   drivers/iio/adc/ti-adc128s052.c:187:50: note: (near initialization for 'adc128_of_match[3].data')
   drivers/iio/adc/ti-adc128s052.c:188:50: warning: initialization of 'const void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     188 |         { .compatible = "ti,adc124s021", .data = 2},
         |                                                  ^
   drivers/iio/adc/ti-adc128s052.c:188:50: note: (near initialization for 'adc128_of_match[4].data')
   drivers/iio/adc/ti-adc128s052.c:189:50: warning: initialization of 'const void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     189 |         { .compatible = "ti,adc124s051", .data = 2},
         |                                                  ^
   drivers/iio/adc/ti-adc128s052.c:189:50: note: (near initialization for 'adc128_of_match[5].data')
   drivers/iio/adc/ti-adc128s052.c:190:50: warning: initialization of 'const void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     190 |         { .compatible = "ti,adc124s101", .data = 2},
         |                                                  ^
   drivers/iio/adc/ti-adc128s052.c:190:50: note: (near initialization for 'adc128_of_match[6].data')


vim +185 drivers/iio/adc/ti-adc128s052.c

   182	
   183	static const struct of_device_id adc128_of_match[] = {
   184		{ .compatible = "ti,adc128s052", .data = 0},
 > 185		{ .compatible = "ti,adc122s021", .data = 1},
   186		{ .compatible = "ti,adc122s051", .data = 1},
   187		{ .compatible = "ti,adc122s101", .data = 1},
   188		{ .compatible = "ti,adc124s021", .data = 2},
   189		{ .compatible = "ti,adc124s051", .data = 2},
   190		{ .compatible = "ti,adc124s101", .data = 2},
   191		{ /* sentinel */ },
   192	};
   193	MODULE_DEVICE_TABLE(of, adc128_of_match);
   194	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-05 17:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 23:01 [PATCH] iio: adc: ti-adc128s052: Fix number of channels when device tree is used Nishanth Menon
2022-07-01  3:38 ` Nishanth Menon
2022-07-01 10:08   ` Andy Shevchenko
2022-07-01 10:13 ` Andy Shevchenko
2022-07-01 16:31   ` Jonathan Cameron
2022-07-05 17:47 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).