mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 5.10/5.15/6.1] clk: mediatek: mt8183: Add memory
@ 2024-06-06 10:34 Aleksandr Mishin
  2024-06-06 10:55 ` AngeloGioacchino Del Regno
  2024-06-06 11:19 ` [PATCH 5.10/5.15/6.1 v2] clk: mediatek: mt8183: Add memory allocation fail handling in clk_mt8183_top_init_early() Aleksandr Mishin
  0 siblings, 2 replies; 3+ messages in thread
From: Aleksandr Mishin @ 2024-06-06 10:34 UTC (permalink / raw)
  To: Weiyi Lu, stable, Greg Kroah-Hartman
  Cc: Aleksandr Mishin, Michael Turquette, Stephen Boyd,
	Matthias Brugger, Sasha Levin, AngeloGioacchino Del Regno,
	Markus Schneider-Pargmann, linux-clk, linux-arm-kernel,
	linux-mediatek, linux-kernel, lvc-project

No upstream commit exists for this commit.

The issue was introduced with commit c93d059a8045 ("clk: mediatek: mt8183:
Register 13MHz clock earlier for clocksource")

In case of memory allocation fail in clk_mt8183_top_init_early()
'top_clk_data' will be set to NULL and later dereferenced without check.
Fix this bug by adding NULL-return check.

Upstream branch code has been significantly refactored and can't be
backported directly.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/clk/mediatek/clk-mt8183.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c
index 78620244144e..8377a877d9e3 100644
--- a/drivers/clk/mediatek/clk-mt8183.c
+++ b/drivers/clk/mediatek/clk-mt8183.c
@@ -1185,6 +1185,11 @@ static void clk_mt8183_top_init_early(struct device_node *node)
 	int i;
 
 	top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
+	if (!top_clk_data) {
+		pr_err("%s(): could not register clock provider: %d\n",
+			__func__, -ENOMEM);
+		return;
+	}
 
 	for (i = 0; i < CLK_TOP_NR_CLK; i++)
 		top_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
-- 
2.30.2


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

* Re: [PATCH 5.10/5.15/6.1] clk: mediatek: mt8183: Add memory
  2024-06-06 10:34 [PATCH 5.10/5.15/6.1] clk: mediatek: mt8183: Add memory Aleksandr Mishin
@ 2024-06-06 10:55 ` AngeloGioacchino Del Regno
  2024-06-06 11:19 ` [PATCH 5.10/5.15/6.1 v2] clk: mediatek: mt8183: Add memory allocation fail handling in clk_mt8183_top_init_early() Aleksandr Mishin
  1 sibling, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-06-06 10:55 UTC (permalink / raw)
  To: Aleksandr Mishin, Weiyi Lu, stable, Greg Kroah-Hartman
  Cc: Michael Turquette, Stephen Boyd, Matthias Brugger, Sasha Levin,
	Markus Schneider-Pargmann, linux-clk, linux-arm-kernel,
	linux-mediatek, linux-kernel, lvc-project

Il 06/06/24 12:34, Aleksandr Mishin ha scritto:
> No upstream commit exists for this commit.
> 
> The issue was introduced with commit c93d059a8045 ("clk: mediatek: mt8183:
> Register 13MHz clock earlier for clocksource")
> 
> In case of memory allocation fail in clk_mt8183_top_init_early()
> 'top_clk_data' will be set to NULL and later dereferenced without check.
> Fix this bug by adding NULL-return check.
> 
> Upstream branch code has been significantly refactored and can't be
> backported directly.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 

There's no fixes tag, and the commit title shall be fixed, you're not
"adding memory".

Please fix - after which, it kind of makes sense to add this to stable.

Cheers,
Angelo

> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> ---
>   drivers/clk/mediatek/clk-mt8183.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c
> index 78620244144e..8377a877d9e3 100644
> --- a/drivers/clk/mediatek/clk-mt8183.c
> +++ b/drivers/clk/mediatek/clk-mt8183.c
> @@ -1185,6 +1185,11 @@ static void clk_mt8183_top_init_early(struct device_node *node)
>   	int i;
>   
>   	top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
> +	if (!top_clk_data) {
> +		pr_err("%s(): could not register clock provider: %d\n",
> +			__func__, -ENOMEM);
> +		return;
> +	}
>   
>   	for (i = 0; i < CLK_TOP_NR_CLK; i++)
>   		top_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);



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

* [PATCH 5.10/5.15/6.1 v2] clk: mediatek: mt8183: Add memory allocation fail handling in clk_mt8183_top_init_early()
  2024-06-06 10:34 [PATCH 5.10/5.15/6.1] clk: mediatek: mt8183: Add memory Aleksandr Mishin
  2024-06-06 10:55 ` AngeloGioacchino Del Regno
@ 2024-06-06 11:19 ` Aleksandr Mishin
  1 sibling, 0 replies; 3+ messages in thread
From: Aleksandr Mishin @ 2024-06-06 11:19 UTC (permalink / raw)
  To: Weiyi Lu, stable, Greg Kroah-Hartman
  Cc: Aleksandr Mishin, Michael Turquette, Stephen Boyd,
	Matthias Brugger, Sasha Levin, AngeloGioacchino Del Regno,
	Markus Schneider-Pargmann, linux-clk, linux-arm-kernel,
	linux-mediatek, linux-kernel, lvc-project

No upstream commit exists for this commit.

The issue was introduced with commit c93d059a8045 ("clk: mediatek: mt8183:
Register 13MHz clock earlier for clocksource")

In case of memory allocation fail in clk_mt8183_top_init_early()
'top_clk_data' will be set to NULL and later dereferenced without check.
Fix this bug by adding NULL-return check.

Upstream branch code has been significantly refactored and can't be
backported directly.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: c93d059a8045 ("clk: mediatek: mt8183: Register 13MHz clock earlier for clocksource")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
v1->v2: Add "Fixes:" tag, fix subject misspell

 drivers/clk/mediatek/clk-mt8183.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c
index 78620244144e..8377a877d9e3 100644
--- a/drivers/clk/mediatek/clk-mt8183.c
+++ b/drivers/clk/mediatek/clk-mt8183.c
@@ -1185,6 +1185,11 @@ static void clk_mt8183_top_init_early(struct device_node *node)
 	int i;
 
 	top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
+	if (!top_clk_data) {
+		pr_err("%s(): could not register clock provider: %d\n",
+			__func__, -ENOMEM);
+		return;
+	}
 
 	for (i = 0; i < CLK_TOP_NR_CLK; i++)
 		top_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
-- 
2.30.2


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

end of thread, other threads:[~2024-06-06 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-06 10:34 [PATCH 5.10/5.15/6.1] clk: mediatek: mt8183: Add memory Aleksandr Mishin
2024-06-06 10:55 ` AngeloGioacchino Del Regno
2024-06-06 11:19 ` [PATCH 5.10/5.15/6.1 v2] clk: mediatek: mt8183: Add memory allocation fail handling in clk_mt8183_top_init_early() Aleksandr Mishin

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

all inboxes | Powered by JetHome®