iio: Fix memory corruption, teardown races and bounds checks
Subsystems (8)
cover iio: Fix memory corruption, teardown races and bounds checks
These issues were reported by Sashiko.
Lee Jones (10):
iio: imu: adis: Clear pointers after freeing in
adis_update_scan_mode()
iio: accel: adxl313: Prevent FIFO buffer overflow in
adxl313_fifo_transfer()
iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
iio: adc: stm32-adc: Validate channel index before writing chan_name
iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
iio: adc: pac1934: Fix custom attribute allocation and channel bounds
iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in
release callback
iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
iio: proximity: isl29501: Fix division by zero and overflow in
isl29501_set_freq() iio: light: tsl2591: Prevent infinite recursion on threshold
boundaries
drivers/iio/accel/adxl313.h | 2 +- drivers/iio/accel/adxl313_core.c | 13 +++++++++-- drivers/iio/adc/pac1934.c | 33 ++++++++++++--------------- drivers/iio/adc/qcom-spmi-adc5-gen3.c | 32 +++++++++++++++++++++----- drivers/iio/adc/stm32-adc-core.c | 6 ++--- drivers/iio/adc/stm32-adc.c | 12 +++++----- drivers/iio/imu/adis_buffer.c | 2 ++ drivers/iio/light/tsl2591.c | 25 ++++++++++++-------- drivers/iio/proximity/isl29501.c | 10 ++++++-- 9 files changed, 87 insertions(+), 48 deletions(-)
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 1/10 iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode()
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.
--- drivers/iio/imu/adis_buffer.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/imu/adis_buffer.c +2 -0
@@ -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);
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 2/10 iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()
In reply to Lee JonesThe 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 in adxl313_get_samples().
--- drivers/iio/accel/adxl313.h | 2 +- drivers/iio/accel/adxl313_core.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/iio/accel/adxl313.h +1 -1
@@ -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 {
drivers/iio/accel/adxl313_core.c +6 -1
@@ -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 -EINVAL ; + +return ret; }static int adxl313_fifo_transfer (struct adxl313_data *data,int samples)
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 3/10 iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
In reply to Lee JonesWhen 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 -EINVAL if the rate field is below ADXL313_RATE_BASE.
--- drivers/iio/accel/adxl313_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/accel/adxl313_core.c +5 -1
@@ -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 -EINVAL ; + + ret = regval -ADXL313_RATE_BASE ; *val = adxl313_odr_freqs[ret][0 ]; *val2 = adxl313_odr_freqs[ret][1 ];return IIO_VAL_INT_PLUS_MICRO ;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 4/10 iio: adc: stm32-adc: Validate channel index before writing chan_name
In reply to Lee Jonesstm32_adc_generic_chan_init() reads the child node's reg property into a signed int and, when the optional label property is present, writes into adc->chan_name[val] and calls stm32_adc_populate_int_ch() before checking whether val exceeds adc_info->max_channels. Because val is signed, values with the top bit set also become negative and bypass the upper-bound check altogether.
Store val as a u32, matching fwnode_property_read_u32(), and move the max_channels bounds check immediately after reading reg.
--- drivers/iio/adc/stm32-adc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/adc/stm32-adc.c +6 -6
@@ -2745,9 +2745,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,const struct stm32_adc_info *adc_info = adc->cfg->adc_info;struct device *dev = &indio_dev->dev;const char *name; -int val, scan_index =0 , ret; +int scan_index =0 , ret;bool differential; -u32 vin[2 ]; +u32 val, vin[2 ];device_for_each_child_node_scoped (dev, child) { ret =fwnode_property_read_u32 (child,"reg" , &val);
@@ -2755,6 +2755,10 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,return dev_err_probe (dev, ret,"Missing channel index\n" ); +if (val >= adc_info->max_channels) +return dev_err_probe (dev, -EINVAL , +"Invalid channel %u\n" , val); + ret =fwnode_property_read_string (child,"label" , &name);/* label is optional */ if (!ret) {
@@ -2773,10 +2777,6 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,return dev_err_probe (dev, ret,"Invalid label\n" ); } -if (val >= adc_info->max_channels) -return dev_err_probe (dev, -EINVAL , -"Invalid channel %d\n" , val); - differential = false; ret =fwnode_property_read_u32_array (child,"diff-channels" , vin,2 );/* diff-channels is optional */
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 5/10 iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
In reply to Lee Jonesstm32_adc_irq_remove() disposes of the child IRQ mappings and removes priv->domain before clearing the parent chained IRQ handlers. Because the parent hardware interrupt lines remain unmasked while child devices use dummy_irq_chip, an interrupt arriving during teardown invokes stm32_adc_irq_handler() after irq_domain_remove() has freed priv->domain, and irq_set_chained_handler() also leaves handler_data dangling.
Detach the chained handlers and clear handler_data with irq_set_chained_handler_and_data() before tearing down the mappings and removing the domain.
--- drivers/iio/adc/stm32-adc-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/adc/stm32-adc-core.c +3 -3
@@ -467,12 +467,12 @@ static void stm32_adc_irq_remove(struct platform_device *pdev,int hwirq;unsigned int i; +for (i =0 ; i < priv->nb_irqs; i++) +irq_set_chained_handler_and_data (priv->irq[i],NULL ,NULL ); +for (hwirq =0 ; hwirq < priv->nb_adc_max; hwirq++)irq_dispose_mapping (irq_find_mapping (priv->domain, hwirq));irq_domain_remove (priv->domain); - -for (i =0 ; i < priv->nb_irqs; i++) -irq_set_chained_handler (priv->irq[i],NULL ); } static int stm32_adc_core_switches_supply_en(struct stm32_adc_priv *priv,
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 6/10 iio: adc: pac1934: Fix custom attribute allocation and channel bounds
In reply to Lee Jonespac1934_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.
--- drivers/iio/adc/pac1934.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
drivers/iio/adc/pac1934.c +15 -18
@@ -1435,10 +1435,17 @@ 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 ; +int i, j, active_channels_count =0 ;struct attribute **pac1934_custom_attr;struct attribute_group *pac1934_group;struct device *dev = &info->client->dev;
@@ -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); + j =0 ; +for (i =0 ; i < info->phys_channels; i++) +if (info->active_channels[i]) + pac1934_custom_attr[j++] = pac1934_shunt_attrs[i]; pac1934_group->attrs = pac1934_custom_attr; info->iio_info.attrs = pac1934_group;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 7/10 iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
In reply to Lee Jonesstruct 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 with devm_kzalloc_obj() on the parent ADC device and providing an empty adc5_gen3_aux_device_release() causes parent devres teardown to free the wrapper immediately after auxiliary_device_uninit(), even if external references to the embedded struct device are still held.
Allocate the wrapper with kzalloc_obj(), release it from adc5_gen3_aux_device_release(), and unwind cleanly on early error paths in adc5_gen3_add_aux_tm_device().
--- drivers/iio/adc/qcom-spmi-adc5-gen3.c | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/iio/adc/qcom-spmi-adc5-gen3.c +24 -6
@@ -24,6 +24,7 @@#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>
@@ -607,14 +608,20 @@ static void adc5_gen3_delete_aux(void *data)auxiliary_device_delete (data); } -static void adc5_gen3_aux_device_release (struct device *dev) {} +static void adc5_gen3_aux_device_release (struct device *dev) +{ +struct tm5_aux_dev_wrapper *aux_device = + container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev); + +kfree (aux_device); +}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_obj (adc->dev, *aux_device); + aux_device =kzalloc_obj (*aux_device);if (!aux_device)return -ENOMEM ;
@@ -626,8 +633,10 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) aux_device->tm_props =devm_kzalloc_objs (adc->dev, *aux_device->tm_props, adc->n_tm_channels); -if (!aux_device->tm_props) +if (!aux_device->tm_props) { +kfree (aux_device);return -ENOMEM ; + } aux_device->dev_data = &adc->dev_data;
@@ -643,8 +652,10 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) aux_device->n_tm_channels = adc->n_tm_channels; ret =auxiliary_device_init (&aux_device->aux_dev); -if (ret) +if (ret) { +kfree (aux_device);return ret; + } ret =devm_add_action_or_reset (adc->dev, adc5_gen3_uninit_aux, &aux_device->aux_dev);
@@ -652,12 +663,19 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id)return ret; ret =auxiliary_device_add (&aux_device->aux_dev); -if (ret) +if (ret) { +devm_release_action (adc->dev, adc5_gen3_uninit_aux, + &aux_device->aux_dev);return ret; + } + ret =devm_add_action_or_reset (adc->dev, adc5_gen3_delete_aux, &aux_device->aux_dev); -if (ret) +if (ret) { +devm_release_action (adc->dev, adc5_gen3_uninit_aux, + &aux_device->aux_dev);return ret; + }return 0 ; }
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 8/10 iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
In reply to Lee JonesIf 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 -EINVAL when device_property_count_u32() reports zero elements.
--- drivers/iio/adc/qcom-spmi-adc5-gen3.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/adc/qcom-spmi-adc5-gen3.c +2 -0
@@ -756,6 +756,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 -EINVAL ; adc->dev_data.num_sdams = ret;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 9/10 iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq()
In reply to Lee Jonesisl29501_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 as an unsigned int within [1, 2222000000], and return -ERANGE otherwise.
--- drivers/iio/proximity/isl29501.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/proximity/isl29501.c +8 -2
@@ -863,11 +863,17 @@ 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 int freq;unsigned long long sample_time; +if (val <0 || val2 <0 || val >2222 ) +return -ERANGE ; +/* sample_freq = 1 / (0.000450 * (sample_time + 1) * 10^-6) */ - freq = val *1000000 + val2 %1000000 ; + freq = val *1000000U + val2 %1000000U ; +if (!freq || freq >2222000000U ) +return -ERANGE ; + sample_time =2222ULL *1000000ULL ;do_div (sample_time, freq);
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
PATCH 10/10 iio: light: tsl2591: Prevent infinite recursion on threshold boundaries
In reply to Lee Jonestsl2591_set_als_lower_threshold() adjusts the upper threshold to als_lower_threshold + 1 whenever the new lower threshold is greater than or equal to the current upper threshold, and tsl2591_set_als_upper_threshold() symmetrically adjusts the lower threshold to als_upper_threshold - 1.
Writing 65535 (TSL2591_ALS_MAX_VALUE) to the falling threshold wraps the 16-bit addition to 0 and calls tsl2591_set_als_upper_threshold(chip, 0), which then wraps 0 - 1 back to 65535 and calls tsl2591_set_als_lower_threshold(chip, 65535) in an infinite mutual recursion until the kernel stack overflows. Writing 0 to the rising threshold triggers the same cycle whenever the lower threshold is non-zero.
Reject als_lower_threshold == TSL2591_ALS_MAX_VALUE and als_upper_threshold == 0 with -EINVAL, propagate errors from the cross-calls, and only update chip->als_settings once the I2C writes succeed.
--- drivers/iio/light/tsl2591.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/iio/light/tsl2591.c +15 -10
@@ -466,23 +466,25 @@ static int tsl2591_set_als_gain_int_time(struct tsl2591_chip *chip)static int tsl2591_set_als_lower_threshold (struct tsl2591_chip *chip,u16 als_lower_threshold) { -struct tsl2591_als_settings als_settings = chip->als_settings;struct i2c_client *client = chip->client;u16 als_upper_threshold;u8 als_lower_l;u8 als_lower_h;int ret; - chip->als_settings.als_lower_thresh = als_lower_threshold; +if (als_lower_threshold ==TSL2591_ALS_MAX_VALUE ) +return -EINVAL ;/* * Lower threshold should not be greater or equal to upper. * If this is the case, then assert upper threshold to new lower * threshold + 1 to avoid ordering issues when setting thresholds. */ -if (als_lower_threshold >= als_settings.als_upper_thresh) { +if (als_lower_threshold >= chip->als_settings.als_upper_thresh) { als_upper_threshold = als_lower_threshold +1 ; -tsl2591_set_als_upper_threshold (chip, als_upper_threshold); + ret =tsl2591_set_als_upper_threshold (chip, als_upper_threshold); +if (ret) +return ret; } als_lower_l = als_lower_threshold;
@@ -504,32 +506,33 @@ static int tsl2591_set_als_lower_threshold(struct tsl2591_chip *chip,return ret; } + chip->als_settings.als_lower_thresh = als_lower_threshold; +return 0 ; }static int tsl2591_set_als_upper_threshold (struct tsl2591_chip *chip,u16 als_upper_threshold) { -struct tsl2591_als_settings als_settings = chip->als_settings;struct i2c_client *client = chip->client;u16 als_lower_threshold;u8 als_upper_l;u8 als_upper_h;int ret; -if (als_upper_threshold >TSL2591_ALS_MAX_VALUE ) +if (!als_upper_threshold)return -EINVAL ; - chip->als_settings.als_upper_thresh = als_upper_threshold; -/* * Upper threshold should not be less than lower. If this * is the case, then assert lower threshold to new upper * threshold - 1 to avoid ordering issues when setting thresholds. */ -if (als_upper_threshold < als_settings.als_lower_thresh) { +if (als_upper_threshold < chip->als_settings.als_lower_thresh) { als_lower_threshold = als_upper_threshold -1 ; -tsl2591_set_als_lower_threshold (chip, als_lower_threshold); + ret =tsl2591_set_als_lower_threshold (chip, als_lower_threshold); +if (ret) +return ret; } als_upper_l = als_upper_threshold;
@@ -551,6 +554,8 @@ static int tsl2591_set_als_upper_threshold(struct tsl2591_chip *chip,return ret; } + chip->als_settings.als_upper_thresh = als_upper_threshold; +return 0 ; }
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
Re: [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()
In reply to Lee JonesQuoted 13 lines · Lee Jones
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 inADXL313_NUM_AXIS*ADXL313_FIFO_SIZE+ 1,fifo_bufis 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-bitFIFO_STATUSentries field (0..63) without bounds checking, allowing a malfunctioning or spoofed bus device to overflowfifo_bufon the heap inadxl313_fifo_transfer().Parenthesise (
ADXL313_FIFO_SIZE+ 1) when sizingfifo_bufand reject entry counts exceedingADXL313_FIFO_SIZE+ 1 inadxl313_get_samples().
...
drivers/iio/accel/adxl313_core.c static int adxl313_get_samples(struct adxl313_data *data) · line 927
Quoted 5 lines
drivers/iio/accel/adxl313_core.c +4
-1-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 -EINVAL ;
ERANGE? EIO? EPROTO? (I think from the listed the first suits better, but maybe in errno.h a better one is lurking.)
Quoted 1 line
drivers/iio/accel/adxl313_core.c +1
-0+return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 03/10] iio: accel: adxl313: Reject sub-base ODR codes in adxl313_read_raw()
In reply to Lee JonesQuoted 11 lines · Lee Jones
When reading
IIO_CHAN_INFO_SAMP_FREQ,adxl313_read_raw()extracts the 4-bit rate field (0..15) fromADXL313_REG_BW_RATEand subtractsADXL313_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, subtractingADXL313_RATE_BASEproduces a negative index and reads before the start of adxl313_odr_freqs[].Return
-EINVALif the rate field is belowADXL313_RATE_BASE.
...
drivers/iio/accel/adxl313_core.c static int adxl313_read_raw(struct iio_dev *indio_dev, · line 652
Quoted 4 lines
drivers/iio/accel/adxl313_core.c +3
-1- ret =FIELD_GET (ADXL313_RATE_MSK , regval) -ADXL313_RATE_BASE ; + regval =FIELD_GET (ADXL313_RATE_MSK , regval); +if (regval <ADXL313_RATE_BASE ) +return -EINVAL ;
Here seems ERANGE is good.
Quoted 1 line
drivers/iio/accel/adxl313_core.c +1
-0+ ret = regval -ADXL313_RATE_BASE ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name
In reply to Lee JonesQuoted 9 lines · Lee Jones
stm32_adc_generic_chan_init()reads the child node's reg property into a signed int and, when the optional label property is present, writes into adc->chan_name[val] and callsstm32_adc_populate_int_ch()before checking whether val exceedsadc_info->max_channels. Because val is signed, values with the top bit set also become negative and bypass the upper-bound check altogether.Store val as a u32, matching
fwnode_property_read_u32(), and move themax_channelsbounds check immediately after reading reg.
...
drivers/iio/adc/stm32-adc.c static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, · line 2759
Quoted 2 lines
drivers/iio/adc/stm32-adc.c +2
-0+if (val >= adc_info->max_channels) + return dev_err_probe(dev, -EINVAL,
-ECHRNG
However it seems in the original code like this.
Quoted 3 lines
drivers/iio/adc/stm32-adc.c +2
-0+ "Invalid channel %u\n", val); + ret =fwnode_property_read_string (child,"label" , &name);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 08/10] iio: adc: qcom-spmi-adc5-gen3: Reject empty reg property in probe
In reply to Lee JonesQuoted 8 lines · Lee Jones
If a firmware node supplies an empty reg property,
device_property_count_u32()returns 0, which passes the negative error check inadc5_gen3_probe()and leavesnum_sdamsset to 0. Subsequent zero-length allocations returnZERO_SIZE_PTR, which is then dereferenced when requesting the VADC SDAM interrupt, andnum_sdams* 8 - 1 wraps in unsigned comparisons when counting TM channels.Return
-EINVALwhendevice_property_count_u32()reports zero elements.
ENOENT is usually used for that.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 06/10] iio: adc: pac1934: Fix custom attribute allocation and channel bounds
In reply to Lee JonesQuoted 15 lines · Lee Jones
pac1934_prep_custom_attributes()sizes thepac1934_custom_attrpointer array usingsizeof(*pac1934_group)instead ofsizeof(*pac1934_custom_attr)and adds 1 byte rather than one pointer element for the terminating NULL entry. Whenactive_channels_countis zero, only a single byte is allocated andiio_device_register_sysfs()reads past the allocation when scanning the attribute list.In addition,
active_channels_countis counted overinfo->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 withdevm_kzalloc_objs()and bound the population loop byinfo->phys_channels.
...
drivers/iio/adc/pac1934.c static IIO_DEVICE_ATTR(in_shunt_resistor3, 0644, · line 1448
Quoted 2 lines
drivers/iio/adc/pac1934.c +1
-1-int i, active_channels_count =0 ; +int i, j, active_channels_count =0 ;
While at it, can we move to make it more like a reversed xmas tree order? But see below first.
...
drivers/iio/adc/pac1934.c static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info, · line 1470
Quoted 4 lines
drivers/iio/adc/pac1934.c +4
-0+ j =0 ; +for (i =0 ; i < info->phys_channels; i++) +if (info->active_channels[i]) + pac1934_custom_attr[j++] = pac1934_shunt_attrs[i];
But i is not used outside of the loop, can we rather have
i = 0; for (int j = 0; j < info->phys_channels; j++) if (info->active_channels[j]) pac1934_custom_attr[i++] = pac1934_shunt_attrs[j];
? In such a case the above hunk won't be needed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 09/10] iio: proximity: isl29501: Fix division by zero and overflow in isl29501_set_freq()
In reply to Lee JonesQuoted 9 lines · Lee Jones
isl29501_set_freq()computes freq = val * 1000000 + val2 % 1000000 in a signed 32-bit int and passes it directly todo_div()without checking for zero or negative inputs. Writing 0 to thesampling_frequencyattribute 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 as an unsigned int within [1, 2222000000], and return
-ERANGEotherwise.
...
drivers/iio/proximity/isl29501.c static int isl29501_set_calibbias(struct isl29501_private *isl29501, · line 867
Quoted 3 lines
drivers/iio/proximity/isl29501.c +1
-1-int freq; +unsigned int freq;unsigned long long sample_time;
Make it reversed xmas tree while at it?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (val < 0 || val2 < 0 || val > 2222) + return -ERANGE;
I would see it be grouped by variable
if (val < 0 || val > 2222 || val2 < 0)
drivers/iio/proximity/isl29501.c static int isl29501_set_calibbias(struct isl29501_private *isl29501, · line 873
Quoted 3 lines
drivers/iio/proximity/isl29501.c +1
-1/* sample_freq = 1 / (0.000450 * (sample_time + 1) * 10^-6) */ - freq = val *1000000 + val2 %1000000 ; + freq = val *1000000U + val2 %1000000U ;
While at it Use HZ_PER_MHZ and similar multipliers from units.h.
Quoted 2 lines
drivers/iio/proximity/isl29501.c +2
-0+if (!freq || freq >2222000000U ) +return -ERANGE ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
In reply to Lee JonesQuoted 13 lines · Lee Jones
struct
tm5_aux_dev_wrapperembeds a reference-counted structauxiliary_device, whose memory must be released from its dev.release callback once the final device reference is dropped.Allocating the wrapper with
devm_kzalloc_obj()on the parent ADC device and providing an emptyadc5_gen3_aux_device_release()causes parent devres teardown to free the wrapper immediately afterauxiliary_device_uninit(), even if external references to the embedded struct device are still held.Allocate the wrapper with
kzalloc_obj(), release it fromadc5_gen3_aux_device_release(), and unwind cleanly on early error paths inadc5_gen3_add_aux_tm_device().
...
drivers/iio/adc/qcom-spmi-adc5-gen3.c static void adc5_gen3_delete_aux(void *data) · line 614
Quoted 11 lines
#include <
linux/platform_device.h>
#include <linux/property.h>
#include <linux/regmap.h>drivers/iio/adc/qcom-spmi-adc5-gen3.c +5
-0+#include <linux/slab.h> #include <linux/types.h> #include <linux/unaligned.h> +static void adc5_gen3_aux_device_release (struct device *dev) +{ +struct tm5_aux_dev_wrapper *aux_device = + container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev);
container_of() is also in a separate header, id est container_of.h.
Quoted 2 lines
(quoted diff) +2
-0+ kfree(aux_device); +}
...
drivers/iio/adc/qcom-spmi-adc5-gen3.c static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) · line 668
Quoted 5 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c +3
-1ret =auxiliary_device_add (&aux_device->aux_dev); -if (ret) +if (ret) { +devm_release_action (adc->dev, adc5_gen3_uninit_aux, + &aux_device->aux_dev);
Oh, this is interesting... Usually the release devm_*() calls point to a misdesign somewhere. But I haven't checked the twisted flow of this code.
Quoted 11 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c +6
-1return ret; + } + ret =devm_add_action_or_reset (adc->dev, adc5_gen3_delete_aux, &aux_device->aux_dev); -if (ret) +if (ret) { +devm_release_action (adc->dev, adc5_gen3_uninit_aux, + &aux_device->aux_dev);return ret; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Fabrice Gasnier
Acked-byRe: [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
Quoted 9 lines · Lee Jones
stm32_adc_generic_chan_init()reads the child node's reg property into a signed int and, when the optional label property is present, writes into adc->chan_name[val] and callsstm32_adc_populate_int_ch()before checking whether val exceedsadc_info->max_channels. Because val is signed, values with the top bit set also become negative and bypass the upper-bound check altogether.Store val as a u32, matching
fwnode_property_read_u32(), and move themax_channelsbounds check immediately after reading reg.
Quoted 8 lines
...
drivers/iio/adc/stm32-adc.c static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, · line 2759
Quoted 2 lines
drivers/iio/adc/stm32-adc.c +2
-0+if (val >= adc_info->max_channels) + return dev_err_probe(dev, -EINVAL,
-ECHRNGHowever it seems in the original code like this.
Hi Lee, Andy
I've no strong opinion on this remark, whether to change the error code here, and if it belongs to this fix ?
In all case,
Best Regards,
Thanks,
Fabrice
Quoted 5 lines
Quoted 4 lines
drivers/iio/adc/stm32-adc.c +2
-0+ "Invalid channel %u\n", val); + ret =fwnode_property_read_string (child,"label" , &name);
Re: [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
In reply to Lee JonesQuoted 12 lines · Lee Jones
stm32_adc_irq_remove()disposes of the child IRQ mappings and removespriv->domainbefore clearing the parent chained IRQ handlers. Because the parent hardware interrupt lines remain unmasked while child devices usedummy_irq_chip, an interrupt arriving during teardown invokesstm32_adc_irq_handler()afterirq_domain_remove()has freedpriv->domain, andirq_set_chained_handler()also leaveshandler_datadangling.Detach the chained handlers and clear
handler_datawithirq_set_chained_handler_and_data()before tearing down the mappings and removing the domain.
Quoted 5 lines
Fixes 1add69880240 ("iio: adc: Add support for STM32 ADC core")Signed-off-by Lee Jones <[email protected]>---
Hi Lee,
Best Regards,
Thanks,
Fabrice
Quoted 23 lines
drivers/iio/adc/stm32-adc-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/adc/stm32-adc-core.c +3
-3@@ -467,12 +467,12 @@ static void stm32_adc_irq_remove(struct platform_device *pdev,int hwirq;unsigned int i; +for (i =0 ; i < priv->nb_irqs; i++) +irq_set_chained_handler_and_data (priv->irq[i],NULL ,NULL ); +for (hwirq =0 ; hwirq < priv->nb_adc_max; hwirq++)irq_dispose_mapping (irq_find_mapping (priv->domain, hwirq));irq_domain_remove (priv->domain); - -for (i =0 ; i < priv->nb_irqs; i++) -irq_set_chained_handler (priv->irq[i],NULL ); } static int stm32_adc_core_switches_supply_en(struct stm32_adc_priv *priv,
Jonathan Cameron
maintainerRe: [PATCH 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode()
In reply to Lee JonesQuoted 10 lines · On Thu, 19 Nov 2026 15:30:34 +0000 Lee Jones <[email protected]> wrote:
adis_update_scan_mode()frees bothadis->xferandadis->bufferat 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->xferis allocated beforeadis->buffer. If theadis->xferallocation fails, the function returns-ENOMEMwhileadis->bufferstill holds the freed pointer from the previous scan configuration, causing a double-free on the next scan mode update or during device teardown inadis_buffer_cleanup().
Quoted 6 lines
Clear both pointers immediately after freeing them.
Fixes aacff892cbd5 ("staging:iio:adis: Preallocate transfer message")Signed-off-by Lee Jones <[email protected]>
Seems good to me. Given Radu has a bunch of work in flight on around the adis drivers and lib. +CC Radu to take a look before I pick this up.
Quoted 18 lines
--- drivers/iio/imu/adis_buffer.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/imu/adis_buffer.c +2
-0@@ -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);
Jonathan Cameron
maintainerRe: [PATCH 02/10] iio: accel: adxl313: Prevent FIFO buffer overflow in adxl313_fifo_transfer()
In reply to Andy ShevchenkoQuoted 17 lines · On Thu, 19 Nov 2026 19:22:17 +0200 Andy Shevchenko…
Quoted 13 lines · Lee Jones
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 inADXL313_NUM_AXIS*ADXL313_FIFO_SIZE+ 1,fifo_bufis 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-bitFIFO_STATUSentries field (0..63) without bounds checking, allowing a malfunctioning or spoofed bus device to overflowfifo_bufon the heap inadxl313_fifo_transfer().Parenthesise (
ADXL313_FIFO_SIZE+ 1) when sizingfifo_bufand reject entry counts exceedingADXL313_FIFO_SIZE+ 1 inadxl313_get_samples()....
Quoted 8 lines
drivers/iio/accel/adxl313_core.c static int adxl313_get_samples(struct adxl313_data *data) · line 927
Quoted 5 lines
drivers/iio/accel/adxl313_core.c +4
-1-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 -EINVAL ;ERANGE? EIO? EPROTO? (I think from the listed the first suits better, but maybe in
errno.ha better one is lurking.)
EIO would be my preference given it's a sign of corrupt message or broken hardware. I can tweak whilst applying if everyone is fine with that.
Quoted 3 lines
Quoted 2 lines
drivers/iio/accel/adxl313_core.c +1
-0+return ret;
Re: [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name
In reply to Fabrice GasnierQuoted 21 lines · On Fri, 20 Nov 2026 18:22:26 +0100 Fabrice Gasnier…
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Lee Jones
stm32_adc_generic_chan_init()reads the child node's reg property into a signed int and, when the optional label property is present, writes into adc->chan_name[val] and callsstm32_adc_populate_int_ch()before checking whether val exceedsadc_info->max_channels. Because val is signed, values with the top bit set also become negative and bypass the upper-bound check altogether.Store val as a u32, matching
fwnode_property_read_u32(), and move themax_channelsbounds check immediately after reading reg.Quoted 8 lines
...
drivers/iio/adc/stm32-adc.c static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, · line 2759
Quoted 2 lines
drivers/iio/adc/stm32-adc.c +2
-0+if (val >= adc_info->max_channels) + return dev_err_probe(dev, -EINVAL,
-ECHRNGHowever it seems in the original code like this.
Quoted 8 lines
Hi Lee, Andy
I've no strong opinion on this remark, whether to change the error code here, and if it belongs to this fix ?
In all case,
Acked-by Fabrice Gasnier <[email protected]>
Let us not over think it.
Applied. Given it's hardening against a bad DT, not rushing this one in. It can wait for the next merge window.
Thanks,
Jonathan
Quoted 11 lines
Best Regards,
Thanks,
FabriceQuoted 5 lines
Quoted 4 lines
drivers/iio/adc/stm32-adc.c +2
-0+ "Invalid channel %u\n", val); + ret =fwnode_property_read_string (child,"label" , &name);
Jonathan Cameron
maintainerRe: [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
In reply to Fabrice GasnierQuoted 19 lines · On Fri, 20 Nov 2026 18:23:19 +0100 Fabrice Gasnier…
Quoted 12 lines · Lee Jones
stm32_adc_irq_remove()disposes of the child IRQ mappings and removespriv->domainbefore clearing the parent chained IRQ handlers. Because the parent hardware interrupt lines remain unmasked while child devices usedummy_irq_chip, an interrupt arriving during teardown invokesstm32_adc_irq_handler()afterirq_domain_remove()has freedpriv->domain, andirq_set_chained_handler()also leaveshandler_datadangling.Detach the chained handlers and clear
handler_datawithirq_set_chained_handler_and_data()before tearing down the mappings and removing the domain.Quoted 5 lines
Fixes 1add69880240 ("iio: adc: Add support for STM32 ADC core")Signed-off-by Lee Jones <[email protected]>---
Quoted 3 lines
Hi Lee,
Acked-by Fabrice Gasnier <[email protected]>
This one seems a little more likely to be hit in practice, but it doesn't apply to the fixes tree due to some other recent changes and I'm lazy.
Hence applied to the testing branch of iio.git to line it up for next merge cycle. We are getting late enough I should be keeping fixes to critical stuff only and I'm going to assume this one isn't.
Jonathan
Quoted 29 lines
Best Regards,
Thanks,
FabriceQuoted 23 lines
drivers/iio/adc/stm32-adc-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/iio/adc/stm32-adc-core.c +3
-3@@ -467,12 +467,12 @@ static void stm32_adc_irq_remove(struct platform_device *pdev,int hwirq;unsigned int i; +for (i =0 ; i < priv->nb_irqs; i++) +irq_set_chained_handler_and_data (priv->irq[i],NULL ,NULL ); +for (hwirq =0 ; hwirq < priv->nb_adc_max; hwirq++)irq_dispose_mapping (irq_find_mapping (priv->domain, hwirq));irq_domain_remove (priv->domain); - -for (i =0 ; i < priv->nb_irqs; i++) -irq_set_chained_handler (priv->irq[i],NULL ); } static int stm32_adc_core_switches_supply_en(struct stm32_adc_priv *priv,
Jonathan Cameron
maintainerRe: [PATCH 06/10] iio: adc: pac1934: Fix custom attribute allocation and channel bounds
In reply to Andy ShevchenkoQuoted 34 lines · On Thu, 19 Nov 2026 19:27:56 +0200 Andy Shevchenko…
Quoted 15 lines · Lee Jones
pac1934_prep_custom_attributes()sizes thepac1934_custom_attrpointer array usingsizeof(*pac1934_group)instead ofsizeof(*pac1934_custom_attr)and adds 1 byte rather than one pointer element for the terminating NULL entry. Whenactive_channels_countis zero, only a single byte is allocated andiio_device_register_sysfs()reads past the allocation when scanning the attribute list.In addition,
active_channels_countis counted overinfo->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 withdevm_kzalloc_objs()and bound the population loop byinfo->phys_channels....
drivers/iio/adc/pac1934.c static IIO_DEVICE_ATTR(in_shunt_resistor3, 0644, · line 1448
Quoted 2 lines
drivers/iio/adc/pac1934.c +1
-1-int i, active_channels_count =0 ; +int i, j, active_channels_count =0 ;While at it, can we move to make it more like a reversed xmas tree order? But see below first.
...
drivers/iio/adc/pac1934.c static int pac1934_prep_custom_attributes(struct pac1934_chip_info *info, · line 1470
Quoted 4 lines
drivers/iio/adc/pac1934.c +4
-0+ j =0 ; +for (i =0 ; i < info->phys_channels; i++) +if (info->active_channels[i]) + pac1934_custom_attr[j++] = pac1934_shunt_attrs[i];But i is not used outside of the loop, can we rather have
Quoted 7 lines
i = 0; for (int j = 0; j < info->phys_channels; j++) if (info->active_channels[j]) pac1934_custom_attr[i++] = pac1934_shunt_attrs[j];? In such a case the above hunk won't be needed.
This change seems reasonable but significant enough I'm not going to just tweak it whilst applying.
So v2 on this one please.
Thanks,
J
Jonathan Cameron
maintainerRe: [PATCH 07/10] iio: adc: qcom-spmi-adc5-gen3: Free TM auxiliary device wrapper in release callback
In reply to Andy ShevchenkoQuoted 36 lines · On Thu, 19 Nov 2026 19:30:35 +0200 Andy Shevchenko…
Quoted 13 lines · Lee Jones
struct
tm5_aux_dev_wrapperembeds a reference-counted structauxiliary_device, whose memory must be released from its dev.release callback once the final device reference is dropped.Allocating the wrapper with
devm_kzalloc_obj()on the parent ADC device and providing an emptyadc5_gen3_aux_device_release()causes parent devres teardown to free the wrapper immediately afterauxiliary_device_uninit(), even if external references to the embedded struct device are still held.Allocate the wrapper with
kzalloc_obj(), release it fromadc5_gen3_aux_device_release(), and unwind cleanly on early error paths inadc5_gen3_add_aux_tm_device()....
drivers/iio/adc/qcom-spmi-adc5-gen3.c static void adc5_gen3_delete_aux(void *data) · line 614
Quoted 11 lines
#include <
linux/platform_device.h>
#include <linux/property.h>
#include <linux/regmap.h>drivers/iio/adc/qcom-spmi-adc5-gen3.c +5
-0+#include <linux/slab.h> #include <linux/types.h> #include <linux/unaligned.h> +static void adc5_gen3_aux_device_release (struct device *dev) +{ +struct tm5_aux_dev_wrapper *aux_device = + container_of(dev, struct tm5_aux_dev_wrapper, aux_dev.dev);
container_of()is also in a separate header, id estcontainer_of.h.Quoted 2 lines
(quoted diff) +2
-0+ kfree(aux_device); +}...
Quoted 9 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc, int id) · line 668
Quoted 5 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c +3
-1ret =auxiliary_device_add (&aux_device->aux_dev); -if (ret) +if (ret) { +devm_release_action (adc->dev, adc5_gen3_uninit_aux, + &aux_device->aux_dev);Oh, this is interesting... Usually the release devm_*() calls point to a misdesign somewhere. But I haven't checked the twisted flow of this code.
It's one of those complex / annoying cases where a driver uses devm but carries on with a subset of features if a particular bit doesn't work.
Right answer here is probably a devres group.
That is independent of the handoff dance done here.
I'd move the auxiliary_device_init() earlier, stop messing with the memory being devm controlled at all except by adding a put_device() in a dev_add_action_or_reset(). Actually that's already done by the auxiliary_device_uniit.
Anyhow, whilst I haven't looked at this that closely looks like right clean answer is a dev_res group for the whole function (can be done at the caller if neater). That allows either handling the group over to normal devres cleanup on success, or cleaning it up on erorr.
That plus the move of the kfree into release as Lee has done. Also smells like tm_props lifetime is probably wrong as well and should be part of the release rather than devm_kzalloc.
Jonathan
Quoted 13 lines
Quoted 12 lines
drivers/iio/adc/qcom-spmi-adc5-gen3.c +6
-1return ret; + } + ret =devm_add_action_or_reset (adc->dev, adc5_gen3_delete_aux, &aux_device->aux_dev); -if (ret) +if (ret) { +devm_release_action (adc->dev, adc5_gen3_uninit_aux, + &aux_device->aux_dev);return ret; + }
Jonathan Cameron
maintainerRe: [PATCH 10/10] iio: light: tsl2591: Prevent infinite recursion on threshold boundaries
In reply to Lee JonesQuoted 19 lines · On Thu, 19 Nov 2026 15:30:43 +0000 Lee Jones <[email protected]> wrote:
tsl2591_set_als_lower_threshold()adjusts the upper threshold toals_lower_threshold+ 1 whenever the new lower threshold is greater than or equal to the current upper threshold, andtsl2591_set_als_upper_threshold()symmetrically adjusts the lower threshold toals_upper_threshold- 1.Writing 65535 (
TSL2591_ALS_MAX_VALUE) to the falling threshold wraps the 16-bit addition to 0 and callstsl2591_set_als_upper_threshold(chip, 0), which then wraps 0 - 1 back to 65535 and callstsl2591_set_als_lower_threshold(chip, 65535)in an infinite mutual recursion until the kernel stack overflows. Writing 0 to the rising threshold triggers the same cycle whenever the lower threshold is non-zero.Reject
als_lower_threshold==TSL2591_ALS_MAX_VALUEandals_upper_threshold== 0 with-EINVAL, propagate errors from the cross-calls, and only updatechip->als_settingsonce the I2C writes succeed.
Quoted 4 lines
Fixes 2335f0d7c790 ("iio: light: Added AMS tsl2591 driver implementation")Signed-off-by Lee Jones <[email protected]>
Ouch.
Applied to the fixes-togreg branch of iio.git.
Thanks,
Jonathan
Re: [PATCH 05/10] iio: adc: stm32-adc: Detach chained IRQ handler before removing domain
In reply to Jonathan CameronQuoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Fri, 20 Nov 2026 18:23:19 +0100 Fabrice Gasnier…
Quoted 12 lines · Lee Jones
stm32_adc_irq_remove()disposes of the child IRQ mappings and removespriv->domainbefore clearing the parent chained IRQ handlers. Because the parent hardware interrupt lines remain unmasked while child devices usedummy_irq_chip, an interrupt arriving during teardown invokesstm32_adc_irq_handler()afterirq_domain_remove()has freedpriv->domain, andirq_set_chained_handler()also leaveshandler_datadangling.Detach the chained handlers and clear
handler_datawithirq_set_chained_handler_and_data()before tearing down the mappings and removing the domain.Quoted 5 lines
Fixes 1add69880240 ("iio: adc: Add support for STM32 ADC core")Signed-off-by Lee Jones <[email protected]>---
Hi Lee,
Quoted 8 lines
Quoted 1 line
Acked-by Fabrice Gasnier <[email protected]>This one seems a little more likely to be hit in practice, but it doesn't apply to the fixes tree due to some other recent changes and I'm lazy.
Hence applied to the testing branch of iio.git to line it up for next merge cycle. We are getting late enough I should be keeping fixes to critical stuff only and I'm going to assume this one isn't.
My preference for all of these sets is for them to be applied for -next rather than -fixes, if it's all the same to you.
And yes, v2s are no issue (replying to your other comments here).
Bear with.
Signature · 1 line
Lee Jones