Skip to contentSkip to conversation

clk: bcm: rpi: Fix potential NULL pointer dereference

PATCH In review Chenyuan Yang 3 participants 3 messages Feb 11, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: bcm: rpi: Fix potential NULL pointer dereference

The init.name could be NULL. Add missing check in the raspberrypi_clk_register().
This is similar to commit 3027e7b15b02
("ice: Fix some null pointer dereference issues in ice_ptp.c"). Besides, bcm2835_register_pll_divider() under the same directory also has a very similar check.

---
 drivers/clk/bcm/clk-raspberrypi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/bcm/clk-raspberrypi.c +2 -0
index 0e1fe3759530..720acc10f8aa 100644
@@ -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
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Chenyuan Yang

The init.name could be NULL. Add missing check in the raspberrypi_clk_register().
This is similar to commit 3027e7b15b02
("ice: Fix some null pointer dereference issues in ice_ptp.c"). Besides, bcm2835_register_pll_divider() under the same directory also has a very similar check.

Signature · 1 line
Florian
Reviewed-by on v1 1/1
#2 lore raw
In reply to Chenyuan Yang
Quoted 17 lines · Chenyuan Yang

The init.name could be NULL. Add missing check in the raspberrypi_clk_register().
This is similar to commit 3027e7b15b02
("ice: Fix some null pointer dereference issues in ice_ptp.c"). Besides, bcm2835_register_pll_divider() under the same directory also has a very similar check.

---
 drivers/clk/bcm/clk-raspberrypi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/bcm/clk-raspberrypi.c +0 -0
index 0e1fe3759530..720acc10f8aa 100644

drivers/clk/bcm/clk-raspberrypi.c static struct clk_hw *raspberrypi_clk_register(struct raspberrypi_clk *rpi, · line 292

Quoted 7 lines
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;

Thanks for the fix. There is a need for a fixes tag in case like that. Please add it in commit message. Take a look here for example [1].

[1] https://lore.kernel.org/netdev/DM3PR11MB8736BC7EF3A66720427F3775ECF22@DM3PR11MB8736.namprd11.prod.outlook.com/T/#mbc8028620ecffb2f3a23c96130fe03708e679b25

Beside that:

Quoted 3 lines
Signature · 2 lines
-- 
2.34.1