Skip to content

Commit 0a46781

Browse files
tititiou36vinodkoul
authored andcommitted
dmaengine: mcf-edma: Fix a potential un-allocated memory access
When 'mcf_edma' is allocated, some space is allocated for a flexible array at the end of the struct. 'chans' item are allocated, that is to say 'pdata->dma_channels'. Then, this number of item is stored in 'mcf_edma->n_chans'. A few lines later, if 'mcf_edma->n_chans' is 0, then a default value of 64 is set. This ends to no space allocated by devm_kzalloc() because chans was 0, but 64 items are read and/or written in some not allocated memory. Change the logic to define a default value before allocating the memory. Fixes: e7a3ff9 ("dmaengine: fsl-edma: add ColdFire mcf5441x edma support") Signed-off-by: Christophe JAILLET <[email protected]> Link: https://lore.kernel.org/r/f55d914407c900828f6fad3ea5fa791a5f17b9a4.1685172449.git.christophe.jaillet@wanadoo.fr Signed-off-by: Vinod Koul <[email protected]>
1 parent a68b48a commit 0a46781

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/dma/mcf-edma.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ static int mcf_edma_probe(struct platform_device *pdev)
190190
return -EINVAL;
191191
}
192192

193-
chans = pdata->dma_channels;
193+
if (!pdata->dma_channels) {
194+
dev_info(&pdev->dev, "setting default channel number to 64");
195+
chans = 64;
196+
} else {
197+
chans = pdata->dma_channels;
198+
}
199+
194200
len = sizeof(*mcf_edma) + sizeof(*mcf_chan) * chans;
195201
mcf_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
196202
if (!mcf_edma)
@@ -202,11 +208,6 @@ static int mcf_edma_probe(struct platform_device *pdev)
202208
mcf_edma->drvdata = &mcf_data;
203209
mcf_edma->big_endian = 1;
204210

205-
if (!mcf_edma->n_chans) {
206-
dev_info(&pdev->dev, "setting default channel number to 64");
207-
mcf_edma->n_chans = 64;
208-
}
209-
210211
mutex_init(&mcf_edma->fsl_edma_mutex);
211212

212213
mcf_edma->membase = devm_platform_ioremap_resource(pdev, 0);

0 commit comments

Comments
 (0)