Skip to content

Commit 4cb79ef

Browse files
GustavoARSilvabroonie
authored andcommitted
ASoC: amd: Fix potential NULL pointer dereference
Check return value from call to devm_kzalloc() in order to prevent a potential NULL pointer dereference. Also, notice that it makes no sense to allocate any resources if res = platform_get_resource(pdev, IORESOURCE_MEM, 0); fails, so move the call to devm_kzalloc() below the mentioned code. Lastly, improve the use of sizeof in the call to devm_kzalloc() by changing it from sizeof(struct i2s_dev_data) to sizeof(*adata) This issue was detected with the help of Coccinelle. Fixes: ac289c7 ("ASoC: amd: add ACP3x PCM platform driver") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c407cd0 commit 4cb79ef

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sound/soc/amd/raven/acp3x-pcm-dma.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,16 @@ static int acp3x_audio_probe(struct platform_device *pdev)
611611
}
612612
irqflags = *((unsigned int *)(pdev->dev.platform_data));
613613

614-
adata = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dev_data),
615-
GFP_KERNEL);
616614
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
617615
if (!res) {
618616
dev_err(&pdev->dev, "IORESOURCE_IRQ FAILED\n");
619617
return -ENODEV;
620618
}
621619

620+
adata = devm_kzalloc(&pdev->dev, sizeof(*adata), GFP_KERNEL);
621+
if (!adata)
622+
return -ENOMEM;
623+
622624
adata->acp3x_base = devm_ioremap(&pdev->dev, res->start,
623625
resource_size(res));
624626

0 commit comments

Comments
 (0)