Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Marco Scardovi <mscardovi95@gmail.com>
To: mika.westerberg@intel.com
Cc: mathias.nyman@intel.com, andriy.shevchenko@intel.com,
	linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Marco Scardovi <mscardovi95@gmail.com>
Subject: [PATCH v2 1/3] [PATCH 1/3] gpio: acpi: modernize resource management using cleanup.h
Date: Wed,  6 May 2026 14:35:34 +0200	[thread overview]
Message-ID: <20260506123637.1077421-3-mscardovi95@gmail.com> (raw)
In-Reply-To: <20260506123637.1077421-1-mscardovi95@gmail.com>

---
 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


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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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   ` Marco Scardovi [this message]
2026-05-06 12:51     ` [PATCH v2 1/3] [PATCH 1/3] " 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

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=20260506123637.1077421-3-mscardovi95@gmail.com \
    --to=mscardovi95@gmail.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=mika.westerberg@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