* [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h
[not found] <20260506113215.GK6785@://intel.com>
@ 2026-05-06 12:34 ` Marco Scardovi
2026-05-06 12:49 ` Andy Shevchenko
2026-05-06 12:35 ` Marco Scardovi
1 sibling, 1 reply; 8+ messages in thread
From: Marco Scardovi @ 2026-05-06 12:34 UTC (permalink / raw)
To: mika.westerberg
Cc: mathias.nyman, andriy.shevchenko, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
From: Marco Scardovi <mscardovi@icloud.com>
*** BLURB HERE ***
Hi Mika,
thanks for the quick reply. Unfortunately I noticed too late that thunderbird had
broken my patch during copy/paste. I'm pushing it again using git send-mail.
I've divided tha patch in 3 smaller pieces: let me know if it is ok for you and
Andy. In the meantime I'm testing it against KASAN and kmemleak as You suggested.
Let me know if there's anything else I need to improve.
Marco Scardovi (3):
gpio: acpi: modernize resource management using cleanup.h
gpio: acpi: modernize resource management using cleanup.h
gpio: acpi: modernize resource management using cleanup.h
drivers/gpio/gpiolib-acpi-core.c | 68 ++++++++++++++++----------------
1 file changed, 35 insertions(+), 33 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h
[not found] <20260506113215.GK6785@://intel.com>
2026-05-06 12:34 ` [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h Marco Scardovi
@ 2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` Marco Scardovi
` (3 more replies)
1 sibling, 4 replies; 8+ messages in thread
From: Marco Scardovi @ 2026-05-06 12:35 UTC (permalink / raw)
To: mika.westerberg
Cc: mathias.nyman, andriy.shevchenko, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
*** BLURB HERE ***
Hi Mika,
thanks for the quick reply. Unfortunately I noticed too late that thunderbird had
broken my patch during copy/paste. I'm pushing it again using git send-mail.
I've divided tha patch in 3 smaller pieces: let me know if it is ok for you and
Andy. In the meantime I'm testing it against KASAN and kmemleak as You suggested.
Let me know if there's anything else I need to improve.
Marco Scardovi (3):
gpio: acpi: modernize resource management using cleanup.h
gpio: acpi: modernize resource management using cleanup.h
gpio: acpi: modernize resource management using cleanup.h
drivers/gpio/gpiolib-acpi-core.c | 68 ++++++++++++++++----------------
1 file changed, 35 insertions(+), 33 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h
2026-05-06 12:35 ` Marco Scardovi
@ 2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` [PATCH v2 1/3] [PATCH 1/3] " Marco Scardovi
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Marco Scardovi @ 2026-05-06 12:35 UTC (permalink / raw)
To: mika.westerberg
Cc: mathias.nyman, andriy.shevchenko, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
*** BLURB HERE ***
Hi Mika,
thanks for the quick reply. Unfortunately I noticed too late that thunderbird had
broken my patch during copy/paste. I'm pushing it again using git send-mail.
I've divided tha patch in 3 smaller pieces: let me know if it is ok for you and
Andy. In the meantime I'm testing it against KASAN and kmemleak as You suggested.
Let me know if there's anything else I need to improve.
Marco Scardovi (3):
gpio: acpi: modernize resource management using cleanup.h
gpio: acpi: modernize resource management using cleanup.h
gpio: acpi: modernize resource management using cleanup.h
drivers/gpio/gpiolib-acpi-core.c | 68 ++++++++++++++++----------------
1 file changed, 35 insertions(+), 33 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/3] [PATCH 1/3] gpio: acpi: modernize resource management using cleanup.h
2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` Marco Scardovi
@ 2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:51 ` Andy Shevchenko
2026-05-06 12:35 ` [PATCH v2 2/3] [PATCH 2/3] " Marco Scardovi
2026-05-06 12:35 ` [PATCH v2 3/3] [PATCH 3/3] " Marco Scardovi
3 siblings, 1 reply; 8+ messages in thread
From: Marco Scardovi @ 2026-05-06 12:35 UTC (permalink / raw)
To: mika.westerberg
Cc: mathias.nyman, andriy.shevchenko, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
---
drivers/gpio/gpiolib-acpi-core.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index eb8a40cfb7a9..7c17bffcd4e7 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -7,6 +7,8 @@
* Mika Westerberg <mika.westerberg@linux.intel.com>
*/
+#include <linux/cleanup.h>
+#include <linux/slab.h>
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/errno.h>
@@ -23,6 +25,16 @@
#include "gpiolib.h"
#include "gpiolib-acpi.h"
+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);
+})
+
/**
* struct acpi_gpio_event - ACPI GPIO event handler data
*
@@ -361,6 +373,7 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
struct acpi_gpio_event *event;
irq_handler_t handler = NULL;
struct gpio_desc *desc;
+ struct gpio_desc *desc_guard __free(free_gpio_desc) = NULL;
unsigned int pin;
int ret, irq;
@@ -370,6 +383,11 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
handle = ACPI_HANDLE(chip->parent);
pin = agpio->pin_table[0];
+ if (pin >= chip->ngpio) {
+ dev_err(chip->parent, "Failed to request GPIO for pin 0x%04X, out of range\n", pin);
+ return AE_OK;
+ }
+
if (pin <= 255) {
char ev_name[8];
sprintf(ev_name, "_%c%02X",
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] [PATCH 2/3] gpio: acpi: modernize resource management using cleanup.h
2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` [PATCH v2 1/3] [PATCH 1/3] " Marco Scardovi
@ 2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` [PATCH v2 3/3] [PATCH 3/3] " Marco Scardovi
3 siblings, 0 replies; 8+ messages in thread
From: Marco Scardovi @ 2026-05-06 12:35 UTC (permalink / raw)
To: mika.westerberg
Cc: mathias.nyman, andriy.shevchenko, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
---
drivers/gpio/gpiolib-acpi-core.c | 38 ++++++++++++--------------------
1 file changed, 14 insertions(+), 24 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index 7c17bffcd4e7..b6accbaba04d 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -410,31 +410,26 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
desc = acpi_request_own_gpiod(chip, agpio, 0, "ACPI:Event");
if (IS_ERR(desc)) {
- dev_err(chip->parent,
- "Failed to request GPIO for pin 0x%04X, err %pe\n",
- pin, desc);
+ dev_err(chip->parent, "Failed to request GPIO for pin 0x%04X, err %pe\n", pin, desc);
return AE_OK;
}
+ desc_guard = desc;
ret = gpiochip_lock_as_irq(chip, pin);
if (ret) {
- dev_err(chip->parent,
- "Failed to lock GPIO pin 0x%04X as interrupt, err %d\n",
- pin, ret);
- goto fail_free_desc;
+ dev_err(chip->parent, "Failed to lock GPIO pin 0x%04X as interrupt, err %d\n", pin, ret);
+ return AE_OK;
}
irq = gpiod_to_irq(desc);
if (irq < 0) {
- dev_err(chip->parent,
- "Failed to translate GPIO pin 0x%04X to IRQ, err %d\n",
- pin, irq);
- goto fail_unlock_irq;
+ dev_err(chip->parent, "Failed to translate GPIO pin 0x%04X to IRQ, err %d\n", pin, irq);
+ goto err_unlock;
}
event = kzalloc_obj(*event);
if (!event)
- goto fail_unlock_irq;
+ goto err_unlock;
event->irqflags = IRQF_ONESHOT;
if (agpio->triggering == ACPI_LEVEL_SENSITIVE) {
@@ -462,17 +457,15 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
event->irq = irq;
event->irq_is_wake = acpi_gpio_irq_is_wake(chip->parent, agpio);
event->pin = pin;
- event->desc = desc;
+ /* Transfer ownership to event, prevent auto-free */
+ event->desc = no_free_ptr(desc_guard);
list_add_tail(&event->node, &acpi_gpio->events);
return AE_OK;
-fail_unlock_irq:
+err_unlock:
gpiochip_unlock_as_irq(chip, pin);
-fail_free_desc:
- gpiochip_free_own_desc(desc);
-
return AE_OK;
}
@@ -1104,7 +1097,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
struct acpi_gpio_chip *achip = region_context;
struct gpio_chip *chip = achip->chip;
struct acpi_resource_gpio *agpio;
- struct acpi_resource *ares;
+ struct acpi_resource *ares __free(acpi_free) = NULL;
u16 pin_index = address;
acpi_status status;
int length;
@@ -1115,20 +1108,17 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
if (ACPI_FAILURE(status))
return status;
- if (WARN_ON(ares->type != ACPI_RESOURCE_TYPE_GPIO)) {
- ACPI_FREE(ares);
+ if (WARN_ON(ares->type != ACPI_RESOURCE_TYPE_GPIO))
return AE_BAD_PARAMETER;
- }
agpio = &ares->data.gpio;
if (WARN_ON(agpio->io_restriction == ACPI_IO_RESTRICT_INPUT &&
- function == ACPI_WRITE)) {
- ACPI_FREE(ares);
+ function == ACPI_WRITE))
return AE_BAD_PARAMETER;
- }
length = min(agpio->pin_table_length, pin_index + bits);
+ status = AE_OK;
for (i = pin_index; i < length; ++i) {
unsigned int pin = agpio->pin_table[i];
struct acpi_gpio_connection *conn;
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] [PATCH 3/3] gpio: acpi: modernize resource management using cleanup.h
2026-05-06 12:35 ` Marco Scardovi
` (2 preceding siblings ...)
2026-05-06 12:35 ` [PATCH v2 2/3] [PATCH 2/3] " Marco Scardovi
@ 2026-05-06 12:35 ` Marco Scardovi
3 siblings, 0 replies; 8+ messages in thread
From: Marco Scardovi @ 2026-05-06 12:35 UTC (permalink / raw)
To: mika.westerberg
Cc: mathias.nyman, andriy.shevchenko, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
---
drivers/gpio/gpiolib-acpi-core.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index b6accbaba04d..7b6476b90f13 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -1126,7 +1126,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
u16 word, shift;
bool found;
- mutex_lock(&achip->conn_lock);
+ guard(mutex)(&achip->conn_lock);
found = false;
list_for_each_entry(conn, &achip->conns, node) {
@@ -1158,17 +1158,15 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
if (!found) {
desc = acpi_request_own_gpiod(chip, agpio, i, "ACPI:OpRegion");
if (IS_ERR(desc)) {
- mutex_unlock(&achip->conn_lock);
status = AE_ERROR;
- goto out;
+ break;
}
conn = kzalloc_obj(*conn);
if (!conn) {
gpiochip_free_own_desc(desc);
- mutex_unlock(&achip->conn_lock);
status = AE_NO_MEMORY;
- goto out;
+ break;
}
conn->pin = pin;
@@ -1176,8 +1174,6 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
list_add_tail(&conn->node, &achip->conns);
}
- mutex_unlock(&achip->conn_lock);
-
/*
* For the cases when OperationRegion() consists of more than
* 64 bits calculate the word and bit shift to use that one to
@@ -1196,8 +1192,6 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
}
}
-out:
- ACPI_FREE(ares);
return status;
}
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h
2026-05-06 12:34 ` [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h Marco Scardovi
@ 2026-05-06 12:49 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-05-06 12:49 UTC (permalink / raw)
To: Marco Scardovi
Cc: mika.westerberg, mathias.nyman, linux-gpio, linux-acpi,
linux-kernel, Marco Scardovi
On Wed, May 06, 2026 at 02:34:21PM +0200, Marco Scardovi wrote:
> thanks for the quick reply. Unfortunately I noticed too late that thunderbird had
> broken my patch during copy/paste. I'm pushing it again using git send-mail.
> I've divided tha patch in 3 smaller pieces: let me know if it is ok for you and
> Andy. In the meantime I'm testing it against KASAN and kmemleak as You suggested.
>
> Let me know if there's anything else I need to improve.
Slow down, please! The time between two versions should be at least 24h!
On top of that, Mika Cc'ed me with this and I only answered a few minutes ago,
meaning that not earlier than on Friday the next version should come. I'm not
going to review this. I believe most of my comments still apply. Also note,
that the email thread is a mess now, something went wrong. And do not forget
to remove placeholders when filing the contents of a cover letter.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/3] [PATCH 1/3] gpio: acpi: modernize resource management using cleanup.h
2026-05-06 12:35 ` [PATCH v2 1/3] [PATCH 1/3] " Marco Scardovi
@ 2026-05-06 12:51 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-05-06 12:51 UTC (permalink / raw)
To: Marco Scardovi
Cc: mika.westerberg, mathias.nyman, linux-gpio, linux-acpi,
linux-kernel
On Wed, May 06, 2026 at 02:35:34PM +0200, Marco Scardovi wrote:
No, this is wrong and completely missed the guidelines!
Please, spend near hours to study the Submitting Patches and Coding Style
kernel documentation before preparing and sending a v3.
...
> +#include <linux/cleanup.h>
> +#include <linux/slab.h>
> #include <linux/acpi.h>
> #include <linux/dmi.h>
> #include <linux/errno.h>
...
> +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);
> +})
And yes, these are still subject to comments I gave against v1.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-05-06 12:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260506113215.GK6785@://intel.com>
2026-05-06 12:34 ` [PATCH v2 0/3] gpio: acpi: modernize resource management using cleanup.h Marco Scardovi
2026-05-06 12:49 ` Andy Shevchenko
2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` Marco Scardovi
2026-05-06 12:35 ` [PATCH v2 1/3] [PATCH 1/3] " Marco Scardovi
2026-05-06 12:51 ` Andy Shevchenko
2026-05-06 12:35 ` [PATCH v2 2/3] [PATCH 2/3] " Marco Scardovi
2026-05-06 12:35 ` [PATCH v2 3/3] [PATCH 3/3] " Marco Scardovi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox