linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] clk: bcm: Add NULL check in raspberrypi_clk_register()
@ 2025-04-01 13:23 Henry Martin
  2025-04-01 18:02 ` Dave Stevenson
  0 siblings, 1 reply; 6+ messages in thread
From: Henry Martin @ 2025-04-01 13:23 UTC (permalink / raw)
  To: mturquette, sboyd, florian.fainelli
  Cc: bcm-kernel-feedback-list, dave.stevenson, popcornmix, mripard,
	u.kleine-koenig, nathan, linux-clk, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently,
raspberrypi_clk_register() does not check for this case, which results
in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes: 7dad8a613185 ("clk: bcm: rpi: Give firmware clocks a name")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/clk/bcm/clk-raspberrypi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
index 0e1fe3759530..720acc10f8aa 100644
--- a/drivers/clk/bcm/clk-raspberrypi.c
+++ b/drivers/clk/bcm/clk-raspberrypi.c
@@ -286,6 +286,8 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi,
 	init.name = devm_kasprintf(rpi->dev, GFP_KERNEL,
 				   "fw-clk-%s",
 				   rpi_firmware_clk_names[id]);
+	if (!init.name)
+		return ERR_PTR(-ENOMEM);
 	init.ops = &raspberrypi_firmware_clk_ops;
 	init.flags = CLK_GET_RATE_NOCACHE;
 
-- 
2.34.1



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

* Re: [PATCH v1] clk: bcm: Add NULL check in raspberrypi_clk_register()
  2025-04-01 13:23 [PATCH v1] clk: bcm: Add NULL check in raspberrypi_clk_register() Henry Martin
@ 2025-04-01 18:02 ` Dave Stevenson
  2025-04-02  2:05   ` [PATCH v2] clk: bcm: rpi: " Henry Martin
  0 siblings, 1 reply; 6+ messages in thread
From: Dave Stevenson @ 2025-04-01 18:02 UTC (permalink / raw)
  To: Henry Martin
  Cc: mturquette, sboyd, florian.fainelli, bcm-kernel-feedback-list,
	popcornmix, mripard, u.kleine-koenig, nathan, linux-clk,
	linux-rpi-kernel, linux-arm-kernel, linux-kernel

Hi Henry

Thanks for the patch.

On Tue, 1 Apr 2025 at 14:23, Henry Martin <bsdhenrymartin@gmail.com> wrote:
>
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> raspberrypi_clk_register() does not check for this case, which results
> in a NULL pointer dereference.
>
> Add NULL check after devm_kasprintf() to prevent this issue.
>
> Fixes: 7dad8a613185 ("clk: bcm: rpi: Give firmware clocks a name")

Nit: It was 93d2725affd6 ("clk: bcm: rpi: Discover the firmware
clocks") that introduced the devm_kasprintf. 7dad8a613185 only changed
the thing being printed.

> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

> ---
>  drivers/clk/bcm/clk-raspberrypi.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
> index 0e1fe3759530..720acc10f8aa 100644
> --- a/drivers/clk/bcm/clk-raspberrypi.c
> +++ b/drivers/clk/bcm/clk-raspberrypi.c
> @@ -286,6 +286,8 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi,
>         init.name = devm_kasprintf(rpi->dev, GFP_KERNEL,
>                                    "fw-clk-%s",
>                                    rpi_firmware_clk_names[id]);
> +       if (!init.name)
> +               return ERR_PTR(-ENOMEM);
>         init.ops = &raspberrypi_firmware_clk_ops;
>         init.flags = CLK_GET_RATE_NOCACHE;
>
> --
> 2.34.1
>


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

* [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
  2025-04-01 18:02 ` Dave Stevenson
@ 2025-04-02  2:05   ` Henry Martin
  2025-04-17 10:08     ` Stefan Wahren
  2025-05-06 21:42     ` Stephen Boyd
  0 siblings, 2 replies; 6+ messages in thread
From: Henry Martin @ 2025-04-02  2:05 UTC (permalink / raw)
  To: dave.stevenson
  Cc: mturquette, sboyd, florian.fainelli, bcm-kernel-feedback-list,
	popcornmix, mripard, u.kleine-koenig, linux-clk, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, nathan, Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently,
raspberrypi_clk_register() does not check for this case, which results
in a NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes: 93d2725affd6 ("clk: bcm: rpi: Discover the firmware clocks")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
V1 -> V2: Correct the commit hash in the Fixes: tag.

 drivers/clk/bcm/clk-raspberrypi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
index 0e1fe3759530..720acc10f8aa 100644
--- a/drivers/clk/bcm/clk-raspberrypi.c
+++ b/drivers/clk/bcm/clk-raspberrypi.c
@@ -286,6 +286,8 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi,
 	init.name = devm_kasprintf(rpi->dev, GFP_KERNEL,
 				   "fw-clk-%s",
 				   rpi_firmware_clk_names[id]);
+	if (!init.name)
+		return ERR_PTR(-ENOMEM);
 	init.ops = &raspberrypi_firmware_clk_ops;
 	init.flags = CLK_GET_RATE_NOCACHE;
 
-- 
2.34.1



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

* Re: [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
  2025-04-02  2:05   ` [PATCH v2] clk: bcm: rpi: " Henry Martin
@ 2025-04-17 10:08     ` Stefan Wahren
  2025-04-17 10:17       ` henry martin
  2025-05-06 21:42     ` Stephen Boyd
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Wahren @ 2025-04-17 10:08 UTC (permalink / raw)
  To: Henry Martin
  Cc: mturquette, sboyd, florian.fainelli, bcm-kernel-feedback-list,
	popcornmix, mripard, u.kleine-koenig, linux-clk, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, nathan, dave.stevenson

Am 02.04.25 um 04:05 schrieb Henry Martin:
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> raspberrypi_clk_register() does not check for this case, which results
> in a NULL pointer dereference.
>
> Add NULL check after devm_kasprintf() to prevent this issue.
>
> Fixes: 93d2725affd6 ("clk: bcm: rpi: Discover the firmware clocks")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Stefan Wahren <wahrenst@gmx.net>

Just a note, please don't send new patch versions as a reply to older 
ones. This makes them harder to find.

Thanks
> ---
> V1 -> V2: Correct the commit hash in the Fixes: tag.
>
>   drivers/clk/bcm/clk-raspberrypi.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
> index 0e1fe3759530..720acc10f8aa 100644
> --- a/drivers/clk/bcm/clk-raspberrypi.c
> +++ b/drivers/clk/bcm/clk-raspberrypi.c
> @@ -286,6 +286,8 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi,
>   	init.name = devm_kasprintf(rpi->dev, GFP_KERNEL,
>   				   "fw-clk-%s",
>   				   rpi_firmware_clk_names[id]);
> +	if (!init.name)
> +		return ERR_PTR(-ENOMEM);
>   	init.ops = &raspberrypi_firmware_clk_ops;
>   	init.flags = CLK_GET_RATE_NOCACHE;
>   



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

* Re: [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
  2025-04-17 10:08     ` Stefan Wahren
@ 2025-04-17 10:17       ` henry martin
  0 siblings, 0 replies; 6+ messages in thread
From: henry martin @ 2025-04-17 10:17 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: mturquette, sboyd, florian.fainelli, bcm-kernel-feedback-list,
	popcornmix, mripard, u.kleine-koenig, linux-clk, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, nathan, dave.stevenson

> Just a note, please don't send new patch versions as a reply to older
> ones. This makes them harder to find.

Noted, thanks for the review! I'll make sure to send new patch versions as
separate emails in the future.

Regards,
Henry

Stefan Wahren <wahrenst@gmx.net> 于2025年4月17日周四 18:09写道:
>
> Am 02.04.25 um 04:05 schrieb Henry Martin:
> > devm_kasprintf() returns NULL when memory allocation fails. Currently,
> > raspberrypi_clk_register() does not check for this case, which results
> > in a NULL pointer dereference.
> >
> > Add NULL check after devm_kasprintf() to prevent this issue.
> >
> > Fixes: 93d2725affd6 ("clk: bcm: rpi: Discover the firmware clocks")
> > Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> > Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> Reviewed-by: Stefan Wahren <wahrenst@gmx.net>
>
> Just a note, please don't send new patch versions as a reply to older
> ones. This makes them harder to find.
>
> Thanks
> > ---
> > V1 -> V2: Correct the commit hash in the Fixes: tag.
> >
> >   drivers/clk/bcm/clk-raspberrypi.c | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
> > index 0e1fe3759530..720acc10f8aa 100644
> > --- a/drivers/clk/bcm/clk-raspberrypi.c
> > +++ b/drivers/clk/bcm/clk-raspberrypi.c
> > @@ -286,6 +286,8 @@ static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi,
> >       init.name = devm_kasprintf(rpi->dev, GFP_KERNEL,
> >                                  "fw-clk-%s",
> >                                  rpi_firmware_clk_names[id]);
> > +     if (!init.name)
> > +             return ERR_PTR(-ENOMEM);
> >       init.ops = &raspberrypi_firmware_clk_ops;
> >       init.flags = CLK_GET_RATE_NOCACHE;
> >
>


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

* Re: [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
  2025-04-02  2:05   ` [PATCH v2] clk: bcm: rpi: " Henry Martin
  2025-04-17 10:08     ` Stefan Wahren
@ 2025-05-06 21:42     ` Stephen Boyd
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2025-05-06 21:42 UTC (permalink / raw)
  To: Henry Martin, dave.stevenson
  Cc: mturquette, florian.fainelli, bcm-kernel-feedback-list,
	popcornmix, mripard, u.kleine-koenig, linux-clk, linux-rpi-kernel,
	linux-arm-kernel, linux-kernel, nathan, Henry Martin

Quoting Henry Martin (2025-04-01 19:05:13)
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> raspberrypi_clk_register() does not check for this case, which results
> in a NULL pointer dereference.
> 
> Add NULL check after devm_kasprintf() to prevent this issue.
> 
> Fixes: 93d2725affd6 ("clk: bcm: rpi: Discover the firmware clocks")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> ---

Applied to clk-next


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

end of thread, other threads:[~2025-05-07  3:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-01 13:23 [PATCH v1] clk: bcm: Add NULL check in raspberrypi_clk_register() Henry Martin
2025-04-01 18:02 ` Dave Stevenson
2025-04-02  2:05   ` [PATCH v2] clk: bcm: rpi: " Henry Martin
2025-04-17 10:08     ` Stefan Wahren
2025-04-17 10:17       ` henry martin
2025-05-06 21:42     ` Stephen Boyd

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).