Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2 1/7] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode()
       [not found] <20261123075122.373060-1-lee@kernel.org>
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 2/7] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Lee Jones
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Nuno Sá, Michael Hennerich, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Lars-Peter Clausen, linux,
	linux-iio, linux-kernel
  Cc: stable, Radu Sabau

adis_update_scan_mode() frees both adis->xfer and adis->buffer at the
start of a scan mode update without clearing either pointer to NULL.

In both adis_update_scan_mode_burst() and the non-burst path, adis->xfer
is allocated before adis->buffer.  If the adis->xfer allocation fails,
the function returns -ENOMEM while adis->buffer still holds the freed
pointer from the previous scan configuration, causing a double-free on
the next scan mode update or during device teardown in
adis_buffer_cleanup().

Clear both pointers immediately after freeing them.

Fixes: aacff892cbd5 ("staging:iio:adis: Preallocate transfer message")
Closes: https://sashiko.dev/#/bug/linux-966f0cd4-488a-4d69-b8a5-449c751365d2
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Radu Sabau <radu.sabau@analog.com>

v1 => v2:
 - CC Radu Sabau (Jonathan)

 drivers/iio/imu/adis_buffer.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c
index 501da4eaef69..9d317b627eba 100644
--- a/drivers/iio/imu/adis_buffer.c
+++ b/drivers/iio/imu/adis_buffer.c
@@ -74,7 +74,9 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
 	__be16 *tx, *rx;
 
 	kfree(adis->xfer);
+	adis->xfer = NULL;
 	kfree(adis->buffer);
+	adis->buffer = NULL;
 
 	if (adis->data->burst_len)
 		return adis_update_scan_mode_burst(indio_dev, scan_mask);
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/7] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()
       [not found] <20261123075122.373060-1-lee@kernel.org>
  2026-11-23  7:50 ` [PATCH v2 1/7] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 3/7] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() Lee Jones
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Lucas Stankus, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Lothar Rubusch,
	linux, linux-iio, linux-kernel
  Cc: stable

The ADXL313 32-entry FIFO plus one sample held in the output filter can
yield up to 33 3-axis samples (ADXL313_FIFO_SIZE + 1).  Because of
missing parentheses in ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1,
fifo_buf is sized at 97 16-bit elements instead of 99, overflowing the
buffer by four bytes whenever all 33 entries are read.

In addition, adxl313_get_samples() returns the 6-bit FIFO_STATUS entries
field (0..63) without bounds checking, allowing a malfunctioning or
spoofed bus device to overflow fifo_buf on the heap in
adxl313_fifo_transfer().

Parenthesise (ADXL313_FIFO_SIZE + 1) when sizing fifo_buf and reject
entry counts exceeding ADXL313_FIFO_SIZE + 1 with -EIO in
adxl313_get_samples().

Fixes: ff8093fa6ba4 ("iio: accel: adxl313: add buffered FIFO watermark with interrupt handling")
Closes: https://sashiko.dev/#/bug/linux-6baeb7fe-ad68-4961-b5f9-5f0c7628df1e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Return -EIO instead of -EINVAL when FIFO entries exceed
   ADXL313_FIFO_SIZE + 1 (Andy, Jonathan)

 drivers/iio/accel/adxl313.h      | 2 +-
 drivers/iio/accel/adxl313_core.c | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/adxl313.h b/drivers/iio/accel/adxl313.h
index 75ef54b60f75..de0bccfcdd0a 100644
--- a/drivers/iio/accel/adxl313.h
+++ b/drivers/iio/accel/adxl313.h
@@ -93,7 +93,7 @@ struct adxl313_data {
 	struct mutex	lock; /* lock to protect transf_buf */
 	u8 watermark;
 	__le16		transf_buf __aligned(IIO_DMA_MINALIGN);
-	__le16		fifo_buf[ADXL313_NUM_AXIS * ADXL313_FIFO_SIZE + 1];
+	__le16		fifo_buf[ADXL313_NUM_AXIS * (ADXL313_FIFO_SIZE + 1)];
 };
 
 struct adxl313_chip_info {
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 6dc918c4ae17..dd0b3efd594e 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -921,7 +921,12 @@ static int adxl313_get_samples(struct adxl313_data *data)
 	if (ret)
 		return ret;
 
-	return FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval);
+	/* 32 FIFO entries plus 1 entry at the output filter */
+	ret = FIELD_GET(ADXL313_REG_FIFO_STATUS_ENTRIES_MSK, regval);
+	if (ret > ADXL313_FIFO_SIZE + 1)
+		return -EIO;
+
+	return ret;
 }
 
 static int adxl313_fifo_transfer(struct adxl313_data *data, int samples)
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/7] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
       [not found] <20261123075122.373060-1-lee@kernel.org>
  2026-11-23  7:50 ` [PATCH v2 1/7] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
  2026-11-23  7:50 ` [PATCH v2 2/7] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 4/7] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Lee Jones
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Lucas Stankus, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko,
	Alexandru Ardelean, linux, linux-iio, linux-kernel
  Cc: stable

When reading IIO_CHAN_INFO_SAMP_FREQ, adxl313_read_raw() extracts the
4-bit rate field (0..15) from ADXL313_REG_BW_RATE and subtracts
ADXL313_RATE_BASE (6) to index adxl313_odr_freqs[].

ADXL312 and ADXL314 support sub-6.25 Hz rate codes 0..5 and do not
perform a soft reset during setup, and debugfs register writes or a
faulty bus read can likewise yield codes below ADXL313_RATE_BASE.  When
that happens, subtracting ADXL313_RATE_BASE produces a negative index
and reads before the start of adxl313_odr_freqs[].

Return -ERANGE if the rate field is below ADXL313_RATE_BASE.

Fixes: 636d44633039 ("iio: accel: Add driver support for ADXL313")
Closes: https://sashiko.dev/#/bug/linux-d6086ee0-d732-43b6-b8ac-24e5bf86a9f8
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Return -ERANGE instead of -EINVAL for sub-base ODR codes (Andy)

 drivers/iio/accel/adxl313_core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index dd0b3efd594e..aaab1935ac60 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -647,7 +647,11 @@ static int adxl313_read_raw(struct iio_dev *indio_dev,
 		if (ret)
 			return ret;
 
-		ret = FIELD_GET(ADXL313_RATE_MSK, regval) - ADXL313_RATE_BASE;
+		regval = FIELD_GET(ADXL313_RATE_MSK, regval);
+		if (regval < ADXL313_RATE_BASE)
+			return -ERANGE;
+
+		ret = regval - ADXL313_RATE_BASE;
 		*val = adxl313_odr_freqs[ret][0];
 		*val2 = adxl313_odr_freqs[ret][1];
 		return IIO_VAL_INT_PLUS_MICRO;
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/7] iio: adc: pac1934: Fix custom attribute allocation and channel bounds
       [not found] <20261123075122.373060-1-lee@kernel.org>
                   ` (2 preceding siblings ...)
  2026-11-23  7:50 ` [PATCH v2 3/7] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Marius Cristea, Jonathan Cameron, David Lechner,
	Nuno Sá, Andy Shevchenko, Bogdan Bolocan, linux-iio,
	linux-kernel
  Cc: stable

pac1934_prep_custom_attributes() sizes the pac1934_custom_attr pointer
array using sizeof(*pac1934_group) instead of
sizeof(*pac1934_custom_attr) and adds 1 byte rather than one pointer
element for the terminating NULL entry.  When active_channels_count is
zero, only a single byte is allocated and iio_device_register_sysfs()
reads past the allocation when scanning the attribute list.

In addition, active_channels_count is counted over info->phys_channels,
whereas the population steps unconditionally inspect all four entries of
info->active_channels[], which can write past the end of the array on
1-, 2-, and 3-channel chip variants.

Allocate active_channels_count + 1 attribute pointers with
devm_kzalloc_objs() and bound the population loop by
info->phys_channels.

Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
Closes: https://sashiko.dev/#/bug/linux-e7b7eab1-9ed4-4d4b-b9c7-889bf720aa5b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Order local variables in reverse Christmas tree style (Andy,
   Jonathan)
 - Scope loop index j to the for-loop (Andy, Jonathan)

 drivers/iio/adc/pac1934.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index 5e901ab25c8e..a307689c6814 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -1435,13 +1435,20 @@ static IIO_DEVICE_ATTR(in_shunt_resistor3, 0644,
 static IIO_DEVICE_ATTR(in_shunt_resistor4, 0644,
 		       pac1934_shunt_value_show, pac1934_shunt_value_store, 3);
 
+static struct attribute * const pac1934_shunt_attrs[] = {
+	PAC1934_DEV_ATTR(in_shunt_resistor1),
+	PAC1934_DEV_ATTR(in_shunt_resistor2),
+	PAC1934_DEV_ATTR(in_shunt_resistor3),
+	PAC1934_DEV_ATTR(in_shunt_resistor4),
+};
+
 static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info,
 					  struct iio_dev *indio_dev)
 {
-	int i, active_channels_count = 0;
+	struct device *dev = &info->client->dev;
 	struct attribute **pac1934_custom_attr;
 	struct attribute_group *pac1934_group;
-	struct device *dev = &info->client->dev;
+	int i, active_channels_count = 0;
 
 	for (i = 0 ; i < info->phys_channels; i++)
 		if (info->active_channels[i])
@@ -1451,26 +1458,16 @@ static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info,
 	if (!pac1934_group)
 		return -ENOMEM;
 
-	pac1934_custom_attr = devm_kzalloc(dev,
-					   (PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
-					   active_channels_count)
-					   * sizeof(*pac1934_group) + 1,
-					   GFP_KERNEL);
+	pac1934_custom_attr = devm_kzalloc_objs(dev, *pac1934_custom_attr,
+						PAC1934_CUSTOM_ATTR_FOR_CHANNEL *
+						active_channels_count + 1);
 	if (!pac1934_custom_attr)
 		return -ENOMEM;
 
 	i = 0;
-	if (info->active_channels[0])
-		pac1934_custom_attr[i++] = PAC1934_DEV_ATTR(in_shunt_resistor1);
-
-	if (info->active_channels[1])
-		pac1934_custom_attr[i++] = PAC1934_DEV_ATTR(in_shunt_resistor2);
-
-	if (info->active_channels[2])
-		pac1934_custom_attr[i++] = PAC1934_DEV_ATTR(in_shunt_resistor3);
-
-	if (info->active_channels[3])
-		pac1934_custom_attr[i] = PAC1934_DEV_ATTR(in_shunt_resistor4);
+	for (int j = 0; j < info->phys_channels; j++)
+		if (info->active_channels[j])
+			pac1934_custom_attr[i++] = pac1934_shunt_attrs[j];
 
 	pac1934_group->attrs = pac1934_custom_attr;
 	info->iio_info.attrs = pac1934_group;
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
       [not found] <20261123075122.373060-1-lee@kernel.org>
                   ` (3 preceding siblings ...)
  2026-11-23  7:50 ` [PATCH v2 4/7] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
  2026-11-23  7:50 ` [PATCH v2 7/7] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Lee Jones
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio,
	linux-kernel
  Cc: stable

struct tm5_aux_dev_wrapper embeds a reference-counted struct
auxiliary_device, whose memory must be released from its dev.release
callback once the final device reference is dropped.

Allocating the wrapper and its tm_props array with parent-managed
devm_*() helpers and providing an empty adc5_gen3_aux_device_release()
causes parent devres teardown to free both allocations immediately when
the parent unbinds, even if external references to the embedded struct
device are still held.  It also leaks the OF node reference taken by
device_set_of_node_from_dev().

Allocate the wrapper and tm_props array without devm, release them
together with the OF node reference in adc5_gen3_aux_device_release(),
and register auxiliary_device_destroy() via devm_add_action_or_reset()
once the auxiliary device has been added.

Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")
Closes: https://sashiko.dev/#/bug/linux-b738d116-f32b-4edf-aa73-77827b79a407
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Allocate tm_props without devm and release it alongside the OF node
   reference in adc5_gen3_aux_device_release() (Jonathan)
 - Move auxiliary_device_init() earlier and register
   auxiliary_device_destroy() via devm_add_action_or_reset(), avoiding
   devm_release_action() (Andy, Jonathan)
 - Note: <linux/container_of.h> is already included

 drivers/iio/adc/qcom-spmi-adc5-gen3.c | 57 +++++++++++++--------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index a23eb5c9096d..85450aa37e65 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -21,9 +21,11 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/unaligned.h>
 
@@ -598,24 +600,22 @@ static int adc5_get_fw_data(struct adc5_chip *adc)
 	return 0;
 }
 
-static void adc5_gen3_uninit_aux(void *data)
+static void adc5_gen3_aux_device_release(struct device *dev)
 {
-	auxiliary_device_uninit(data);
-}
+	struct tm5_aux_dev_wrapper *aux_device =
+		container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev);
 
-static void adc5_gen3_delete_aux(void *data)
-{
-	auxiliary_device_delete(data);
+	of_node_put(dev->of_node);
+	kfree(aux_device->tm_props);
+	kfree(aux_device);
 }
 
-static void adc5_gen3_aux_device_release(struct device *dev) {}
-
 static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
 {
 	struct tm5_aux_dev_wrapper *aux_device;
 	int i, ret, i_tm = 0;
 
-	aux_device = devm_kzalloc(adc->dev, sizeof(*aux_device), GFP_KERNEL);
+	aux_device = kzalloc_obj(*aux_device);
 	if (!aux_device)
 		return -ENOMEM;
 
@@ -624,11 +624,20 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
 	aux_device->aux_dev.dev.parent = adc->dev;
 	aux_device->aux_dev.dev.release = adc5_gen3_aux_device_release;
 
-	aux_device->tm_props = devm_kcalloc(adc->dev, adc->n_tm_channels,
-					    sizeof(*aux_device->tm_props),
-					    GFP_KERNEL);
-	if (!aux_device->tm_props)
+	ret = auxiliary_device_init(&aux_device->aux_dev);
+	if (ret) {
+		kfree(aux_device);
+		return ret;
+	}
+
+	device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev);
+
+	aux_device->tm_props = kzalloc_objs(*aux_device->tm_props,
+					    adc->n_tm_channels);
+	if (!aux_device->tm_props) {
+		auxiliary_device_uninit(&aux_device->aux_dev);
 		return -ENOMEM;
+	}
 
 	aux_device->dev_data = &adc->dev_data;
 
@@ -639,28 +648,16 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)
 		i_tm++;
 	}
 
-	device_set_of_node_from_dev(&aux_device->aux_dev.dev, adc->dev);
-
 	aux_device->n_tm_channels = adc->n_tm_channels;
 
-	ret = auxiliary_device_init(&aux_device->aux_dev);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(adc->dev, adc5_gen3_uninit_aux,
-				       &aux_device->aux_dev);
-	if (ret)
-		return ret;
-
 	ret = auxiliary_device_add(&aux_device->aux_dev);
-	if (ret)
-		return ret;
-	ret = devm_add_action_or_reset(adc->dev, adc5_gen3_delete_aux,
-				       &aux_device->aux_dev);
-	if (ret)
+	if (ret) {
+		auxiliary_device_uninit(&aux_device->aux_dev);
 		return ret;
+	}
 
-	return 0;
+	return devm_add_action_or_reset(adc->dev, auxiliary_device_destroy,
+					&aux_device->aux_dev);
 }
 
 void adc5_gen3_mutex_lock(struct device *dev)
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
       [not found] <20261123075122.373060-1-lee@kernel.org>
                   ` (4 preceding siblings ...)
  2026-11-23  7:50 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  2026-11-23  7:50 ` [PATCH v2 7/7] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Lee Jones
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jishnu Prakash, linux-arm-msm, linux-iio,
	linux-kernel
  Cc: stable

If a firmware node supplies an empty reg property,
device_property_count_u32() returns 0, which passes the negative error
check in adc5_gen3_probe() and leaves num_sdams set to 0.  Subsequent
zero-length allocations return ZERO_SIZE_PTR, which is then dereferenced
when requesting the VADC SDAM interrupt, and num_sdams * 8 - 1 wraps in
unsigned comparisons when counting TM channels.

Return -ENOENT when device_property_count_u32() reports zero elements.

Fixes: baff45179e90 ("iio: adc: Add support for QCOM PMIC5 Gen3 ADC")
Closes: https://sashiko.dev/#/bug/linux-d8ad5868-82f5-4c97-bc67-84ceebb10a1a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Return -ENOENT instead of -EINVAL when reg is empty (Andy)

 drivers/iio/adc/qcom-spmi-adc5-gen3.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index 85450aa37e65..8e316aa88f48 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -736,6 +736,8 @@ static int adc5_gen3_probe(struct platform_device *pdev)
 	ret = device_property_count_u32(dev, "reg");
 	if (ret < 0)
 		return ret;
+	if (!ret)
+		return -ENOENT;
 
 	adc->dev_data.num_sdams = ret;
 
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 7/7] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq()
       [not found] <20261123075122.373060-1-lee@kernel.org>
                   ` (5 preceding siblings ...)
  2026-11-23  7:50 ` [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
@ 2026-11-23  7:50 ` Lee Jones
  6 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-23  7:50 UTC (permalink / raw)
  To: lee, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Mathieu Othacehe, linux-iio, linux-kernel
  Cc: stable

isl29501_set_freq() computes freq = val * 1000000 + val2 % 1000000 in a
signed 32-bit int and passes it directly to do_div() without checking
for zero or negative inputs.  Writing 0 to the sampling_frequency
attribute triggers a division by zero in the kernel, while valid
frequencies above 2147 Hz up to the sensor's 2222 Hz limit overflow
signed int.

Validate that val and val2 are non-negative, compute freq using
HZ_PER_MHZ as an unsigned int within [1, 2222 * HZ_PER_MHZ], and return
-ERANGE otherwise.

Fixes: 1c28799257bc ("iio: light: isl29501: Add support for the ISL29501 ToF sensor.")
Closes: https://sashiko.dev/#/bug/linux-e4bc1c30-bbf1-458a-99f9-a36e949af67c
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Order local variables in reverse Christmas tree style (Andy)
 - Group range checks by variable (Andy)
 - Use HZ_PER_MHZ from <linux/units.h> (Andy)

 drivers/iio/proximity/isl29501.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/proximity/isl29501.c b/drivers/iio/proximity/isl29501.c
index a98a9975323c..43be78b82e50 100644
--- a/drivers/iio/proximity/isl29501.c
+++ b/drivers/iio/proximity/isl29501.c
@@ -18,6 +18,7 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/buffer.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/units.h>
 
 /* Control, setting and status registers */
 #define ISL29501_DEVICE_ID			0x00
@@ -863,12 +864,18 @@ static int isl29501_set_calibbias(struct isl29501_private *isl29501,
 static int isl29501_set_freq(struct isl29501_private *isl29501,
 			     int val, int val2)
 {
-	int freq;
 	unsigned long long sample_time;
+	unsigned int freq;
+
+	if (val < 0 || val > 2222 || val2 < 0)
+		return -ERANGE;
 
 	/* sample_freq = 1 / (0.000450 * (sample_time + 1) * 10^-6) */
-	freq = val * 1000000 + val2 % 1000000;
-	sample_time = 2222ULL * 1000000ULL;
+	freq = val * HZ_PER_MHZ + val2 % HZ_PER_MHZ;
+	if (!freq || freq > 2222U * HZ_PER_MHZ)
+		return -ERANGE;
+
+	sample_time = 2222ULL * HZ_PER_MHZ;
 	do_div(sample_time, freq);
 
 	sample_time -= 1;
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-23  7:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261123075122.373060-1-lee@kernel.org>
2026-11-23  7:50 ` [PATCH v2 1/7] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode() Lee Jones
2026-11-23  7:50 ` [PATCH v2 2/7] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer() Lee Jones
2026-11-23  7:50 ` [PATCH v2 3/7] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw() Lee Jones
2026-11-23  7:50 ` [PATCH v2 4/7] iio: adc: pac1934: Fix custom attribute allocation and channel bounds Lee Jones
2026-11-23  7:50 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback Lee Jones
2026-11-23  7:50 ` [PATCH v2 6/7] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe Lee Jones
2026-11-23  7:50 ` [PATCH v2 7/7] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq() Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox