Skip to contentSkip to conversation

iio: core: switch info_mask fields to unsigned long to match find_bit helpers

PATCH Applied Junjie Cao 3 participants 3 messages Aug 20, 2025 – Aug 25, 2025 IIO

lore
Share & tools
lore

Junjie Cao

author
#0 lore raw

PATCH v2 1/1 iio: core: switch info_mask fields to unsigned long to match find_bit helpers

for_each_set_bit()/find_*_bit() expect arrays of unsigned long (see include/linux/find.h), but industrialio-core passed const long * into iio_device_add_info_mask_type{,_avail}().

These masks are used purely as bit arrays and are populated via BIT() (1UL << n). Switch the info_mask_* fields and the corresponding function parameters to unsigned long so the types match the helpers. This removes sparse warnings about signedness mismatches (seen with 'make C=1' CF='-Wsparse-all') without changing behavior or struct layout.

No functional change intended.

---
Hi Jonathan,

Thanks so much for the feedback and the clear fix suggestion.

Changes in v2:
- Implemented Jonathan's suggestion to change info_mask_* fields to unsigned long
- Updated commit message based on feedback

v1: https://lore.kernel.org/linux-iio/[email protected]/

Regarding how I triggered the warning, I can reproduce it with:
make M=drivers/iio clean
make C=1 drivers/iio/industrialio-core.o CF='-Wsparse-all' 2>&1 | grep signedness

Environment details:
- Tree: linux-next (tag next-20250808)
- GCC: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
- Sparse: v0.5.0-8881-g2fb2b909

I completely agree that your approach is much better. The masks are indeed used purely as bit arrays, so making them unsigned long must be the right solution.

To double-check beyond industrialio-core, I (1) ran a subsystem-wide sparse pass and a clean build of drivers/iio, (2) audited usages of info_mask_*, and (3) reviewed other for_each_set_bit() sites. With the type change applied, there were no remaining signedness diagnostics, no new build warnings, and no sites relying on these fields being signed.

Here is the v2 patch implementing your suggestion. No functional change intended; the patch has been build- and sparse-tested.

Thanks,
Junjie

 drivers/iio/industrialio-core.c |  4 ++--
 include/linux/iio/iio.h         | 16 ++++++++--------
 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/iio/industrialio-core.c +2 -2
index 159d6c5ca3ce..9125d466118d 100644
@@ -1243,7 +1243,7 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev,
 static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
 					 struct iio_chan_spec const *chan,
 					 enum iio_shared_by shared_by,
-					 const long *infomask)
+					 const unsigned long *infomask)
 {
 	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	int i, ret, attrcount = 0;
@@ -1273,7 +1273,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
 static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
 					       struct iio_chan_spec const *chan,
 					       enum iio_shared_by shared_by,
-					       const long *infomask)
+					       const unsigned long *infomask)
 {
 	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	int i, ret, attrcount = 0;
include/linux/iio/iio.h +8 -8
index d11668f14a3e..39c55116939e 100644
@@ -271,14 +271,14 @@ struct iio_chan_spec {
 			unsigned int num_ext_scan_type;
 		};
 	};
-	long			info_mask_separate;
-	long			info_mask_separate_available;
-	long			info_mask_shared_by_type;
-	long			info_mask_shared_by_type_available;
-	long			info_mask_shared_by_dir;
-	long			info_mask_shared_by_dir_available;
-	long			info_mask_shared_by_all;
-	long			info_mask_shared_by_all_available;
+	unsigned long			info_mask_separate;
+	unsigned long			info_mask_separate_available;
+	unsigned long			info_mask_shared_by_type;
+	unsigned long			info_mask_shared_by_type_available;
+	unsigned long			info_mask_shared_by_dir;
+	unsigned long			info_mask_shared_by_dir_available;
+	unsigned long			info_mask_shared_by_all;
+	unsigned long			info_mask_shared_by_all_available;
 	const struct iio_event_spec *event_spec;
 	unsigned int		num_event_specs;
 	const struct iio_chan_spec_ext_info *ext_info;
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Junjie Cao

for_each_set_bit()/find_*_bit() expect arrays of unsigned long (see include/linux/find.h), but industrialio-core passed const long * into iio_device_add_info_mask_type{,_avail}().

Quoted 7 lines

These masks are used purely as bit arrays and are populated via BIT() (1UL << n). Switch the info_mask_* fields and the corresponding function parameters to unsigned long so the types match the helpers. This removes sparse warnings about signedness mismatches (seen with 'make C=1' CF='-Wsparse-all') without changing behavior or struct layout.

No functional change intended.

Thanks, this is better than v1.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#2 lore raw
Quoted 12 lines · On Wed, 20 Aug 2025 12:52:18 +0300 Andy Shevchenko <[email protected]>…
Quoted 11 lines · Junjie Cao

for_each_set_bit()/find_*_bit() expect arrays of unsigned long (see include/linux/find.h), but industrialio-core passed const long * into iio_device_add_info_mask_type{,_avail}().

These masks are used purely as bit arrays and are populated via BIT() (1UL << n). Switch the info_mask_* fields and the corresponding function parameters to unsigned long so the types match the helpers. This removes sparse warnings about signedness mismatches (seen with 'make C=1' CF='-Wsparse-all') without changing behavior or struct layout.

Quoted 5 lines
Quoted 1 line

No functional change intended.

Thanks, this is better than v1.

Applied.

Thanks,

Jonathan