From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796331398; b=ZurpCMS+6r1fWY0C8iZx4BY6Nh0HsMAag0/dKxJE6CNf1X3B67z8prDx0j2RgrxjisCL 1gEeuT9qoYF9rEOgm8sgZQYLCosBcAl6gtlXgxQZOl/okskXTv5DRUxASOtSZeKMaX1EM MR31G7nebO+8Jk4+jx9/v7k9cghod/9TpzT2UmReScNq0NFc+JwpSWq5q4kAkD2G9rIzJ T6pAd1RANSLib8TbyUtGDMSe/GXBgn+3BHfw/R+UdoKCLbpjco68HzLRa14WB2xkX4hDL jLBFKUj4hqCiqiszRqmk3vpK0xye07Z1a+0LsQVwD4Y1XTcDQj3RVeKGjSgsfeXAQgw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331398; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=e9QScd1kZQmbRfQSz/UPfmjRuf/+TntCLvF/KFT/GOI=; b=x7h49whSe6qJjP6G721epbqEibehrUBdpivMmcErWbJeEEWI64PQwEs84539AHsb8VR+ 8x22DBqCTvkSVrS/T9cypoRDOzOXzJRy8B9kTXW1DqHxve3UodBEo2mSz8ZSb8rRNJzoF WXDL7obBC0tEW0EM3asXyVq25mAlFq5/dDj2ubLEiOpfeO8fv4VEtZIsCHOafxv1KuDVA Q0TEyHuGANABKA0canhXQYNUiUwad/MJSAYX4OOJLX7A0OkFFzfdLWF7iXV6Sl6cqoPdR lh4uc3fUb2GO4K2GcKvZR7guFX0fcTuUKbjtbPL1GJVvkVMUgzdH+sMDGG8iWuTZozA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WjADTS3O; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9487C606A322; Thu, 3 Dec 2026 20:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WjADTS3O Received: by smtp.kernel.org (Postfix) with ESMTPSA id C49C01F000C2; Thu, 3 Dec 2026 20:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796331398; bh=e9QScd1kZQmbRfQSz/UPfmjRuf/+TntCLvF/KFT/GOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WjADTS3OA6pzBOsDIPPGUc+1Tct3cpzGjD2ONIwxXX/AVnSfpTg3nvceTAOGEPg7H 8EzmuNXb0/JSU0DEFIoJeWYvaJ9E0v3gME5CWArhkOtZWHaQYp8ZiHkSY/iuEG/R3B 2T4WogDunVB+Gz8oLwHRPtZqogVGfUfns1mlJ0pSRDluCU9ubSmwInlIBIpU/OSa8d mDgCDgBHVMD7qr+CuWR1VnaEFAFLgXB7DRpAvWASVEyx4sIARgice47tEMGxRoB+ZQ KZ1qbQKNTuu8Y4pvF7xwW9ia7FXh71QmyOKrIfy8f6aNhuAmpK9/OTkHY26UxKHqws uTM2tgGVGUPHw== From: Lee Jones To: lee@kernel.org, Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Mathias Nyman , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Date: Thu, 3 Dec 2026 20:55:00 +0000 Message-ID: <20261203205606.3905705-3-lee@kernel.org> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261203205606.3905705-1-lee@kernel.org> References: <20261203205606.3905705-1-lee@kernel.org> X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit acpi_dev_gpio_irq_wake_get_by() obtains a descriptor from __acpi_find_gpio() without holding gpio_devices_srcu or acquiring a reference to desc->gdev. Because acpi_get_gpiod() releases its gpio_device reference before returning, a concurrent GPIO controller unbind can free gdev and gdev->descs before gpiod_to_irq() and the subsequent descriptor configuration helpers run. Expose gpio_devices_srcu internally within gpiolib, guard the __acpi_find_gpio() lookup with gpio_devices_srcu, and acquire a scoped gpio_device reference via gpio_device_get() before leaving the SRCU read-side critical section. Fixes: e348544f7994 ("gpio: protect the list of GPIO devices with SRCU") Closes: https://sashiko.dev/#/bug/linux-97d822c4-1532-47ad-ab8d-717448607bc1 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- drivers/gpio/gpiolib-acpi-core.c | 9 +++++++-- drivers/gpio/gpiolib.c | 2 +- drivers/gpio/gpiolib.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c index f94f456dbe5f..fccb4fe71e80 100644 --- a/drivers/gpio/gpiolib-acpi-core.c +++ b/drivers/gpio/gpiolib-acpi-core.c @@ -1027,10 +1027,15 @@ int acpi_dev_gpio_irq_wake_get_by(struct acpi_device *adev, const char *con_id, for (i = 0, idx = 0; idx <= index; i++) { struct acpi_gpio_info info = {}; + struct gpio_device *gdev __free(gpio_device_put) = NULL; struct gpio_desc *desc; - /* Ignore -EPROBE_DEFER, it only matters if idx matches */ - desc = __acpi_find_gpio(fwnode, con_id, i, true, &info); + scoped_guard(srcu, &gpio_devices_srcu) { + /* Ignore -EPROBE_DEFER, it only matters if idx matches */ + desc = __acpi_find_gpio(fwnode, con_id, i, true, &info); + if (!IS_ERR(desc)) + gdev = gpio_device_get(desc->gdev); + } if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER) return PTR_ERR(desc); diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 22c9288fea10..8843b2175caf 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -102,7 +102,7 @@ static LIST_HEAD(gpio_devices); /* Protects the GPIO device list against concurrent modifications. */ static DEFINE_MUTEX(gpio_devices_lock); /* Ensures coherence during read-only accesses to the list of GPIO devices. */ -DEFINE_STATIC_SRCU(gpio_devices_srcu); +DEFINE_SRCU(gpio_devices_srcu); const char *const gpio_suffixes[] = { "gpios", "gpio", NULL }; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 8dd8ea747f8a..c4a390231086 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -283,6 +283,8 @@ int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev); struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); const char *gpiod_get_label(struct gpio_desc *desc); +extern struct srcu_struct gpio_devices_srcu; + /* With descriptor prefix */ #define __gpiod_pr(level, desc, fmt, ...) \ -- 2.56.1.911.g883d8bcb20-goog