* [PATCH v2] platform/x86/amd/pmc: Fix RTC reference leak in amd_pmc_verify_czn_rtc()
@ 2026-09-15 12:09 Ma Ke
2026-09-15 12:17 ` Ilpo Järvinen
0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2026-09-15 12:09 UTC (permalink / raw)
To: Shyam-sundar.S-k, hansg, ilpo.jarvinen, mario.limonciello
Cc: platform-driver-x86, linux-kernel, akpm, Ma Ke, stable
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] platform/x86/amd/pmc: Fix RTC reference leak in amd_pmc_verify_czn_rtc()
2026-09-15 12:09 [PATCH v2] platform/x86/amd/pmc: Fix RTC reference leak in amd_pmc_verify_czn_rtc() Ma Ke
@ 2026-09-15 12:17 ` Ilpo Järvinen
0 siblings, 0 replies; 2+ messages in thread
From: Ilpo Järvinen @ 2026-09-15 12:17 UTC (permalink / raw)
To: Ma Ke
Cc: Shyam-sundar.S-k, Hans de Goede, mario.limonciello,
platform-driver-x86, LKML, akpm, stable
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-15 12:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15 12:09 [PATCH v2] platform/x86/amd/pmc: Fix RTC reference leak in amd_pmc_verify_czn_rtc() Ma Ke
2026-09-15 12:17 ` Ilpo Järvinen
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®