Skip to contentSkip to conversation

drivers/base/regmap/regmap-i2c.c:340:42: sparse: sparse: incorrect type in argument 3 (different base types)

PATCH In review kernel test robot 3 participants 9 messages May 16 – May 22

Subsystems (2)
lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   d458a240344c4369bf6f3da203f2779515177738
commit: bad4bd28abf4d7cb2adcb39cc0de789729d2cd69 regmap-i2c: add SMBus byte/word reg16 bus for adapters lacking I2C_FUNC_I2C
date:   5 weeks ago
config: x86_64-randconfig-122-20260516 (https://download.01.org/0day-ci/archive/20260516/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260516/[email protected]/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

| Fixes: bad4bd28abf4 ("regmap-i2c: add SMBus byte/word reg16 bus for adapters lacking I2C_FUNC_I2C")
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/base/regmap/regmap-i2c.c:340:42: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected unsigned short [usertype] value @@     got restricted __le16 [usertype] @@

drivers/base/regmap/regmap-i2c.c:340:42: sparse: expected unsigned short [usertype] value
drivers/base/regmap/regmap-i2c.c:340:42: sparse: got restricted __le16 [usertype]

vim +340 drivers/base/regmap/regmap-i2c.c

305
306 /*
307 * SMBus byte/word reg16 support for adapters that have SMBUS_BYTE_DATA
308 * and SMBUS_WORD_DATA but lack I2C_FUNC_I2C and I2C_FUNC_SMBUS_I2C_BLOCK,
309 * such as the AMD PIIX4.
310 *

   311	 * READ:  set 16-bit EEPROM address via write_byte_data(addr_lo, addr_hi),
   312	 *        then sequentially read bytes via read_byte() (EEPROM auto-
   313	 *        increments the address pointer).  Same as the I2C-block reg16
   314	 *        read path above.
   315	 *
   316	 * WRITE: encode the low address byte and data into a word transaction:
   317	 *        write_word_data(addr_hi, (data_byte << 8) | addr_lo).
   318	 *        Only single-byte writes are supported (one value per transaction).
   319	 */
   320	static int regmap_smbus_word_write_reg16(void *context, const void *data,
   321						 size_t count)
   322	{
   323		struct device *dev = context;
   324		struct i2c_client *i2c = to_i2c_client(dev);
   325		u8 addr_hi, addr_lo, val;
   326	
   327		/*
   328		 * data layout: [addr_hi, addr_lo, val0, val1, ...].
   329		 * Only single-byte value writes are supported; multi-byte would
   330		 * require raw I2C (or repeated word writes with incrementing address).
   331		 */
   332		if (count != 3)
   333			return -EINVAL;
   334	
   335		addr_hi = ((u8 *)data)[0];
   336		addr_lo = ((u8 *)data)[1];
   337		val = ((u8 *)data)[2];
   338	
   339		return i2c_smbus_write_word_data(i2c, addr_hi,
 > 340						 cpu_to_le16(((u16)val << 8) | addr_lo));

341 }
342

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

#1 lore raw

PATCH 1/1 regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

From 12085a8445d18202a59e3558118f74db32673b17 Mon Sep 17 00:00:00 2001
From: Nishanth Sampath Kumar <[email protected]>
Date: Tue, 19 May 2026 09:41:53 -0700
Subject: [PATCH] regmap-i2c: fix sparse warning in
regmap_smbus_word_write_reg16

i2c_smbus_write_word_data() expects a plain u16, but cpu_to_le16() returns __le16 (a sparse-restricted endian type), causing:

drivers/base/regmap/regmap-i2c.c:340: sparse: incorrect type in argument 3 (different base types)
expected unsigned short [usertype] value
got restricted __le16 [usertype]

SMBus already defines byte ordering internally, so cpu_to_le16() is wrong here. Replace it with a plain (u16) cast.

Fixes bad4bd28abf4 ("regmap-i2c: add SMBus byte/word reg16 bus for adapters lacking I2C_FUNC_I2C")
---
 drivers/base/regmap/regmap-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regmap-i2c.c +1 -1
index 31e30dfced19..9102d8b20896 100644
@@ -337,7 +337,7 @@ static int regmap_smbus_word_write_reg16(void *context, const void *data,
 	val = ((u8 *)data)[2];
 
 	return i2c_smbus_write_word_data(i2c, addr_hi,
-					 cpu_to_le16(((u16)val << 8) | addr_lo));
+					(u16)(((u16)val << 8) | addr_lo));
 }
 
 static const struct regmap_bus regmap_smbus_byte_word_reg16 = {
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

Quoted 5 lines · Nishanth Sampath Kumar

From 12085a8445d18202a59e3558118f74db32673b17 Mon Sep 17 00:00:00 2001
From: Nishanth Sampath Kumar <[email protected]>
Date: Tue, 19 May 2026 09:41:53 -0700
Subject: [PATCH] regmap-i2c: fix sparse warning in
regmap_smbus_word_write_reg16

Please post the patch as covered in submitting-patches.rst, not as an attachment. If you're having trouble with your mail server b4 send is helpful:

https://b4.docs.kernel.org/en/latest/contributor/overview.html

drivers/base/regmap/regmap-i2c.c static int regmap_smbus_word_write_reg16(void *context, const void *data, · line 340

Quoted 3 lines
drivers/base/regmap/regmap-i2c.c +1 -1
 	return i2c_smbus_write_word_data(i2c, addr_hi,
-					 cpu_to_le16(((u16)val << 8) | addr_lo));
+					(u16)(((u16)val << 8) | addr_lo));

What is the top level (u16) cast doing here? This is not a legibility triumph...

#3 lore raw

PATCH 1/1 regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

In reply to kernel test robot

i2c_smbus_write_word_data() expects a plain u16, but cpu_to_le16() returns __le16 (a sparse-restricted endian type), causing:

drivers/base/regmap/regmap-i2c.c:340: sparse: incorrect type in argument 3 (different base types)
expected unsigned short [usertype] value
got restricted __le16 [usertype]

SMBus already defines byte ordering internally, so cpu_to_le16() is wrong here. Replace it with a plain (u16) cast.

Fixes bad4bd28abf4 ("regmap-i2c: add SMBus byte/word reg16 bus for adapters lacking I2C_FUNC_I2C")
---
 drivers/base/regmap/regmap-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regmap-i2c.c +1 -1
index 31e30dfced19..ae441fc63127 100644
@@ -337,7 +337,7 @@ static int regmap_smbus_word_write_reg16(void *context, const void *data,
 	val = ((u8 *)data)[2];
 
 	return i2c_smbus_write_word_data(i2c, addr_hi,
-					 cpu_to_le16(((u16)val << 8) | addr_lo));
+					 ((u16)val << 8) | addr_lo));
 }
 
 static const struct regmap_bus regmap_smbus_byte_word_reg16 = {
Signature · 1 line
2.25.1
author build bot
#4 lore raw

Re: [PATCH] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

kernel test robot noticed the following build errors:

Hi Nishanth,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-regmap/for-next]
[also build test ERROR on linus/master v7.1-rc4 next-20260519] [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/Nishanth-Sampath-Kumar/regmap-i2c-fix-sparse-warning-in-regmap_smbus_word_write_reg16/20260520-011137
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
patch link:    https://lore.kernel.org/r/20260519170836.1344260-1-nissampa%40cisco.com
patch subject: [PATCH] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16
config: arm64-randconfig-004-20260520 (https://download.01.org/0day-ci/archive/20260520/[email protected]/config)
compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260520/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/base/regmap/regmap-i2c.c:340:33: error: expected ';' after return statement
                                            ((u16)val << 8) | addr_lo));
                                                                      ^
                                                                      ;

1 error generated.

vim +340 drivers/base/regmap/regmap-i2c.c

305
306 /*
307 * SMBus byte/word reg16 support for adapters that have SMBUS_BYTE_DATA
308 * and SMBUS_WORD_DATA but lack I2C_FUNC_I2C and I2C_FUNC_SMBUS_I2C_BLOCK,
309 * such as the AMD PIIX4.
310 *

   311	 * READ:  set 16-bit EEPROM address via write_byte_data(addr_lo, addr_hi),
   312	 *        then sequentially read bytes via read_byte() (EEPROM auto-
   313	 *        increments the address pointer).  Same as the I2C-block reg16
   314	 *        read path above.
   315	 *
   316	 * WRITE: encode the low address byte and data into a word transaction:
   317	 *        write_word_data(addr_hi, (data_byte << 8) | addr_lo).
   318	 *        Only single-byte writes are supported (one value per transaction).
   319	 */
   320	static int regmap_smbus_word_write_reg16(void *context, const void *data,
   321						 size_t count)
   322	{
   323		struct device *dev = context;
   324		struct i2c_client *i2c = to_i2c_client(dev);
   325		u8 addr_hi, addr_lo, val;
   326	
   327		/*
   328		 * data layout: [addr_hi, addr_lo, val0, val1, ...].
   329		 * Only single-byte value writes are supported; multi-byte would
   330		 * require raw I2C (or repeated word writes with incrementing address).
   331		 */
   332		if (count != 3)
   333			return -EINVAL;
   334	
   335		addr_hi = ((u8 *)data)[0];
   336		addr_lo = ((u8 *)data)[1];
   337		val = ((u8 *)data)[2];
   338	
   339		return i2c_smbus_write_word_data(i2c, addr_hi,
 > 340						 ((u16)val << 8) | addr_lo));

341 }
342

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

author build bot
#5 lore raw

Re: [PATCH] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

In reply to Nishanth Sampath Kumar
kernel test robot noticed the following build errors:

Hi Nishanth,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-regmap/for-next]
[also build test ERROR on linus/master v7.1-rc4 next-20260519] [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/Nishanth-Sampath-Kumar/regmap-i2c-fix-sparse-warning-in-regmap_smbus_word_write_reg16/20260520-011137
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
patch link:    https://lore.kernel.org/r/20260519170836.1344260-1-nissampa%40cisco.com
patch subject: [PATCH] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16
config: s390-randconfig-r071-20260520 (https://download.01.org/0day-ci/archive/20260520/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
smatch: v0.5.0-9185-gbcc58b9c
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260520/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/base/regmap/regmap-i2c.c: In function 'regmap_smbus_word_write_reg16':

>> drivers/base/regmap/regmap-i2c.c:340:33: error: expected ';' before ')' token
          ((u16)val << 8) | addr_lo));
                                    ^
                                    ;
>> drivers/base/regmap/regmap-i2c.c:340:33: error: expected statement before ')' token

vim +340 drivers/base/regmap/regmap-i2c.c

305
306 /*
307 * SMBus byte/word reg16 support for adapters that have SMBUS_BYTE_DATA
308 * and SMBUS_WORD_DATA but lack I2C_FUNC_I2C and I2C_FUNC_SMBUS_I2C_BLOCK,
309 * such as the AMD PIIX4.
310 *

   311	 * READ:  set 16-bit EEPROM address via write_byte_data(addr_lo, addr_hi),
   312	 *        then sequentially read bytes via read_byte() (EEPROM auto-
   313	 *        increments the address pointer).  Same as the I2C-block reg16
   314	 *        read path above.
   315	 *
   316	 * WRITE: encode the low address byte and data into a word transaction:
   317	 *        write_word_data(addr_hi, (data_byte << 8) | addr_lo).
   318	 *        Only single-byte writes are supported (one value per transaction).
   319	 */
   320	static int regmap_smbus_word_write_reg16(void *context, const void *data,
   321						 size_t count)
   322	{
   323		struct device *dev = context;
   324		struct i2c_client *i2c = to_i2c_client(dev);
   325		u8 addr_hi, addr_lo, val;
   326	
   327		/*
   328		 * data layout: [addr_hi, addr_lo, val0, val1, ...].
   329		 * Only single-byte value writes are supported; multi-byte would
   330		 * require raw I2C (or repeated word writes with incrementing address).
   331		 */
   332		if (count != 3)
   333			return -EINVAL;
   334	
   335		addr_hi = ((u8 *)data)[0];
   336		addr_lo = ((u8 *)data)[1];
   337		val = ((u8 *)data)[2];
   338	
   339		return i2c_smbus_write_word_data(i2c, addr_hi,
 > 340						 ((u16)val << 8) | addr_lo));

341 }
342

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

#6 lore raw

PATCH v2 1/1 regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

In reply to kernel test robot

i2c_smbus_write_word_data() expects a plain u16, but cpu_to_le16() returns __le16 (a sparse-restricted endian type), causing:

drivers/base/regmap/regmap-i2c.c:340: sparse: incorrect type in argument 3 (different base types)
expected unsigned short [usertype] value
got restricted __le16 [usertype]

SMBus already defines byte ordering internally, so cpu_to_le16() is wrong here. Replace it with a plain (u16) cast.

Fixes bad4bd28abf4 ("regmap-i2c: add SMBus byte/word reg16 bus for adapters lacking I2C_FUNC_I2C")
---
 drivers/base/regmap/regmap-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regmap-i2c.c +1 -1
index 31e30dfced19..51a04961faf7 100644
@@ -337,7 +337,7 @@ static int regmap_smbus_word_write_reg16(void *context, const void *data,
 	val = ((u8 *)data)[2];
 
 	return i2c_smbus_write_word_data(i2c, addr_hi,
-					 cpu_to_le16(((u16)val << 8) | addr_lo));
+					 ((u16)val << 8) | addr_lo);
 }
 
 static const struct regmap_bus regmap_smbus_byte_word_reg16 = {
Signature · 1 line
2.25.1
maintainer
#7 lore raw

Re: [PATCH v2] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

Quoted 2 lines · Nishanth Sampath Kumar

i2c_smbus_write_word_data() expects a plain u16, but cpu_to_le16() returns __le16 (a sparse-restricted endian type), causing:

Please don't send new patches in reply to old patches or serieses, this makes it harder for both people and tools to understand what is going on - it can bury things in mailboxes and make it difficult to keep track of what current patches are, both for the new patches and the old ones.

maintainer
#8 lore raw

Re: [PATCH v2] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

In reply to Nishanth Sampath Kumar
Quoted 1 line · Nishanth Sampath Kumar

regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-7.2

Thanks!

[1/1] regmap-i2c: fix sparse warning in regmap_smbus_word_write_reg16

      https://git.kernel.org/broonie/regmap/c/19a5211cda12

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark