[PATCH 01/10] iio: imu: adis: Clear pointers after freeing in adis_update_scan_mode()

From: Lee Jones

Date: Thu Nov 19 2026 - 10:32:30 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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.708.g77570a6a1d-goog