lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250820004755.69627-1-junjie.cao@intel.com>
Date: Wed, 20 Aug 2025 08:47:55 +0800
From: Junjie Cao <junjie.cao@...el.com>
To: jic23@...nel.org,
	linux-iio@...r.kernel.org
Cc: dlechner@...libre.com,
	nuno.sa@...log.com,
	andy@...nel.org,
	linux-kernel@...r.kernel.org,
	Junjie Cao <junjie.cao@...el.com>
Subject: [PATCH v2] 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.

Suggested-by: Jonathan Cameron <jic23@...nel.org>
Signed-off-by: Junjie Cao <junjie.cao@...el.com>
---
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/20250815022528.24705-1-junjie.cao@intel.com/

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(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 159d6c5ca3ce..9125d466118d 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -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;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index d11668f14a3e..39c55116939e 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -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;
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ