[PATCH] iio: light: al3320a: read both ALS ADC registers again

Alexander A. Klimov posted 1 patch 3 days, 16 hours ago
There is a newer version of this series
drivers/iio/light/al3320a.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
[PATCH] iio: light: al3320a: read both ALS ADC registers again
Posted by Alexander A. Klimov 3 days, 16 hours ago
al3320a_read_raw() used to read two adjacent registers
until the driver was modernized using the regmap framework.
That cleanup accidentally replaced the 16-bit word read
with a single byte read. I'm reverting latter.

Fixes: 1850e6ae7f91 ("iio: light: al3320a: Implement regmap support")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
 drivers/iio/light/al3320a.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c
index 63f5a85912fc..f40b8b36f22d 100644
--- a/drivers/iio/light/al3320a.c
+++ b/drivers/iio/light/al3320a.c
@@ -135,7 +135,8 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,
 			    int *val2, long mask)
 {
 	struct al3320a_data *data = iio_priv(indio_dev);
-	int ret, gain, raw;
+	int ret, gain;
+	uint16_t raw;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
@@ -144,11 +145,12 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,
 		 * - low byte of output is stored at AL3320A_REG_DATA_LOW
 		 * - high byte of output is stored at AL3320A_REG_DATA_LOW + 1
 		 */
-		ret = regmap_read(data->regmap, AL3320A_REG_DATA_LOW, &raw);
+		ret = regmap_bulk_read(data->regmap, AL3320A_REG_DATA_LOW,
+				       &raw, sizeof(raw));
 		if (ret)
 			return ret;
 
-		*val = raw;
+		*val = le16_to_cpu(raw);
 
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-- 
2.54.0
Re: [PATCH] iio: light: al3320a: read both ALS ADC registers again
Posted by Jonathan Cameron 2 days, 6 hours ago
On Thu, 21 May 2026 06:10:35 +0200
"Alexander A. Klimov" <grandmaster@al2klimov.de> wrote:

> al3320a_read_raw() used to read two adjacent registers
> until the driver was modernized using the regmap framework.
> That cleanup accidentally replaced the 16-bit word read
> with a single byte read. I'm reverting latter.
> 
> Fixes: 1850e6ae7f91 ("iio: light: al3320a: Implement regmap support")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
>  drivers/iio/light/al3320a.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c
> index 63f5a85912fc..f40b8b36f22d 100644
> --- a/drivers/iio/light/al3320a.c
> +++ b/drivers/iio/light/al3320a.c
> @@ -135,7 +135,8 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,
>  			    int *val2, long mask)
>  {
>  	struct al3320a_data *data = iio_priv(indio_dev);
> -	int ret, gain, raw;
> +	int ret, gain;
> +	uint16_t raw;

Just for completeness as same as the other one.
	__le16 raw;

Which is what the bot is also complaining about

Thanks,

Jonathan


>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> @@ -144,11 +145,12 @@ static int al3320a_read_raw(struct iio_dev *indio_dev,
>  		 * - low byte of output is stored at AL3320A_REG_DATA_LOW
>  		 * - high byte of output is stored at AL3320A_REG_DATA_LOW + 1
>  		 */
> -		ret = regmap_read(data->regmap, AL3320A_REG_DATA_LOW, &raw);
> +		ret = regmap_bulk_read(data->regmap, AL3320A_REG_DATA_LOW,
> +				       &raw, sizeof(raw));
>  		if (ret)
>  			return ret;
>  
> -		*val = raw;
> +		*val = le16_to_cpu(raw);
>  
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
Re: [PATCH] iio: light: al3320a: read both ALS ADC registers again
Posted by kernel test robot 3 days, 10 hours ago
Hi Alexander,

kernel test robot noticed the following build warnings:

[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v7.1-rc4 next-20260520]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Alexander-A-Klimov/iio-light-al3320a-read-both-ALS-ADC-registers-again/20260521-121359
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20260521041041.542095-1-grandmaster%40al2klimov.de
patch subject: [PATCH] iio: light: al3320a: read both ALS ADC registers again
config: csky-randconfig-r133-20260521 (https://download.01.org/0day-ci/archive/20260521/202605211815.ZBkYyHp5-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 15.2.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260521/202605211815.ZBkYyHp5-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605211815.ZBkYyHp5-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/iio/light/al3320a.c:153:24: sparse: sparse: cast to restricted __le16

vim +153 drivers/iio/light/al3320a.c

   132	
   133	static int al3320a_read_raw(struct iio_dev *indio_dev,
   134				    struct iio_chan_spec const *chan, int *val,
   135				    int *val2, long mask)
   136	{
   137		struct al3320a_data *data = iio_priv(indio_dev);
   138		int ret, gain;
   139		uint16_t raw;
   140	
   141		switch (mask) {
   142		case IIO_CHAN_INFO_RAW:
   143			/*
   144			 * ALS ADC value is stored in two adjacent registers:
   145			 * - low byte of output is stored at AL3320A_REG_DATA_LOW
   146			 * - high byte of output is stored at AL3320A_REG_DATA_LOW + 1
   147			 */
   148			ret = regmap_bulk_read(data->regmap, AL3320A_REG_DATA_LOW,
   149					       &raw, sizeof(raw));
   150			if (ret)
   151				return ret;
   152	
 > 153			*val = le16_to_cpu(raw);
   154	
   155			return IIO_VAL_INT;
   156		case IIO_CHAN_INFO_SCALE:
   157			ret = regmap_read(data->regmap, AL3320A_REG_CONFIG_RANGE, &gain);
   158			if (ret)
   159				return ret;
   160	
   161			gain = FIELD_GET(AL3320A_GAIN_MASK, gain);
   162			*val = al3320a_scales[gain][0];
   163			*val2 = al3320a_scales[gain][1];
   164	
   165			return IIO_VAL_INT_PLUS_MICRO;
   166		}
   167		return -EINVAL;
   168	}
   169	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki