linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Henry Martin <bsdhenrymartin@gmail.com>
To: andrew@lunn.ch, gregory.clement@bootlin.com,
	sebastian.hesselbarth@gmail.com, mturquette@baylibre.com,
	sboyd@kernel.org
Cc: linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Henry Martin <bsdhenrymartin@gmail.com>
Subject: [PATCH v1] ASoC: imx-card: Add NULL check in ap806_syscon_common_probe()
Date: Thu, 10 Apr 2025 11:04:38 +0800	[thread overview]
Message-ID: <20250410030438.53232-1-bsdhenrymartin@gmail.com> (raw)

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@gmail.com>
---
 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,
 						0, cpuclk_freq);
 	if (IS_ERR(ap806_clks[0])) {
@@ -181,6 +185,10 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
 	}
 
 	name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-1");
+	if (!name) {
+		ret = -ENOMEM;
+		goto fail1;
+	}
 	ap806_clks[1] = clk_register_fixed_rate(dev, name, NULL, 0,
 						cpuclk_freq);
 	if (IS_ERR(ap806_clks[1])) {
@@ -190,6 +198,10 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
 
 	/* Fixed clock is always 1200 Mhz */
 	fixedclk_name = ap_cp_unique_name(dev, syscon_node, "fixed");
+	if (!name) {
+		ret = -ENOMEM;
+		goto fail2;
+	}
 	ap806_clks[2] = clk_register_fixed_rate(dev, fixedclk_name, NULL,
 						0, 1200 * 1000 * 1000);
 	if (IS_ERR(ap806_clks[2])) {
@@ -199,6 +211,10 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
 
 	/* MSS Clock is fixed clock divided by 6 */
 	name = ap_cp_unique_name(dev, syscon_node, "mss");
+	if (!name) {
+		ret = -ENOMEM;
+		goto fail3;
+	}
 	ap806_clks[3] = clk_register_fixed_factor(NULL, name, fixedclk_name,
 						  0, 1, 6);
 	if (IS_ERR(ap806_clks[3])) {
@@ -208,6 +224,10 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
 
 	/* SDIO(/eMMC) Clock is fixed clock divided by 3 */
 	name = ap_cp_unique_name(dev, syscon_node, "sdio");
+	if (!name) {
+		ret = -ENOMEM;
+		goto fail4;
+	}
 	ap806_clks[4] = clk_register_fixed_factor(NULL, name,
 						  fixedclk_name,
 						  0, 1, 3);
@@ -218,6 +238,10 @@ static int ap806_syscon_common_probe(struct platform_device *pdev,
 
 	/* AP-DCLK(HCLK) Clock is DDR clock divided by 2 */
 	name = ap_cp_unique_name(dev, syscon_node, "ap-dclk");
+	if (!name) {
+		ret = -ENOMEM;
+		goto fail5;
+	}
 	ap806_clks[5] = clk_register_fixed_rate(dev, name, NULL, 0, dclk_freq);
 	if (IS_ERR(ap806_clks[5])) {
 		ret = PTR_ERR(ap806_clks[5]);
-- 
2.34.1



             reply	other threads:[~2025-04-10  3:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10  3:04 Henry Martin [this message]
2025-06-21 21:23 ` [PATCH v1] ASoC: imx-card: Add NULL check in ap806_syscon_common_probe() Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250410030438.53232-1-bsdhenrymartin@gmail.com \
    --to=bsdhenrymartin@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=gregory.clement@bootlin.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=sebastian.hesselbarth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).