public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Marco Scardovi <mscardovi95@gmail.com>,
	mathias.nyman@linux.intel.com, linux-gpio@vger.kernel.org,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpio: acpi: modernize resource management using cleanup.h
Date: Wed, 6 May 2026 15:46:13 +0300	[thread overview]
Message-ID: <afs4FUf2ppBWrZ4Z@ashevche-desk.local> (raw)
In-Reply-To: <20260506113215.GK6785@black.igk.intel.com>

On Wed, May 06, 2026 at 01:32:15PM +0200, Mika Westerberg wrote:

> +Andy

Thanks for Cc'ing me. Marco, you have to follow the MAINTAINERS database when
submitting this. For simplicity you may use my "smart" script [1] that does
almost right (it still uses heuristics but nobody complained so far) the Cc
lists.


> On Wed, May 06, 2026 at 11:29:36AM +0200, Marco Scardovi wrote:
> > 
> > I was looking for ways to switch to modern cleanup guards and auto-freeing
> > pointers to simplify error paths and synchronization in gpiolib-acpi-core.c
> > so I came up with the patch you can find below.
> > 
> > Here you can see the main points I've worked on:
> > - Use DEFINE_FREE() for gpio_desc and ACPI resources.
> > - Use guard(mutex)() within the OpRegion handler loop for automatic locking.
> > - Use __free() for automatic descriptor and memory cleanup.
> > - Fix off-by-one error in GPIO pin bounds check.
> > - Return AE_OK on out-of-range pins to allow processing other resources
> >   even if one is misconfigured in firmware.
> > - Use break instead of goto in OpRegion handler for cleaner control flow
> >   leveraging auto-cleanup.
> 
> That should be several patches not one doing all these.

As Mika said, please, split this to the per-logical change series.

> > I've tested it (both build and functionality) against linux-next-20260430.

This is assumed, but you can put that into the cover letter.

> > Signed-off-by: Marco Scardovi <mscardovi95@gmail.com>

...

> > +#include <linux/cleanup.h>
> > +#include <linux/slab.h>
> > +
> 
> Drop the empty line.

And follow the existing order.

...

> > +DEFINE_FREE(free_gpio_desc, struct gpio_desc *, {
> > +    if (_T)
> > +        gpiochip_free_own_desc(_T);
> > +})
> > +
> > +DEFINE_FREE(acpi_free, void *, {
> > +    if (_T)
> > +        ACPI_FREE(_T);
> > +})

> These are white space damaged. Also I'm not big fan of these but if Andy is
> fine then works for me too. However, please test with KASAN and kmemleak
> enabled that you don't break anything.

They are fine, but:

- they need to be just one liner as it's done elsewhere
- the {} are redundant (see existing examples)
- they need to be added per subsystem to their headers

(so, two more patches on top of whatever this one has to be split to for
 different subsystems).

...

> >      struct acpi_gpio_event *event;
> >      irq_handler_t handler = NULL;
> >      struct gpio_desc *desc;
> > +    struct gpio_desc *desc_guard __free(free_gpio_desc) = NULL;

This way of defining is highly discouraged. See below.

> >      desc = acpi_request_own_gpiod(chip, agpio, 0, "ACPI:Event");

This one should be used otherwise as

	struct gpio_desc *desc __free(free_gpio_desc) =
		acpi_request_own_gpiod(chip, agpio, 0, "ACPI:Event");

...

> > -    struct acpi_resource *ares;
> > +    struct acpi_resource *ares __free(acpi_free) = NULL;

As per above.

...

[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-05-06 12:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06  9:29 [PATCH] gpio: acpi: modernize resource management using cleanup.h Marco Scardovi
2026-05-06 11:32 ` Mika Westerberg
2026-05-06 12:46   ` Andy Shevchenko [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=afs4FUf2ppBWrZ4Z@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=mscardovi95@gmail.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