diff mbox series

[v1] ASoC: imx-card: Add NULL check in imx_card_probe()

Message ID 20250401142510.29900-1-bsdhenrymartin@gmail.com (mailing list archive)
State New
Headers show
Series [v1] ASoC: imx-card: Add NULL check in imx_card_probe() | expand

Commit Message

Henry Martin April 1, 2025, 2:25 p.m. UTC
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>
---
 sound/soc/fsl/imx-card.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Frank Li April 1, 2025, 2:52 p.m. UTC | #1
On Tue, Apr 01, 2025 at 10:25:10PM +0800, Henry Martin wrote:
> 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>

>  sound/soc/fsl/imx-card.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
> index 905294682996..3686d468506b 100644
> --- a/sound/soc/fsl/imx-card.c
> +++ b/sound/soc/fsl/imx-card.c
> @@ -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";
>  			}
>  		}
> --
> 2.34.1
>
Mark Brown April 1, 2025, 6:04 p.m. UTC | #2
On Tue, 01 Apr 2025 22:25:10 +0800, Henry Martin wrote:
> 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.
> 
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: imx-card: Add NULL check in imx_card_probe()
      commit: 93d34608fd162f725172e780b1c60cc93a920719

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
index 905294682996..3686d468506b 100644
--- a/sound/soc/fsl/imx-card.c
+++ b/sound/soc/fsl/imx-card.c
@@ -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";
 			}
 		}