drivers/platform/x86/amd/pmc/pmc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
amd_pmc_verify_czn_rtc() opens the RTC with rtc_class_open(), which
takes both a device reference and a module reference on the RTC
driver. rtc_class_close() is the matching release, but it is not
called.
Use a __free() to cleanup call on the declaration
Found by code review.
Fixes: 59348401ebed ("platform/x86: amd-pmc: Add special handling for timer based S0i3 wakeup")
Cc: stable@vger.kernel.org
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
Changes in v2:
- modified the patch, thanks for developer's suggestions.
---
drivers/platform/x86/amd/pmc/pmc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/amd/pmc/pmc.c b/drivers/platform/x86/amd/pmc/pmc.c
index 6792aa2c6187..b1ad79b22c07 100644
--- a/drivers/platform/x86/amd/pmc/pmc.c
+++ b/drivers/platform/x86/amd/pmc/pmc.c
@@ -14,6 +14,7 @@
#include <linux/array_size.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/dmi.h>
@@ -646,9 +647,11 @@ static int amd_pmc_wa_irq1(struct amd_pmc_dev *pdev)
return 0;
}
+DEFINE_FREE(rtc_class_close, struct rtc_device *, rtc_class_close(_T));
+
static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *pdev, u32 *arg)
{
- struct rtc_device *rtc_device;
+ struct rtc_device *rtc_device __free(rtc_class_close) = NULL;
time64_t then, now, duration;
struct rtc_wkalrm alarm;
struct rtc_time tm;
--
2.43.0
On Tue, 15 Sep 2026, Ma Ke wrote:
> amd_pmc_verify_czn_rtc() opens the RTC with rtc_class_open(), which
> takes both a device reference and a module reference on the RTC
> driver. rtc_class_close() is the matching release, but it is not
> called.
>
> Use a __free() to cleanup call on the declaration
>
> Found by code review.
>
> Fixes: 59348401ebed ("platform/x86: amd-pmc: Add special handling for timer based S0i3 wakeup")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
> Changes in v2:
> - modified the patch, thanks for developer's suggestions.
> ---
> drivers/platform/x86/amd/pmc/pmc.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/amd/pmc/pmc.c b/drivers/platform/x86/amd/pmc/pmc.c
> index 6792aa2c6187..b1ad79b22c07 100644
> --- a/drivers/platform/x86/amd/pmc/pmc.c
> +++ b/drivers/platform/x86/amd/pmc/pmc.c
> @@ -14,6 +14,7 @@
> #include <linux/array_size.h>
> #include <linux/bitfield.h>
> #include <linux/bits.h>
> +#include <linux/cleanup.h>
> #include <linux/debugfs.h>
> #include <linux/delay.h>
> #include <linux/dmi.h>
> @@ -646,9 +647,11 @@ static int amd_pmc_wa_irq1(struct amd_pmc_dev *pdev)
> return 0;
> }
>
> +DEFINE_FREE(rtc_class_close, struct rtc_device *, rtc_class_close(_T));
I'm sorry, I only now realize this is not a local thing at all so it would
below to the header defining rtc_class_open/close().
More importantly, rtc_class_close() does not handle NULL inputs so
this DEFINE_FREE() should have the if (_T) boilerplate.
> +
> static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *pdev, u32 *arg)
> {
> - struct rtc_device *rtc_device;
> + struct rtc_device *rtc_device __free(rtc_class_close) = NULL;
Please move this to where the actual assignment to rtc_device occurs as
explained in the long comment in cleanup.h.
> time64_t then, now, duration;
> struct rtc_wkalrm alarm;
> struct rtc_time tm;
>
--
i.
© 2016 - 2026 Red Hat, Inc.