Re: [PATCH v4 07/15] rtc: rzn1: Replace remove callback with devm_add_action_or_reset()

[email protected]
Newsgroups org.kernel.vger.linux-rtc,org.kernel.vger.linux-devicetree
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Asynchronous pm_runtime_put() in managed teardown action races with pm_runtime_disable(), leaving hardware powered on.
--

--- Patch [7]: [PATCH v4 07/15] rtc: rzn1: Replace remove callback with devm_add_action_or_reset() ---
commit c31bf08fd16c6f4ea71e35f49bac8367fb7f3cce
Author: Lad Prabhakar <[email protected]>

rtc: rzn1: Replace remove callback with devm_add_action_or_reset()

This commit simplifies driver teardown by registering a managed cleanup action.
It uses devm_add_action_or_reset() to disable hardware and drop the runtime PM
usage count, eliminating the explicit remove callback and probe error paths.

> diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c
> index 94d592e88a044..da7d13337c0da 100644
> --- a/drivers/rtc/rtc-rzn1.c
> +++ b/drivers/rtc/rtc-rzn1.c
> @@ -371,6 +371,17 @@ static const struct rtc_class_ops rzn1_rtc_ops_scmp = {
>  	.alarm_irq_enable = rzn1_rtc_alarm_irq_enable,
>  };
>  
> +static void rzn1_rtc_disable_hardware(void *data)
> +{
> +	struct device *dev = data;
> +	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
> +
> +	/* Disable all interrupts */
> +	writel(0, rtc->base + RZN1_RTC_CTL1);
> +
> +	pm_runtime_put(dev);

[Severity: High]
This isn't a bug introduced by this patch, but does this asynchronous
pm_runtime_put() risk leaving the hardware powered on?

Because rzn1_rtc_disable_hardware() is registered as a devres action, it will
execute during driver unbind just before the automatic cleanup of
pm_runtime_enable(). 

When the devres cleanup calls pm_runtime_disable(), any pending asynchronous
suspend work queued by pm_runtime_put() may be cancelled, leaving the hardware
clocks and power domains permanently active. 

Would it be safer to use pm_runtime_put_sync() here to ensure the device 
reaches a suspended state before the teardown continues?

> +}
> +
>  static int rzn1_rtc_probe(struct platform_device *pdev)
>  {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.