lkml.org 
[lkml]   [2026]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 1/3] [PATCH 1/3] gpio: acpi: modernize resource management using cleanup.h
Date
---
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

\
 
 \ /
  Last update: 2026-05-06 14:42    [W:0.122 / U:14.842 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog