public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] interconnect: Add NULL check in exynos_generic_icc_probe
@ 2025-03-31 11:08 Henry Martin
  2025-03-31 11:32 ` Krzysztof Kozlowski
  2025-03-31 11:34 ` Krzysztof Kozlowski
  0 siblings, 2 replies; 3+ messages in thread
From: Henry Martin @ 2025-03-31 11:08 UTC (permalink / raw)
  To: djakov, krzk
  Cc: s.nawrocki, a.swigon, alim.akhtar, linux-pm, linux-samsung-soc,
	linux-arm-kernel, linux-kernel, Henry Martin

When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function exynos_generic_icc_probe.

A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error. This is similar to the commit 050b23d081da.

Fixes: 2f95b9d5cf0b3 ("interconnect: Add generic interconnect driver for Exynos SoCs")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/interconnect/samsung/exynos.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/interconnect/samsung/exynos.c b/drivers/interconnect/samsung/exynos.c
index 9e041365d909..3dccc84f72cf 100644
--- a/drivers/interconnect/samsung/exynos.c
+++ b/drivers/interconnect/samsung/exynos.c
@@ -134,6 +134,8 @@ static int exynos_generic_icc_probe(struct platform_device *pdev)
 	priv->node = icc_node;
 	icc_node->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn",
 					bus_dev->of_node);
+	if (!icc_node->name)
+		return -ENOMEM;
 	if (of_property_read_u32(bus_dev->of_node, "samsung,data-clock-ratio",
 				 &priv->bus_clk_ratio))
 		priv->bus_clk_ratio = EXYNOS_ICC_DEFAULT_BUS_CLK_RATIO;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] interconnect: Add NULL check in exynos_generic_icc_probe
  2025-03-31 11:08 [PATCH] interconnect: Add NULL check in exynos_generic_icc_probe Henry Martin
@ 2025-03-31 11:32 ` Krzysztof Kozlowski
  2025-03-31 11:34 ` Krzysztof Kozlowski
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-03-31 11:32 UTC (permalink / raw)
  To: Henry Martin, djakov
  Cc: s.nawrocki, a.swigon, alim.akhtar, linux-pm, linux-samsung-soc,
	linux-arm-kernel, linux-kernel

On 31/03/2025 13:08, Henry Martin wrote:
> When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function exynos_generic_icc_probe.

Please wrap commit message according to Linux coding style / submission
process (neither too early nor over the limit):
https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597

Please run scripts/checkpatch.pl on the patches and fix reported
warnings. After that, run also 'scripts/checkpatch.pl --strict' on the
patches and (probably) fix more warnings. Some warnings can be ignored,
especially from --strict run, but the code here looks like it needs a
fix. Feel free to get in touch if the warning is not clear.


> 
> A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error. 



> This is similar to the commit 050b23d081da.

Not related. These are different drivers, so drop.

These apply to all your patches.


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] interconnect: Add NULL check in exynos_generic_icc_probe
  2025-03-31 11:08 [PATCH] interconnect: Add NULL check in exynos_generic_icc_probe Henry Martin
  2025-03-31 11:32 ` Krzysztof Kozlowski
@ 2025-03-31 11:34 ` Krzysztof Kozlowski
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-03-31 11:34 UTC (permalink / raw)
  To: Henry Martin, djakov
  Cc: s.nawrocki, a.swigon, alim.akhtar, linux-pm, linux-samsung-soc,
	linux-arm-kernel, linux-kernel

On 31/03/2025 13:08, Henry Martin wrote:
> ---
>  drivers/interconnect/samsung/exynos.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/interconnect/samsung/exynos.c b/drivers/interconnect/samsung/exynos.c
> index 9e041365d909..3dccc84f72cf 100644
> --- a/drivers/interconnect/samsung/exynos.c
> +++ b/drivers/interconnect/samsung/exynos.c
> @@ -134,6 +134,8 @@ static int exynos_generic_icc_probe(struct platform_device *pdev)
>  	priv->node = icc_node;
>  	icc_node->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn",
>  					bus_dev->of_node);
> +	if (!icc_node->name)
> +		return -ENOMEM;

Ah, and this also leaks ICC node.

Don't create such patches in automated way, but really analyze the
entire code. You just looked at other persons' commit and decided to do
the same, but this is not correct.


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-31 11:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 11:08 [PATCH] interconnect: Add NULL check in exynos_generic_icc_probe Henry Martin
2025-03-31 11:32 ` Krzysztof Kozlowski
2025-03-31 11:34 ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox