* [PATCH v2] rtc: jz4740: Register the power-off handler with devres
@ 2026-11-28 9:56 Tian Xuechen
2026-11-28 10:05 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Tian Xuechen @ 2026-11-28 9:56 UTC (permalink / raw)
To: paul, alexandre.belloni, maarten; +Cc: linux-mips, linux-rtc
From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
A clock registration failure or driver removal leaves the power-off
callback pointing at the old RTC. Register a managed handler with
the device as its callback argument.
This issue was found by our static analysis tool under development.
Fixes: f9eb69d1ae2f ("rtc: jz4740: Add support for acting as the system power controller")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
v2:
- Return notifier_from_errno(-EIO) if kernel_halt() returns, as
suggested by Paul Cercueil.
drivers/rtc/rtc-jz4740.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 32c331f3feb3..825dc035de2e 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -68,7 +68,6 @@ struct jz4740_rtc {
spinlock_t lock;
};
-static struct device *dev_for_power_off;
static inline uint32_t jz4740_rtc_reg_read(struct jz4740_rtc *rtc, size_t reg)
{
@@ -253,10 +252,12 @@ static void jz4740_rtc_poweroff(struct device *dev)
jz4740_rtc_reg_write(rtc, JZ_REG_RTC_HIBERNATE, 1);
}
-static void jz4740_rtc_power_off(void)
+static int jz4740_rtc_power_off(struct sys_off_data *data)
{
- jz4740_rtc_poweroff(dev_for_power_off);
+ jz4740_rtc_poweroff(data->dev);
kernel_halt();
+
+ return notifier_from_errno(-EIO);
}
static const struct of_device_id jz4740_rtc_of_match[] = {
@@ -396,15 +397,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "Failed to request rtc irq\n");
- if (of_device_is_system_power_controller(np)) {
- dev_for_power_off = dev;
-
- if (!pm_power_off)
- pm_power_off = jz4740_rtc_power_off;
- else
- dev_warn(dev, "Poweroff handler already present!\n");
- }
-
if (device_property_present(dev, "#clock-cells")) {
rtc->clk32k.init = CLK_HW_INIT_HW("clk32k", __clk_get_hw(clk),
&jz4740_rtc_clk32k_ops, 0);
@@ -421,6 +413,12 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
"Unable to register clk32k clock provider\n");
}
+ if (of_device_is_system_power_controller(np)) {
+ ret = devm_register_power_off_handler(dev, jz4740_rtc_power_off, NULL);
+ if (ret)
+ dev_warn(dev, "Failed to register power-off handler: %d\n", ret);
+ }
+
return 0;
}
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] rtc: jz4740: Register the power-off handler with devres
2026-11-28 9:56 [PATCH v2] rtc: jz4740: Register the power-off handler with devres Tian Xuechen
@ 2026-11-28 10:05 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-28 10:05 UTC (permalink / raw)
To: Tian Xuechen; +Cc: linux-rtc, Alexandre Belloni
> From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
>
> A clock registration failure or driver removal leaves the power-off
> callback pointing at the old RTC. Register a managed handler with
> the device as its callback argument.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: f9eb69d1ae2f ("rtc: jz4740: Add support for acting as the system power controller")
> Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128095638.840312-1-202300460064@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-28 10:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 9:56 [PATCH v2] rtc: jz4740: Register the power-off handler with devres Tian Xuechen
2026-11-28 10:05 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox