Skip to contentSkip to conversation

iio: adc: nxp-sar-adc: zero-initialize dma_slave_config

PATCH Applied Shuvam Pandey 3 participants 3 messages Apr 6 – Apr 20 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: nxp-sar-adc: zero-initialize dma_slave_config

nxp_sar_adc_start_cyclic_dma() only fills the RX-side members of dma_slave_config before passing it to dmaengine_slave_config().

Zero-initialize the structure so unused members do not contain stack garbage. Some DMA engines consult optional dma_slave_config fields, so leaving them uninitialized can cause DMA setup failures.

Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")
---
 drivers/iio/adc/nxp-sar-adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/nxp-sar-adc.c +1 -1
index 9efa883c277d..7d7b5a580167 100644
@@ -659,7 +659,7 @@ static void nxp_sar_adc_dma_cb(void *data)
 static int nxp_sar_adc_start_cyclic_dma(struct iio_dev *indio_dev)
 {
 	struct nxp_sar_adc *info = iio_priv(indio_dev);
-	struct dma_slave_config config;
+	struct dma_slave_config config = {};
 	struct dma_async_tx_descriptor *desc;
 	int ret;
 
Signature · 1 line
2.50.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Shuvam Pandey

nxp_sar_adc_start_cyclic_dma() only fills the RX-side members of dma_slave_config before passing it to dmaengine_slave_config().

Zero-initialize the structure so unused members do not contain stack garbage. Some DMA engines consult optional dma_slave_config fields, so leaving them uninitialized can cause DMA setup failures.

Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")
---
 drivers/iio/adc/nxp-sar-adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/nxp-sar-adc.c +0 -0
index 9efa883c277d..7d7b5a580167 100644

drivers/iio/adc/nxp-sar-adc.c static void nxp_sar_adc_dma_cb(void *data) · line 662

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c +1 -1
@@ -659,7 +659,7 @@ static void nxp_sar_adc_dma_cb(void *data)
 static int nxp_sar_adc_start_cyclic_dma(struct iio_dev *indio_dev)
 {
 	struct nxp_sar_adc *info = iio_priv(indio_dev);
-	struct dma_slave_config config;
+	struct dma_slave_config config = {};

IIO style is to have space between braces.

Wait and see if Jonathan asks for a new version first though before sending one for trivial changes like that.

drivers/iio/adc/nxp-sar-adc.c static void nxp_sar_adc_dma_cb(void *data) · line 665

Quoted 3 lines
drivers/iio/adc/nxp-sar-adc.c +0 -0
 	struct dma_async_tx_descriptor *desc;
 	int ret;
 
maintainer Applied
#2 lore raw
Quoted 27 lines · On Mon, 6 Apr 2026 08:59:34 -0500 David Lechner <[email protected]> wrote:
Quoted 18 lines · Shuvam Pandey

nxp_sar_adc_start_cyclic_dma() only fills the RX-side members of dma_slave_config before passing it to dmaengine_slave_config().

Zero-initialize the structure so unused members do not contain stack garbage. Some DMA engines consult optional dma_slave_config fields, so leaving them uninitialized can cause DMA setup failures.

Fixes 4434072a893e ("iio: adc: Add the NXP SAR ADC support for the s32g2/3 platforms")
---
 drivers/iio/adc/nxp-sar-adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/nxp-sar-adc.c +0 -0
index 9efa883c277d..7d7b5a580167 100644

drivers/iio/adc/nxp-sar-adc.c static void nxp_sar_adc_dma_cb(void *data) · line 662

Quoted 5 lines
drivers/iio/adc/nxp-sar-adc.c +1 -1
@@ -659,7 +659,7 @@ static void nxp_sar_adc_dma_cb(void *data)
 static int nxp_sar_adc_start_cyclic_dma(struct iio_dev *indio_dev)
 {
 	struct nxp_sar_adc *info = iio_priv(indio_dev);
-	struct dma_slave_config config;
+	struct dma_slave_config config = {};  

IIO style is to have space between braces.

Quoted 9 lines

Wait and see if Jonathan asks for a new version first though before sending one for trivial changes like that.

drivers/iio/adc/nxp-sar-adc.c static void nxp_sar_adc_dma_cb(void *data) · line 665

Quoted 3 lines
drivers/iio/adc/nxp-sar-adc.c +0 -0
 	struct dma_async_tx_descriptor *desc;
 	int ret;
 

Note I picked this up and tweaked as above, so the following is just thoughts on how we might do similar in future.

It is a bigger change but maybe it's worth

	struct dma_slave_config config;

...

	config = (struct dma_slave_config) {
		.direction = DMA_DEV_TO_MEM,
		.src_addr_width = NXP_SAR_ADC_DMA_SAMPLE_SZ,
		.src_addr = NXP_SAR_ADC_CDR(info->regs_phys, info->buffered_chan[0]),
		.src_port_window_size = info->channels_used,
		.src_maxburst = info->channels_used,
	};

Which will ensure whole thing is set at the point of use rather than clear and then fill stuff in later as this patch does.

Given this has been sat a while, lets go for good enough and it's a more minimal patch which is always nice for a fix.

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan