2024-06-06 11:12:14

by Aleksandr Mishin

[permalink] [raw]
Subject: [PATCH 5.10/5.15/6.1] clk: mediatek: Add memory allocation fail handling in clk_mt2712_top_init_early()

No upstream commit exists for this commit.

The issue was introduced with commit e2f744a82d72 ("clk: mediatek:
Add MT2712 clock support")

In case of memory allocation fail in clk_mt2712_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 <[email protected]>
---
drivers/clk/mediatek/clk-mt2712.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt2712.c b/drivers/clk/mediatek/clk-mt2712.c
index a0f0c9ed48d1..1830bae661dc 100644
--- a/drivers/clk/mediatek/clk-mt2712.c
+++ b/drivers/clk/mediatek/clk-mt2712.c
@@ -1277,6 +1277,11 @@ static void clk_mt2712_top_init_early(struct device_node *node)

if (!top_clk_data) {
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



2024-06-06 11:28:47

by Aleksandr Mishin

[permalink] [raw]
Subject: [PATCH 5.10/5.15/6.1 v2] clk: mediatek: Add memory allocation fail handling in clk_mt2712_top_init_early()

No upstream commit exists for this commit.

The issue was introduced with commit e2f744a82d72 ("clk: mediatek:
Add MT2712 clock support")

In case of memory allocation fail in clk_mt2712_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: e2f744a82d72 ("clk: mediatek: Add MT2712 clock support")
Signed-off-by: Aleksandr Mishin <[email protected]>
---
v1->v2: Add "Fixes:" tag

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

diff --git a/drivers/clk/mediatek/clk-mt2712.c b/drivers/clk/mediatek/clk-mt2712.c
index a0f0c9ed48d1..1830bae661dc 100644
--- a/drivers/clk/mediatek/clk-mt2712.c
+++ b/drivers/clk/mediatek/clk-mt2712.c
@@ -1277,6 +1277,11 @@ static void clk_mt2712_top_init_early(struct device_node *node)

if (!top_clk_data) {
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


Subject: Re: [PATCH 5.10/5.15/6.1] clk: mediatek: Add memory allocation fail handling in clk_mt2712_top_init_early()

Il 06/06/24 13:09, Aleksandr Mishin ha scritto:
> No upstream commit exists for this commit.
>
> The issue was introduced with commit e2f744a82d72 ("clk: mediatek:
> Add MT2712 clock support")
>
> In case of memory allocation fail in clk_mt2712_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.
>

...the fixes tag is still missing.

Regards,
Angelo

> Signed-off-by: Aleksandr Mishin <[email protected]>
> ---
> drivers/clk/mediatek/clk-mt2712.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/clk/mediatek/clk-mt2712.c b/drivers/clk/mediatek/clk-mt2712.c
> index a0f0c9ed48d1..1830bae661dc 100644
> --- a/drivers/clk/mediatek/clk-mt2712.c
> +++ b/drivers/clk/mediatek/clk-mt2712.c
> @@ -1277,6 +1277,11 @@ static void clk_mt2712_top_init_early(struct device_node *node)
>
> if (!top_clk_data) {
> 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);