Linux ACPI
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: "Rafael J. Wysocki (Intel)" <rafael@kernel.org>,
	 linux-media@vger.kernel.org, linux-acpi@vger.kernel.org,
	 Daniel Scally <dan.scally@ideasonboard.com>,
	 Hans de Goede <hansg@kernel.org>,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Date: Wed, 26 Aug 2026 12:04:34 +0300 (EEST)	[thread overview]
Message-ID: <762e0630-1b04-6a82-69b6-ca5148e74cff@linux.intel.com> (raw)
In-Reply-To: <ao3uh2xos_1uwAgJ@kekkonen.localdomain>

On Tue, 25 Aug 2026, Sakari Ailus wrote:

> Hi Rafael, Ilpo,
> 
> On Tue, Aug 25, 2026 at 03:08:07PM +0200, Rafael J. Wysocki (Intel) wrote:
> > > If there is a cleanup.h "free" that can only be used with objects
> > > returned by acpi_evaluate_dsm_typed(), I'll be fine with that.
> > >
> > > Or if everyone agrees that doing
> > >
> > >     union acpi_object *out_obj __free(ACPI_FREE) = NULL;
> > >
> > > is not confusing and fine, I may just say "Hey, I don't care that much".
> > 
> > And particularly there is this paragraph in a comment in cleanup.h:
> > 
> >  * Given that the "__free(...) = NULL" pattern for variables defined at
> >  * the top of the function poses this potential interdependency problem
> >  * the recommendation is to always define and assign variables in one
> >  * statement and not group variable definitions at the top of the
> >  * function when __free() is used.
> > 
> > regarding a broken code example, so I would think that this is not a
> > made-up concern.
> 
> That's indeed a valid concern, still quite unlikely in practice but
> probably hard to find when it happens, so avoiding that is definitely
> preferred. That being said, the biggest trap in cleanup.h is probably in
> scoped_guard(), and doing __free() = NULL somewhere doesn't matter much in
> the end.

__free() = NULL is not that hard to catch during review (or even in
code already in-tree), have done that dozens of times myself by now.
Checkpatch, too, should be able to catch that easily, if it doesn't 
already.

None of those cases I've commented on had a bug, so it was just for 
teaching submitters & readers of that code the correct __free() pattern.
I think the concern is largely overblown given how rare actual bugs are 
even if the wrong pattern is used. Put that to contrast to memleaks found 
on our rollback paths, __free() looks a clear win despite very rare to 
occur caveats.

Given what I've seen, I'd say on dangerous level __free() = NULL is 
somewhere around using MAGIC_SIZE_DEFINE instead sizeof(*obj) when doing 
mem allocs. It usually isn't buggy even if we don't want to teach people 
to use it.

Besides, it was actually Rafael himself who brought the unsafe pattern 
into this discussion (I immediately noticed the problem but since it was 
not an actual patch, I didn't raise a concern). Sakari's patch did use the 
correct pattern (and if it wouldn't have done so, there would have been a 
review comment from me ;-)). In my reply to Rafael, I intentionally left 
the right side open with "= ..." to not place that NULL there.

> In this case I'll just call ACPI_FREE() sooner.

That works too in this case, yes.

-- 
 i.


  reply	other threads:[~2026-08-26  9:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 21:13 [PATCH v2 0/5] Fix static analyser and compiler warnings in int3472 Sakari Ailus
2026-08-24 21:13 ` [PATCH v2 1/5] platform/x86: int3472: Address Coccinelle warning on an error print Sakari Ailus
2026-08-24 21:13 ` [PATCH v2 2/5] platform/x86: int3472: Fix uninitialised variable warning Sakari Ailus
2026-08-24 21:13 ` [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects Sakari Ailus
2026-08-25 11:51   ` Rafael J. Wysocki (Intel)
2026-08-25 12:07     ` Sakari Ailus
2026-08-25 12:18       ` Rafael J. Wysocki (Intel)
2026-08-25 12:32         ` Ilpo Järvinen
2026-08-25 13:02           ` Rafael J. Wysocki (Intel)
2026-08-25 13:08             ` Rafael J. Wysocki (Intel)
2026-08-25 13:51               ` Ilpo Järvinen
2026-08-25 14:42                 ` Rafael J. Wysocki (Intel)
2026-08-25 19:35               ` Sakari Ailus
2026-08-26  9:04                 ` Ilpo Järvinen [this message]
2026-08-26 10:17                   ` Rafael J. Wysocki (Intel)
2026-08-25 13:37             ` Ilpo Järvinen
2026-08-25 13:49               ` Rafael J. Wysocki (Intel)
2026-08-24 21:13 ` [PATCH v2 4/5] platform/x86: int3472: Release ACPI objects using __free() Sakari Ailus
2026-08-25 11:54   ` Rafael J. Wysocki (Intel)
2026-08-25 12:04     ` Sakari Ailus
2026-08-25 12:32       ` Rafael J. Wysocki (Intel)
2026-08-24 21:13 ` [PATCH v2 5/5] platform/x86: int3472: Clean up GPIO parsing Sakari Ailus
2026-08-25 10:40   ` Ilpo Järvinen
2026-08-25 10:54     ` Sakari Ailus

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=762e0630-1b04-6a82-69b6-ca5148e74cff@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=hansg@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /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