Re: [PATCH v1] ASoC: imx-card: Add NULL check in ap806_syscon_common_probe()

From: Stephen Boyd
Date: Sat Jun 21 2025 - 17:24:08 EST


Quoting Henry Martin (2025-04-09 20:04:38)
> devm_kasprintf() in ap_cp_unique_name() returns NULL when memory
> allocation fails. Currently, ap806_syscon_common_probe() does not check
> for this case, which results in a NULL pointer dereference.
>
> Add NULL check after ap_cp_unique_name() to prevent this issue.
>
> Fixes: baf4c10f8878 ("clk: mvebu: ap806: Fix clock name for the cluster")
> Fixes: 33c0259092c8 ("clk: mvebu: add helper file for Armada AP and CP clocks")
> Signed-off-by: Henry Martin <bsdhenrymartin@xxxxxxxxx>
> ---
> drivers/clk/mvebu/ap806-system-controller.c | 24 +++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/drivers/clk/mvebu/ap806-system-controller.c b/drivers/clk/mvebu/ap806-system-controller.c
> index 948bd1e71aea..1461922752e3 100644
> --- a/drivers/clk/mvebu/ap806-system-controller.c
> +++ b/drivers/clk/mvebu/ap806-system-controller.c
> @@ -173,6 +173,10 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
>
> /* CPU clocks depend on the Sample At Reset configuration */
> name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-0");
> + if (!name) {
> + ret = -ENOMEM;
> + goto fail0;
> + }
> ap806_clks[0] = clk_register_fixed_rate(dev, name, NULL,

TL;DR: This patch is unnecessary.

If name is NULL this function will fail. See the kstrdup_const() call in
__clk_register() and how it returns -ENOMEM when the copy of the
init.name is NULL, which is what happens when you duplicate a NULL
pointer.