clk: bcm: Add NULL check in raspberrypi_clk_register()
Subsystems (2)
PATCH 1/1 clk: bcm: Add NULL check in raspberrypi_clk_register()
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.
--- drivers/clk/bcm/clk-raspberrypi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/bcm/clk-raspberrypi.c +2 -0
@@ -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 ;
Signature · 1 line
2.34.1
Hi Henry
Thanks for the patch.
Quoted 8 lines · 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")
Nit: It was 93d2725affd6 ("clk: bcm: rpi: Discover the firmware clocks") that introduced the devm_kasprintf. 7dad8a613185 only changed the thing being printed.
Quoted 1 line
Signed-off-by Henry Martin <[email protected]>
Quoted 20 lines
--- drivers/clk/bcm/clk-raspberrypi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/clk/bcm/clk-raspberrypi.c +2
-1@@ -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
PATCH v2 1/1 clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
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.
---
V1 -> V2: Correct the commit hash in the Fixes: tag.
drivers/clk/bcm/clk-raspberrypi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/bcm/clk-raspberrypi.c +2 -0
@@ -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 ;
Signature · 1 line
2.34.1
Re: [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
Am 02.04.25 um 04:05 schrieb Henry Martin:
Quoted 9 lines
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 <[email protected]>Reviewed-by Dave Stevenson <[email protected]>
Just a note, please don't send new patch versions as a reply to older ones. This makes them harder to find.
Thanks
Quoted 19 lines
---
V1 -> V2: Correct the commit hash in the Fixes: tag.drivers/clk/bcm/clk-raspberrypi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/clk/bcm/clk-raspberrypi.c +2
-0@@ -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 ;
Re: [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
Quoted 2 lines
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
Quoted 37 lines · Stefan Wahren <[email protected]> 于2025年4月17日周四 18:09写道:
Am 02.04.25 um 04:05 schrieb Henry Martin:
Quoted 9 lines
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 <[email protected]>Reviewed-by Dave Stevenson <[email protected]>Reviewed-by Stefan Wahren <[email protected]>Just a note, please don't send new patch versions as a reply to older ones. This makes them harder to find.
Thanks
Quoted 19 lines
---
V1 -> V2: Correct the commit hash in the Fixes: tag.drivers/clk/bcm/clk-raspberrypi.c | 2 ++ 1 file changed, 2 insertions(+)drivers/clk/bcm/clk-raspberrypi.c +2
-0@@ -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 ;
Re: [PATCH v2] clk: bcm: rpi: Add NULL check in raspberrypi_clk_register()
In reply to Henry MartinQuoting Henry Martin (2025-04-01 19:05:13)
Quoted 10 lines
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 <[email protected]>Reviewed-by Dave Stevenson <[email protected]>---
Applied to clk-next