From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Ma Ke <make_ruc2021@163.com>
Cc: Shyam-sundar.S-k@amd.com, Hans de Goede <hansg@kernel.org>,
mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
akpm@linux-foundation.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86/amd/pmc: Fix RTC reference leak in amd_pmc_verify_czn_rtc()
Date: Tue, 15 Sep 2026 15:17:42 +0300 (EEST) [thread overview]
Message-ID: <c6096e2c-0112-81d0-1940-35ba54a66305@linux.intel.com> (raw)
In-Reply-To: <20260915120943.3988720-1-make_ruc2021@163.com>
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.
prev parent reply other threads:[~2026-09-15 12:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 12:09 Ma Ke
2026-09-15 12:17 ` Ilpo Järvinen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c6096e2c-0112-81d0-1940-35ba54a66305@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Shyam-sundar.S-k@amd.com \
--cc=akpm@linux-foundation.org \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=make_ruc2021@163.com \
--cc=mario.limonciello@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®