ASoC: imx-card: Add NULL check in imx_card_probe()
authorHenry Martin <bsdhenrymartin@gmail.com>
Tue, 1 Apr 2025 14:25:10 +0000 (22:25 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 1 Apr 2025 16:01:10 +0000 (17:01 +0100)
devm_kasprintf() returns NULL when memory allocation fails. Currently,
imx_card_probe() does not check for this case, which results in a NULL
pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes: aa736700f42f ("ASoC: imx-card: Add imx-card machine driver")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20250401142510.29900-1-bsdhenrymartin@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/fsl/imx-card.c

index 905294682996e6c67b8ccff49cfe4066875d458b..3686d468506b35b75352127cb9d2b0d1d5317e33 100644 (file)
@@ -772,6 +772,8 @@ static int imx_card_probe(struct platform_device *pdev)
                                data->dapm_routes[i].sink =
                                        devm_kasprintf(&pdev->dev, GFP_KERNEL, "%d %s",
                                                       i + 1, "Playback");
+                               if (!data->dapm_routes[i].sink)
+                                       return -ENOMEM;
                                data->dapm_routes[i].source = "CPU-Playback";
                        }
                }
@@ -789,6 +791,8 @@ static int imx_card_probe(struct platform_device *pdev)
                                data->dapm_routes[i].source =
                                        devm_kasprintf(&pdev->dev, GFP_KERNEL, "%d %s",
                                                       i + 1, "Capture");
+                               if (!data->dapm_routes[i].source)
+                                       return -ENOMEM;
                                data->dapm_routes[i].sink = "CPU-Capture";
                        }
                }