firmware: raspberrypi: Handle device registration errors
cover firmware: raspberrypi: Handle device registration errors
Hi,
This series improves error handling when registering the Raspberry Pi firmware hwmon and clock platform devices.
The first patch checks errors returned by platform_device_register_data() and unwinds previously allocated resources when registration fails. It preserves the existing behavior of skipping hwmon registration when the RPI_FIRMWARE_GET_THROTTLED request fails.
The second patch fixes formatting issues reported by checkpatch.
Triet Hoang (2):
firmware: raspberrypi: Handle device registration errors
firmware: raspberrypi: Clean up local formatting
drivers/firmware/raspberrypi.c | 60 ++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 firmware: raspberrypi: Handle device registration errors
Check the return value of platform_device_register_data() when registering the hwmon and clock devices. Propagate registration failures to the firmware probe instead of silently ignoring them.
Use local platform device pointers so the global pointers are only updated after successful registration. If clock registration fails, unregister the previously registered hwmon device before releasing the firmware instance.
Keep the existing behavior of skipping hwmon registration when the RPI_FIRMWARE_GET_THROTTLED request fails.
--- drivers/firmware/raspberrypi.c | 57 ++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 13 deletions(-)
drivers/firmware/raspberrypi.c +44 -13
@@ -197,22 +197,31 @@ rpi_firmware_print_firmware_revision(struct rpi_firmware *fw)dev_info (fw->cl.dev,"Attached to firmware from %ptT\n" , &date_and_time); } -static void +static int 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)); +int ret; + ret =rpi_firmware_property (fw,RPI_FIRMWARE_GET_THROTTLED , + &packet,sizeof (packet));if (ret) -return ; +return 0 ; + + pdev =platform_device_register_data (dev,"raspberrypi-hwmon" , +-1 ,NULL ,0 ); +if (IS_ERR (pdev)) +return PTR_ERR (pdev); - rpi_hwmon =platform_device_register_data (dev,"raspberrypi-hwmon" , --1 ,NULL ,0 ); + rpi_hwmon = pdev; + +return 0 ; } -static void rpi_register_clk_driver (struct device *dev) +static int rpi_register_clk_driver (struct device *dev) { +struct platform_device *pdev;struct device_node *firmware;/*
@@ -224,11 +233,17 @@ static void rpi_register_clk_driver(struct device *dev) "raspberrypi,firmware-clocks");if (firmware) {of_node_put (firmware); -return ; +return 0 ; } - 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 PTR_ERR (pdev); + + rpi_clk = pdev; + +return 0 ; }unsigned int rpi_firmware_clk_get_max_rate (struct rpi_firmware *fw,unsigned int id)
@@ -277,6 +292,7 @@ static int rpi_firmware_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct rpi_firmware *fw; +int ret;/* * Memory will be freed by rpi_firmware_delete() once all users have
@@ -292,7 +308,7 @@ static int rpi_firmware_probe(struct platform_device *pdev) fw->chan =mbox_request_channel (&fw->cl,0 );if (IS_ERR (fw->chan)) { -int ret =PTR_ERR (fw->chan); + ret =PTR_ERR (fw->chan);kfree (fw);return dev_err_probe (dev, ret,"Failed to get mbox channel\n" ); }
@@ -303,10 +319,25 @@ static int rpi_firmware_probe(struct platform_device *pdev)platform_set_drvdata (pdev, fw);rpi_firmware_print_firmware_revision (fw); -rpi_register_hwmon_driver (dev, fw); -rpi_register_clk_driver (dev); + + ret =rpi_register_hwmon_driver (dev, fw); +if (ret) + goto err_put_fw; + + ret =rpi_register_clk_driver (dev); +if (ret) + goto err_unregister_hwmon;return 0 ; + +err_unregister_hwmon: +platform_device_unregister (rpi_hwmon); + rpi_hwmon =NULL ; +err_put_fw: +platform_set_drvdata (pdev,NULL ); +rpi_firmware_put (fw); + +return ret; }static void rpi_firmware_shutdown (struct platform_device *pdev)
Signature · 1 line
2.53.0
Am 19.09.26 um 05:48 schrieb Triet Hoang:
Quoted 9 lines
Check the return value of
platform_device_register_data()when registering the hwmon and clock devices. Propagate registration failures to the firmware probe instead of silently ignoring them.Use local platform device pointers so the global pointers are only updated after successful registration. If clock registration fails, unregister the previously registered hwmon device before releasing the firmware instance.
Quoted 6 lines
Keep the existing behavior of skipping hwmon registration when the
RPI_FIRMWARE_GET_THROTTLEDrequest fails.Fixes 70eea1bbb556 ("firmware: raspberrypi: Register hwmon driver")Fixes 91f2cf4a6b21 ("firmware: raspberrypi: register clk device")Signed-off-by Triet Hoang <[email protected]>
PATCH 2/2 firmware: raspberrypi: Clean up local formatting
In reply to Triet HoangAdd a blank line after the local variable declaration in response_callback() and fix the indentation of the UINT_MAX return in rpi_firmware_clk_get_max_rate().
No functional change intended.
--- drivers/firmware/raspberrypi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/raspberrypi.c +2 -1
@@ -39,6 +39,7 @@ static DEFINE_MUTEX(transaction_lock);static void response_callback (struct mbox_client *cl,void *msg) { struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl); +complete (&fw->c); }
@@ -260,7 +261,7 @@ unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, unsigned int* assume the maximum clock rate is absolute maximum we can * store over our type. */ -return UINT_MAX ; +return UINT_MAX ;return le32_to_cpu (msg.rate); }
Signature · 1 line
2.53.0
Re: [PATCH 2/2] firmware: raspberrypi: Clean up local formatting
Am 19.09.26 um 05:48 schrieb Triet Hoang:
Quoted 7 lines
Add a blank line after the local variable declaration in
response_callback()and fix the indentation of theUINT_MAXreturn inrpi_firmware_clk_get_max_rate().No functional change intended.
Signed-off-by Triet Hoang <[email protected]>
Re: [PATCH 2/2] firmware: raspberrypi: Clean up local formatting
In reply to Triet HoangQuoted 3 lines
Add a blank line after the local variable declaration in
response_callback()and fix the indentation of theUINT_MAXreturn inrpi_firmware_clk_get_max_rate().
…
Regards,
Markus
Re: [PATCH 2/2] firmware: raspberrypi: Clean up local formatting
Hi Markus,
Am 22.09.26 um 16:22 schrieb Markus Elfring:
Quoted 7 lines
Quoted 3 lines
Add a blank line after the local variable declaration in
response_callback()and fix the indentation of theUINT_MAXreturn inrpi_firmware_clk_get_max_rate().…
sorry but I didn't get. What's the problem about the commit message?
Quoted 3 lines
Regards,
Markus
Re: [2/2] firmware: raspberrypi: Clean up local formatting
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Add a blank line after the local variable declaration in response_callback() and fix the indentation of the UINT_MAX return in
rpi_firmware_clk_get_max_rate().…
sorry but I didn't get. What's the problem about the commit message?
“… and fix …”
I imagine that another known advice can eventually be taken better into account.
“… Solve only one problem per patch. …”
Regards,
Markus
Re: [2/2] firmware: raspberrypi: Clean up local formatting
Hi Markus,
Am 03.10.26 um 13:17 schrieb Markus Elfring:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Add a blank line after the local variable declaration in response_callback() and fix the indentation of the UINT_MAX return in
rpi_firmware_clk_get_max_rate().…
Quoted 7 lines
Quoted 1 line
sorry but I didn't get. What's the problem about the commit message?
“… and fix …”
I imagine that another known advice can eventually be taken better into account.
“… Solve only one problem per patch. …”
thanks for clarifying. The link pointed to a different line.
Best regards
Quoted 3 lines
Regards,
Markus