From: Dan Carpenter <dan.carpenter@linaro.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>,
Hans de Goede <hdegoede@redhat.com>,
Patil Rajesh Reddy <Patil.Reddy@amd.com>,
Mario Limonciello <mario.limonciello@amd.com>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] platform/x86/amd/pmf: fix cleanup in amd_pmf_init_smart_pc()
Date: Mon, 10 Mar 2025 17:52:03 +0300 [thread overview]
Message-ID: <4a14c0a5-d6f8-4df9-b947-a0d3c3ef02b3@stanley.mountain> (raw)
In-Reply-To: <32c6c456-94f0-f077-040c-09f67d60953a@linux.intel.com>
On Mon, Mar 10, 2025 at 02:43:51PM +0200, Ilpo Järvinen wrote:
> On Mon, 10 Mar 2025, Dan Carpenter wrote:
>
> > There are a couple problems in this code:
> >
> > First, if amd_pmf_tee_init() fails then the function returns directly
> > instead of cleaning up. We cannot simply do a "goto error;" because
> > that would lead to a double free. I have re-written this code to
> > use an unwind ladder to free the allocations.
>
> Thanks Dan,
>
> Could you please amend this with the information of what is getting
> double freed, it took considerable amount of time for me to figure out.
> I assume it's ->fw_shm_pool ?
>
Yes, that's it. Sure, I can re-write that.
> > Second, if amd_pmf_start_policy_engine() fails on every iteration though
> > the loop then the code calls amd_pmf_tee_deinit() twice which is also a
> > double free. Call amd_pmf_tee_deinit() inside the loop for each failed
> > iteration. Also on that path the error codes are not necessarily
> > negative kernel error codes. Set the error code to -EINVAL.
>
> Maybe I should start to consistently reject any attempt to use
> cleanup/deinit helper functions instead of a proper rollback. It
> seems a pattern that is very prone to errors like this.
I do not like deinit functions. They are so hard to review. But I
detected this bug because of a Smatch warning:
drivers/platform/x86/amd/pmf/tee-if.c:540 amd_pmf_init_smart_pc() warn: missing unwind goto?
regards,
dan carpenter
next prev parent reply other threads:[~2025-03-10 14:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 10:51 Dan Carpenter
2025-03-10 12:43 ` Ilpo Järvinen
2025-03-10 14:52 ` Dan Carpenter [this message]
2025-03-11 8:52 ` Shyam Sundar S K
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=4a14c0a5-d6f8-4df9-b947-a0d3c3ef02b3@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=Patil.Reddy@amd.com \
--cc=Shyam-sundar.S-k@amd.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=platform-driver-x86@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®