* [PATCH] rtc: jz4740: Register the power-off handler with devres
@ 2026-11-27 11:33 Tian Xuechen
2026-11-27 11:48 ` sashiko-bot
2026-11-27 11:51 ` Paul Cercueil
0 siblings, 2 replies; 3+ messages in thread
From: Tian Xuechen @ 2026-11-27 11:33 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>
---
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..63ef067eb824 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 NOTIFY_DONE;
}
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] 3+ messages in thread
* Re: [PATCH] rtc: jz4740: Register the power-off handler with devres
2026-11-27 11:33 [PATCH] rtc: jz4740: Register the power-off handler with devres Tian Xuechen
@ 2026-11-27 11:48 ` sashiko-bot
2026-11-27 11:51 ` Paul Cercueil
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-27 11:48 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/20261127113337.390592-1-202300460064@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] rtc: jz4740: Register the power-off handler with devres
2026-11-27 11:33 [PATCH] rtc: jz4740: Register the power-off handler with devres Tian Xuechen
2026-11-27 11:48 ` sashiko-bot
@ 2026-11-27 11:51 ` Paul Cercueil
1 sibling, 0 replies; 3+ messages in thread
From: Paul Cercueil @ 2026-11-27 11:51 UTC (permalink / raw)
To: Tian Xuechen, alexandre.belloni, maarten; +Cc: linux-mips, linux-rtc
Hi,
Overall a nice cleanup, I like that it finally gets rid of the
"dev_for_power_off" variable.
One comment below though.
Le vendredi 27 novembre 2026 à 19:33 +0800, Tian Xuechen a écrit :
> 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>
> ---
> 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..63ef067eb824 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 NOTIFY_DONE;
After kernel_halt() runs the hardware should be shut down, so if we get there we
have a problem... I think it would make sense to:
return notifier_from_errno(-EIO);
Cheers,
-Paul
> }
>
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 11:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 11:33 [PATCH] rtc: jz4740: Register the power-off handler with devres Tian Xuechen
2026-11-27 11:48 ` sashiko-bot
2026-11-27 11:51 ` Paul Cercueil
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.