* [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime
@ 2026-11-07 18:21 Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 1/6] firmware: raspberrypi: Add blank line after declaration in response_callback Sander Speetjens
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
This series does minor style cleanups in the Raspberry Pi firmware
driver and fixes the lifetime handling of the hwmon and clock child
devices.
The first five patches address checkpatch warnings (missing blank lines
after declarations, incorrect indentation, unnecessary braces, and
undocumented memory barriers).
The final patch moves the hwmon and clock platform device pointers from
globals into struct rpi_firmware. This pairs their lifetime with the
parent device and prevents leaks or incorrect unregistration if the
driver is probed more than once. It also checks the return value of
platform_device_register_data() so that an error pointer is never
stored. Registration failures are not propagated because the child
devices are optional.
---
Changes in v2:
- Move platform device pointers to rpi firmware struct
- Link to v1: https://lore.kernel.org/r/20261107-fix-raspberrypi-firmware-v1-0-707362c710cd@gmail.com
---
Sander Speetjens (6):
firmware: raspberrypi: Add blank line after declaration in response_callback
firmware: raspberrypi: Fix indentation of return statement
firmware: raspberrypi: Add blank line after declaration in probe error path
firmware: raspberrypi: Remove unnecessary braces in transaction helper
firmware: raspberrypi: Document memory barriers in property list path
firmware: raspberrypi: Store child devices in struct rpi_firmware
drivers/firmware/raspberrypi.c | 61 ++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 23 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-fix-raspberrypi-firmware-be9c602d6755
Best regards,
--
Sander Speetjens <sander.speetjens@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/6] firmware: raspberrypi: Add blank line after declaration in response_callback
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
@ 2026-11-07 18:21 ` Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 2/6] firmware: raspberrypi: Fix indentation of return statement Sander Speetjens
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
Add a blank line after the local variable declaration.
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
drivers/firmware/raspberrypi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 443459c8c90f..8f3653c4a669 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -40,6 +40,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);
}
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/6] firmware: raspberrypi: Fix indentation of return statement
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 1/6] firmware: raspberrypi: Add blank line after declaration in response_callback Sander Speetjens
@ 2026-11-07 18:21 ` Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 3/6] firmware: raspberrypi: Add blank line after declaration in probe error path Sander Speetjens
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
The return was over-indented; statements should start on a tab stop.
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
drivers/firmware/raspberrypi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 8f3653c4a669..e0c91719b4d0 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -267,7 +267,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);
}
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 3/6] firmware: raspberrypi: Add blank line after declaration in probe error path
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 1/6] firmware: raspberrypi: Add blank line after declaration in response_callback Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 2/6] firmware: raspberrypi: Fix indentation of return statement Sander Speetjens
@ 2026-11-07 18:21 ` Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 4/6] firmware: raspberrypi: Remove unnecessary braces in transaction helper Sander Speetjens
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
Add the conventional blank line after the local variable declaration.
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
drivers/firmware/raspberrypi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index e0c91719b4d0..04163c3f385d 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -315,6 +315,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);
+
kfree(fw);
return dev_err_probe(dev, ret, "Failed to get mbox channel\n");
}
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 4/6] firmware: raspberrypi: Remove unnecessary braces in transaction helper
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
` (2 preceding siblings ...)
2026-11-07 18:21 ` [PATCH v2 3/6] firmware: raspberrypi: Add blank line after declaration in probe error path Sander Speetjens
@ 2026-11-07 18:21 ` Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 5/6] firmware: raspberrypi: Document memory barriers in property list path Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 6/6] firmware: raspberrypi: Store child devices in struct rpi_firmware Sander Speetjens
5 siblings, 0 replies; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
Braces are not needed around the single-statement arms of the
wait_for_completion_timeout() check.
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
drivers/firmware/raspberrypi.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 04163c3f385d..d9a569a6dae7 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -60,11 +60,10 @@ rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data)
reinit_completion(&fw->c);
ret = mbox_send_message(fw->chan, &message);
if (ret >= 0) {
- if (wait_for_completion_timeout(&fw->c, HZ)) {
+ if (wait_for_completion_timeout(&fw->c, HZ))
ret = 0;
- } else {
+ else
ret = -ETIMEDOUT;
- }
} else {
dev_err(fw->cl.dev, "mbox_send_message returned %d\n", ret);
}
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 5/6] firmware: raspberrypi: Document memory barriers in property list path
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
` (3 preceding siblings ...)
2026-11-07 18:21 ` [PATCH v2 4/6] firmware: raspberrypi: Remove unnecessary braces in transaction helper Sander Speetjens
@ 2026-11-07 18:21 ` Sander Speetjens
2026-11-07 18:46 ` Manuel Ebner
2026-11-07 18:21 ` [PATCH v2 6/6] firmware: raspberrypi: Store child devices in struct rpi_firmware Sander Speetjens
5 siblings, 1 reply; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
Add comments explaining the wmb() before the firmware transaction and
the rmb() before reading the response, as required by coding style.
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
drivers/firmware/raspberrypi.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index d9a569a6dae7..57f21e4e65d6 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -110,10 +110,12 @@ int rpi_firmware_property_list(struct rpi_firmware *fw,
buf[1] = RPI_FIRMWARE_STATUS_REQUEST;
memcpy(&buf[2], data, tag_size);
buf[size / 4 - 1] = RPI_FIRMWARE_PROPERTY_END;
+ /* Make sure the writes to the buffer are visible to the firmware. */
wmb();
ret = rpi_firmware_transaction(fw, MBOX_CHAN_PROPERTY, bus_addr);
+ /* Make sure we see the firmware's response before reading it. */
rmb();
memcpy(data, &buf[2], tag_size);
if (ret == 0 && buf[1] != RPI_FIRMWARE_STATUS_SUCCESS) {
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 6/6] firmware: raspberrypi: Store child devices in struct rpi_firmware
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
` (4 preceding siblings ...)
2026-11-07 18:21 ` [PATCH v2 5/6] firmware: raspberrypi: Document memory barriers in property list path Sander Speetjens
@ 2026-11-07 18:21 ` Sander Speetjens
5 siblings, 0 replies; 8+ messages in thread
From: Sander Speetjens @ 2026-11-07 18:21 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Eric Anholt, Stefan Wahren, Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel, sander.speetjens
The hwmon and clock platform devices were kept in global variables.
Move them into struct rpi_firmware so each instance owns its own
children and their lifetimes are correctly paired with the parent.
Also check the return value of platform_device_register_data() so that
an error pointer is never stored. The child devices are optional; do
not propagate registration failures so the main firmware interface
remains available.
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
drivers/firmware/raspberrypi.c | 50 ++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 57f21e4e65d6..d44b2c9f0d96 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -22,10 +22,6 @@
#define MBOX_DATA28(msg) ((msg) & ~0xf)
#define MBOX_CHAN_PROPERTY 8
-static struct platform_device *rpi_hwmon;
-static struct platform_device *rpi_clk;
-static struct platform_device *rpi_rtc;
-
struct rpi_firmware {
struct mbox_client cl;
struct mbox_chan *chan; /* The property channel. */
@@ -33,6 +29,10 @@ struct rpi_firmware {
u32 enabled;
struct kref consumers;
+
+ struct platform_device *hwmon_dev;
+ struct platform_device *clk_dev;
+ struct platform_device *rtc_dev;
};
static DEFINE_MUTEX(transaction_lock);
@@ -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;
+
+ fw->hwmon_dev = pdev;
}
-static void rpi_register_clk_driver(struct device *dev)
+static void rpi_register_clk_driver(struct device *dev, struct rpi_firmware *fw)
{
struct device_node *firmware;
+ struct platform_device *pdev;
/*
* Earlier DTs don't have a node for the firmware clocks but
@@ -230,11 +237,16 @@ 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;
+
+ fw->clk_dev = pdev;
}
-static void rpi_register_rtc_driver(struct device *dev)
+static void rpi_register_rtc_driver(struct device *dev, struct rpi_firmware *fw)
{
struct platform_device *pdev;
@@ -251,7 +263,7 @@ static void rpi_register_rtc_driver(struct device *dev)
if (IS_ERR(pdev))
return;
- rpi_rtc = pdev;
+ fw->rtc_dev = pdev;
}
unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, unsigned int id)
@@ -328,8 +340,8 @@ static int rpi_firmware_probe(struct platform_device *pdev)
rpi_firmware_print_firmware_revision(fw);
rpi_register_hwmon_driver(dev, fw);
- rpi_register_clk_driver(dev);
- rpi_register_rtc_driver(dev);
+ rpi_register_clk_driver(dev, fw);
+ rpi_register_rtc_driver(dev, fw);
return 0;
}
@@ -348,12 +360,12 @@ static void rpi_firmware_remove(struct platform_device *pdev)
{
struct rpi_firmware *fw = platform_get_drvdata(pdev);
- platform_device_unregister(rpi_hwmon);
- rpi_hwmon = NULL;
- platform_device_unregister(rpi_clk);
- rpi_clk = NULL;
- platform_device_unregister(rpi_rtc);
- rpi_rtc = NULL;
+ platform_device_unregister(fw->hwmon_dev);
+ fw->hwmon_dev = NULL;
+ platform_device_unregister(fw->clk_dev);
+ fw->clk_dev = NULL;
+ platform_device_unregister(fw->rtc_dev);
+ fw->rtc_dev = NULL;
rpi_firmware_put(fw);
}
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 5/6] firmware: raspberrypi: Document memory barriers in property list path
2026-11-07 18:21 ` [PATCH v2 5/6] firmware: raspberrypi: Document memory barriers in property list path Sander Speetjens
@ 2026-11-07 18:46 ` Manuel Ebner
0 siblings, 0 replies; 8+ messages in thread
From: Manuel Ebner @ 2026-11-07 18:46 UTC (permalink / raw)
To: Sander Speetjens, Florian Fainelli,
Broadcom internal kernel review list, Eric Anholt, Stefan Wahren,
Stephen Boyd, Nicolas Saenz Julienne
Cc: linux-rpi-kernel, linux-arm-kernel, linux-kernel
Hi Sander,
On Sat, 2026-11-07 at 19:21 +0100, Sander Speetjens wrote:
> Add comments explaining the wmb() before the firmware transaction and
> the rmb() before reading the response, as required by coding style.
>
> Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
For Patches 1-5/6:
Reviewed-by: Manuel Ebner <manuelebnerli@mailbox.org>
Thanks
Manuel
> ---
> drivers/firmware/raspberrypi.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> index d9a569a6dae7..57f21e4e65d6 100644
> --- a/drivers/firmware/raspberrypi.c
> +++ b/drivers/firmware/raspberrypi.c
> @@ -110,10 +110,12 @@ int rpi_firmware_property_list(struct rpi_firmware *fw,
> buf[1] = RPI_FIRMWARE_STATUS_REQUEST;
> memcpy(&buf[2], data, tag_size);
> buf[size / 4 - 1] = RPI_FIRMWARE_PROPERTY_END;
> + /* Make sure the writes to the buffer are visible to the firmware. */
> wmb();
>
> ret = rpi_firmware_transaction(fw, MBOX_CHAN_PROPERTY, bus_addr);
>
> + /* Make sure we see the firmware's response before reading it. */
> rmb();
> memcpy(data, &buf[2], tag_size);
> if (ret == 0 && buf[1] != RPI_FIRMWARE_STATUS_SUCCESS) {
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-07 18:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 18:21 [PATCH v2 0/6] firmware: raspberrypi: Style cleanups and fix child device lifetime Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 1/6] firmware: raspberrypi: Add blank line after declaration in response_callback Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 2/6] firmware: raspberrypi: Fix indentation of return statement Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 3/6] firmware: raspberrypi: Add blank line after declaration in probe error path Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 4/6] firmware: raspberrypi: Remove unnecessary braces in transaction helper Sander Speetjens
2026-11-07 18:21 ` [PATCH v2 5/6] firmware: raspberrypi: Document memory barriers in property list path Sander Speetjens
2026-11-07 18:46 ` Manuel Ebner
2026-11-07 18:21 ` [PATCH v2 6/6] firmware: raspberrypi: Store child devices in struct rpi_firmware Sander Speetjens
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®