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

Alexander A. Klimov posted 1 patch 4 days, 3 hours ago
There is a newer version of this series
drivers/iio/light/al3010.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
[PATCH] iio: light: al3010: read both ALS ADC registers again
Posted by Alexander A. Klimov 4 days, 3 hours ago
al3010_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: 0e5e21e23dd6 ("iio: light: al3010: Implement regmap support")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
---
 drivers/iio/light/al3010.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c
index 0932fa2b49fa..1800776d725e 100644
--- a/drivers/iio/light/al3010.c
+++ b/drivers/iio/light/al3010.c
@@ -111,7 +111,8 @@ static int al3010_read_raw(struct iio_dev *indio_dev,
 			   int *val2, long mask)
 {
 	struct al3010_data *data = iio_priv(indio_dev);
-	int ret, gain, raw;
+	int ret, gain;
+	uint16_t raw;
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
@@ -120,11 +121,12 @@ static int al3010_read_raw(struct iio_dev *indio_dev,
 		 * - low byte of output is stored at AL3010_REG_DATA_LOW
 		 * - high byte of output is stored at AL3010_REG_DATA_LOW + 1
 		 */
-		ret = regmap_read(data->regmap, AL3010_REG_DATA_LOW, &raw);
+		ret = regmap_bulk_read(data->regmap, AL3010_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: al3010: read both ALS ADC registers again
Posted by Jonathan Cameron 3 days, 10 hours ago
On Wed, 20 May 2026 19:58:49 +0200
"Alexander A. Klimov" <grandmaster@al2klimov.de> wrote:

> al3010_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: 0e5e21e23dd6 ("iio: light: al3010: Implement regmap support")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>

Hi Alexander,

> ---
>  drivers/iio/light/al3010.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c
> index 0932fa2b49fa..1800776d725e 100644
> --- a/drivers/iio/light/al3010.c
> +++ b/drivers/iio/light/al3010.c
> @@ -111,7 +111,8 @@ static int al3010_read_raw(struct iio_dev *indio_dev,
>  			   int *val2, long mask)
>  {
>  	struct al3010_data *data = iio_priv(indio_dev);
> -	int ret, gain, raw;
> +	int ret, gain;
> +	uint16_t raw;

Kernel types, and more relevantly as the bot pointed out

	__le16 raw;

>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
> @@ -120,11 +121,12 @@ static int al3010_read_raw(struct iio_dev *indio_dev,
>  		 * - low byte of output is stored at AL3010_REG_DATA_LOW
>  		 * - high byte of output is stored at AL3010_REG_DATA_LOW + 1
>  		 */
> -		ret = regmap_read(data->regmap, AL3010_REG_DATA_LOW, &raw);
> +		ret = regmap_bulk_read(data->regmap, AL3010_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: al3010: read both ALS ADC registers again
Posted by kernel test robot 3 days, 18 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-al3010-read-both-ALS-ADC-registers-again/20260521-024036
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20260520175855.538098-1-grandmaster%40al2klimov.de
patch subject: [PATCH] iio: light: al3010: read both ALS ADC registers again
config: sh-randconfig-r111-20260521 (https://download.01.org/0day-ci/archive/20260521/202605211105.cR7k7vyR-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 13.4.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260521/202605211105.cR7k7vyR-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/202605211105.cR7k7vyR-lkp@intel.com/

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

vim +129 drivers/iio/light/al3010.c

   108	
   109	static int al3010_read_raw(struct iio_dev *indio_dev,
   110				   struct iio_chan_spec const *chan, int *val,
   111				   int *val2, long mask)
   112	{
   113		struct al3010_data *data = iio_priv(indio_dev);
   114		int ret, gain;
   115		uint16_t raw;
   116	
   117		switch (mask) {
   118		case IIO_CHAN_INFO_RAW:
   119			/*
   120			 * ALS ADC value is stored in two adjacent registers:
   121			 * - low byte of output is stored at AL3010_REG_DATA_LOW
   122			 * - high byte of output is stored at AL3010_REG_DATA_LOW + 1
   123			 */
   124			ret = regmap_bulk_read(data->regmap, AL3010_REG_DATA_LOW,
   125					       &raw, sizeof(raw));
   126			if (ret)
   127				return ret;
   128	
 > 129			*val = le16_to_cpu(raw);
   130	
   131			return IIO_VAL_INT;
   132		case IIO_CHAN_INFO_SCALE:
   133			ret = regmap_read(data->regmap, AL3010_REG_CONFIG, &gain);
   134			if (ret)
   135				return ret;
   136	
   137			gain = FIELD_GET(AL3010_GAIN_MASK, gain);
   138			*val = al3010_scales[gain][0];
   139			*val2 = al3010_scales[gain][1];
   140	
   141			return IIO_VAL_INT_PLUS_MICRO;
   142		}
   143		return -EINVAL;
   144	}
   145	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] iio: light: al3010: read both ALS ADC registers again
Posted by David Heidelberg 4 days, 2 hours ago
On 20/05/2026 19:58, Alexander A. Klimov wrote:
> al3010_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.

Good catch!

Reviewed-by: David Heidelberg <david@ixit.cz>

Thank you. If you're at it, could you post same patch for the al3320a? Asus 
tf701t likely suffer the same issue.

David

> 
> Fixes: 0e5e21e23dd6 ("iio: light: al3010: Implement regmap support")
> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
> ---
>   drivers/iio/light/al3010.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c
> index 0932fa2b49fa..1800776d725e 100644
> --- a/drivers/iio/light/al3010.c
> +++ b/drivers/iio/light/al3010.c
> @@ -111,7 +111,8 @@ static int al3010_read_raw(struct iio_dev *indio_dev,
>   			   int *val2, long mask)
>   {
>   	struct al3010_data *data = iio_priv(indio_dev);
> -	int ret, gain, raw;
> +	int ret, gain;
> +	uint16_t raw;
>   
>   	switch (mask) {
>   	case IIO_CHAN_INFO_RAW:
> @@ -120,11 +121,12 @@ static int al3010_read_raw(struct iio_dev *indio_dev,
>   		 * - low byte of output is stored at AL3010_REG_DATA_LOW
>   		 * - high byte of output is stored at AL3010_REG_DATA_LOW + 1
>   		 */
> -		ret = regmap_read(data->regmap, AL3010_REG_DATA_LOW, &raw);
> +		ret = regmap_bulk_read(data->regmap, AL3010_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:

-- 
David Heidelberg