[PATCH 6/6] firmware: raspberrypi: Handle device registration errors

From: Sander Speetjens

Date: Sat Nov 07 2026 - 12:02:55 EST


Check the return value of platform_device_register_data() before assigning
it to the global rpi_hwmon / rpi_clk pointers. Previously an ERR_PTR was
stored on failure, which could be used later without proper checking.

Do not propagate the error to the caller. The hwmon and clock platform
devices are optional helpers; making the whole rpi_firmware_probe() fail
just because a child platform device could not be created would be worse,
as it would lose the firmware interface that many other drivers need.

Fixes: 70eea1bbb556 ("firmware: raspberrypi: Register hwmon driver")
Fixes: 91f2cf4a6b21 ("firmware: raspberrypi: register clk device")
Signed-off-by: Sander Speetjens <sander.speetjens@xxxxxxxxx>
---
drivers/firmware/raspberrypi.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 57f21e4e65d6..48cb8063ddb9 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -203,6 +203,7 @@ rpi_firmware_print_firmware_revision(struct rpi_firmware *fw)
static void
rpi_register_hwmon_driver(struct device *dev, struct rpi_firmware *fw)
{
+ struct platform_device *pdev;
u32 packet;
int ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_THROTTLED,
&packet, sizeof(packet));
@@ -210,13 +211,19 @@ rpi_register_hwmon_driver(struct device *dev, struct rpi_firmware *fw)
if (ret)
return;

- rpi_hwmon = platform_device_register_data(dev, "raspberrypi-hwmon",
- -1, NULL, 0);
+ pdev = platform_device_register_data(dev, "raspberrypi-hwmon",
+ -1, NULL, 0);
+
+ if (IS_ERR(pdev))
+ return;
+
+ rpi_hwmon = pdev;
}

static void rpi_register_clk_driver(struct device *dev)
{
struct device_node *firmware;
+ struct platform_device *pdev;

/*
* Earlier DTs don't have a node for the firmware clocks but
@@ -230,8 +237,13 @@ static void rpi_register_clk_driver(struct device *dev)
return;
}

- rpi_clk = platform_device_register_data(dev, "raspberrypi-clk",
- -1, NULL, 0);
+ pdev = platform_device_register_data(dev, "raspberrypi-clk",
+ -1, NULL, 0);
+
+ if (IS_ERR(pdev))
+ return;
+
+ rpi_clk = pdev;
}

static void rpi_register_rtc_driver(struct device *dev)

--
2.56.0