Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2196246/?format=api
{ "id": 2196246, "url": "http://patchwork.ozlabs.org/api/patches/2196246/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260213092958.864411-5-tzungbi@kernel.org/", "project": { "id": 42, "url": "http://patchwork.ozlabs.org/api/projects/42/?format=api", "name": "Linux GPIO development", "link_name": "linux-gpio", "list_id": "linux-gpio.vger.kernel.org", "list_email": "linux-gpio@vger.kernel.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260213092958.864411-5-tzungbi@kernel.org>", "list_archive_url": null, "date": "2026-02-13T09:29:51", "name": "[v3,04/11] gpio: Ensure struct gpio_chip for gpiochip_setup_dev()", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "31a57f7d9fdfbf2da9cdabe4afc08738a558fdf2", "submitter": { "id": 83557, "url": "http://patchwork.ozlabs.org/api/people/83557/?format=api", "name": "Tzung-Bi Shih", "email": "tzungbi@kernel.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-gpio/patch/20260213092958.864411-5-tzungbi@kernel.org/mbox/", "series": [ { "id": 492068, "url": "http://patchwork.ozlabs.org/api/series/492068/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-gpio/list/?series=492068", "date": "2026-02-13T09:29:47", "name": "gpio: Adopt revocable mechanism for UAF prevention", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/492068/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2196246/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2196246/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "\n <linux-gpio+bounces-31661-incoming=patchwork.ozlabs.org@vger.kernel.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "linux-gpio@vger.kernel.org" ], "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=KnUp4c4i;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-gpio+bounces-31661-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)", "smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"KnUp4c4i\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201" ], "Received": [ "from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fC6PR2gWxz1xvQ\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 13 Feb 2026 20:31:39 +1100 (AEDT)", "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id A750F302C156\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 13 Feb 2026 09:31:15 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 2B05E2D9EC5;\n\tFri, 13 Feb 2026 09:31:15 +0000 (UTC)", "from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id E00F432695F;\n\tFri, 13 Feb 2026 09:31:14 +0000 (UTC)", "by smtp.kernel.org (Postfix) with ESMTPSA id F388BC116C6;\n\tFri, 13 Feb 2026 09:31:11 +0000 (UTC)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1770975075; cv=none;\n b=XsIwDUYcO6kPNogT8/vprfUFeRgGH91JgzaA8tjZY1owJGJbhXNoTWn6YId3Xa+kDJT5QxB+A+5PEBygRkxEjTXW7+4oPYKvCI+GfI/8I8t8snguqt9seyZYoeHkeMAmLF1XIrt/rHUJP7EsL2SrOK2BfCrsJ37hMDT3gkuEFWc=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1770975075; c=relaxed/simple;\n\tbh=a0Nuy0UYMO/xZM1sfMO/NhXKrBeZbiAntWD51TL+aEo=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=goJK/X4CmxvUJs4mg6BhdSJWLsCh5UIUjpnnZVATGBccynLESyRbN1tVgQtpVaJwitYj+5EZUCF0v4dWSOvyNq95cS3Xi+4XolYJfbw+dy9smUc4BFqp+sryJ3IrVbuEVZJZjufKVCbrfzGkYxjullKJlr/99togWvc3PRQ8Y3Q=", "ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=KnUp4c4i; arc=none smtp.client-ip=10.30.226.201", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1770975074;\n\tbh=a0Nuy0UYMO/xZM1sfMO/NhXKrBeZbiAntWD51TL+aEo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KnUp4c4igH3L73SeFnlJHue+5d6oQX4YIFccDtCwThwzVbiuoGmNVpWCP++xvgp8c\n\t JN9UAfUcP95a0oEQ5e32iacV967RH6sawoW7qHfmylfXOizHVNRZ016E2Xyeq/qmzC\n\t NJA4OOMxZn3nJEAmDTlD/8Xmh7dlkaD7FGt8YFCFBdmr9KJ7JzJVV5wuKChmVGVIhz\n\t jwBCbLKLTH6PX4XK6NgpqB524QGAbsAQ7LA19p11lamvyE/8noVXXgEz+hOkdW+Hdz\n\t XqBxYxW1s4EJsYt6H9FMAK9DrkxgVNLR+3Z5QBaQiPx99Ef0E2H3ZzsV9Mr3N2KbrW\n\t 4fIfQr9yf4dKg==", "From": "Tzung-Bi Shih <tzungbi@kernel.org>", "To": "Bartosz Golaszewski <brgl@kernel.org>,\n\tLinus Walleij <linusw@kernel.org>", "Cc": "Greg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\t\"Rafael J. Wysocki\" <rafael@kernel.org>,\n\tDanilo Krummrich <dakr@kernel.org>,\n\tJonathan Corbet <corbet@lwn.net>,\n\tShuah Khan <shuah@kernel.org>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tWolfram Sang <wsa+renesas@sang-engineering.com>,\n\tJason Gunthorpe <jgg@nvidia.com>,\n\tJohan Hovold <johan@kernel.org>,\n\t\"Paul E . McKenney\" <paulmck@kernel.org>,\n\tDan Williams <dan.j.williams@intel.com>,\n\tchrome-platform@lists.linux.dev,\n\ttzungbi@kernel.org,\n\tlinux-gpio@vger.kernel.org,\n\tlinux-kselftest@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org", "Subject": "[PATCH v3 04/11] gpio: Ensure struct gpio_chip for\n gpiochip_setup_dev()", "Date": "Fri, 13 Feb 2026 09:29:51 +0000", "Message-ID": "<20260213092958.864411-5-tzungbi@kernel.org>", "X-Mailer": "git-send-email 2.53.0.310.g728cabbaf7-goog", "In-Reply-To": "<20260213092958.864411-1-tzungbi@kernel.org>", "References": "<20260213092958.864411-1-tzungbi@kernel.org>", "Precedence": "bulk", "X-Mailing-List": "linux-gpio@vger.kernel.org", "List-Id": "<linux-gpio.vger.kernel.org>", "List-Subscribe": "<mailto:linux-gpio+subscribe@vger.kernel.org>", "List-Unsubscribe": "<mailto:linux-gpio+unsubscribe@vger.kernel.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit" }, "content": "Ensure struct gpio_chip for gpiochip_setup_dev(). This eliminates a few\nchecks for struct gpio_chip.\n\nSigned-off-by: Tzung-Bi Shih <tzungbi@kernel.org>\n---\nv3:\n- Pass struct gpio_chip * only.\n\nv2: https://lore.kernel.org/all/20260203061059.975605-5-tzungbi@kernel.org\n- No changes.\n\nv1: https://lore.kernel.org/all/20260116081036.352286-10-tzungbi@kernel.org\n\n drivers/gpio/gpiolib-cdev.c | 12 ++----------\n drivers/gpio/gpiolib-cdev.h | 2 +-\n drivers/gpio/gpiolib-sysfs.c | 13 +++----------\n drivers/gpio/gpiolib-sysfs.h | 4 ++--\n drivers/gpio/gpiolib.c | 24 +++++++++++++++++-------\n 5 files changed, 25 insertions(+), 30 deletions(-)", "diff": "diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c\nindex 2adc3c070908..b028198adba8 100644\n--- a/drivers/gpio/gpiolib-cdev.c\n+++ b/drivers/gpio/gpiolib-cdev.c\n@@ -2782,9 +2782,9 @@ static const struct file_operations gpio_fileops = {\n #endif\n };\n \n-int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)\n+int gpiolib_cdev_register(struct gpio_chip *gc, dev_t devt)\n {\n-\tstruct gpio_chip *gc;\n+\tstruct gpio_device *gdev = gc->gpiodev;\n \tint ret;\n \n \tcdev_init(&gdev->chrdev, &gpio_fileops);\n@@ -2802,14 +2802,6 @@ int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)\n \t\treturn ret;\n \t}\n \n-\tguard(srcu)(&gdev->srcu);\n-\tgc = srcu_dereference(gdev->chip, &gdev->srcu);\n-\tif (!gc) {\n-\t\tcdev_device_del(&gdev->chrdev, &gdev->dev);\n-\t\tdestroy_workqueue(gdev->line_state_wq);\n-\t\treturn -ENODEV;\n-\t}\n-\n \tgpiochip_dbg(gc, \"added GPIO chardev (%d:%d)\\n\", MAJOR(devt), gdev->id);\n \n \treturn 0;\ndiff --git a/drivers/gpio/gpiolib-cdev.h b/drivers/gpio/gpiolib-cdev.h\nindex b42644cbffb8..4a9cb3335d99 100644\n--- a/drivers/gpio/gpiolib-cdev.h\n+++ b/drivers/gpio/gpiolib-cdev.h\n@@ -7,7 +7,7 @@\n \n struct gpio_device;\n \n-int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt);\n+int gpiolib_cdev_register(struct gpio_chip *gc, dev_t devt);\n void gpiolib_cdev_unregister(struct gpio_device *gdev);\n \n #endif /* GPIOLIB_CDEV_H */\ndiff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c\nindex 97e269f30945..3fdcfa0c7d42 100644\n--- a/drivers/gpio/gpiolib-sysfs.c\n+++ b/drivers/gpio/gpiolib-sysfs.c\n@@ -978,10 +978,10 @@ void gpiod_unexport(struct gpio_desc *desc)\n }\n EXPORT_SYMBOL_GPL(gpiod_unexport);\n \n-int gpiochip_sysfs_register(struct gpio_device *gdev)\n+int gpiochip_sysfs_register(struct gpio_chip *chip)\n {\n+\tstruct gpio_device *gdev = chip->gpiodev;\n \tstruct gpiodev_data *data;\n-\tstruct gpio_chip *chip;\n \tstruct device *parent;\n \tint err;\n \n@@ -994,12 +994,6 @@ int gpiochip_sysfs_register(struct gpio_device *gdev)\n \tif (!class_is_registered(&gpio_class))\n \t\treturn 0;\n \n-\tguard(srcu)(&gdev->srcu);\n-\n-\tchip = srcu_dereference(gdev->chip, &gdev->srcu);\n-\tif (!chip)\n-\t\treturn -ENODEV;\n-\n \t/*\n \t * For sysfs backward compatibility we need to preserve this\n \t * preferred parenting to the gpio_chip parent field, if set.\n@@ -1080,10 +1074,9 @@ void gpiochip_sysfs_unregister(struct gpio_chip *chip)\n */\n static int gpiofind_sysfs_register(struct gpio_chip *gc, const void *data)\n {\n-\tstruct gpio_device *gdev = gc->gpiodev;\n \tint ret;\n \n-\tret = gpiochip_sysfs_register(gdev);\n+\tret = gpiochip_sysfs_register(gc);\n \tif (ret)\n \t\tgpiochip_err(gc, \"failed to register the sysfs entry: %d\\n\", ret);\n \ndiff --git a/drivers/gpio/gpiolib-sysfs.h b/drivers/gpio/gpiolib-sysfs.h\nindex 9ee2f9dd268f..aacc8e6454a4 100644\n--- a/drivers/gpio/gpiolib-sysfs.h\n+++ b/drivers/gpio/gpiolib-sysfs.h\n@@ -7,12 +7,12 @@ struct gpio_device;\n \n #ifdef CONFIG_GPIO_SYSFS\n \n-int gpiochip_sysfs_register(struct gpio_device *gdev);\n+int gpiochip_sysfs_register(struct gpio_chip *chip);\n void gpiochip_sysfs_unregister(struct gpio_chip *chip);\n \n #else\n \n-static inline int gpiochip_sysfs_register(struct gpio_device *gdev)\n+static inline int gpiochip_sysfs_register(struct gpio_chip *chip)\n {\n \treturn 0;\n }\ndiff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c\nindex 3ff57b1e51bf..74ee7bfb974c 100644\n--- a/drivers/gpio/gpiolib.c\n+++ b/drivers/gpio/gpiolib.c\n@@ -882,14 +882,14 @@ static const struct device_type gpio_dev_type = {\n };\n \n #ifdef CONFIG_GPIO_CDEV\n-#define gcdev_register(gdev, devt)\tgpiolib_cdev_register((gdev), (devt))\n+#define gcdev_register(gc, devt)\tgpiolib_cdev_register((gc), (devt))\n #define gcdev_unregister(gdev)\t\tgpiolib_cdev_unregister((gdev))\n #else\n /*\n * gpiolib_cdev_register() indirectly calls device_add(), which is still\n * required even when cdev is not selected.\n */\n-#define gcdev_register(gdev, devt)\tdevice_add(&(gdev)->dev)\n+#define gcdev_register(gc, devt)\tdevice_add(&(gc)->gpiodev->dev)\n #define gcdev_unregister(gdev)\t\tdevice_del(&(gdev)->dev)\n #endif\n \n@@ -897,8 +897,9 @@ static const struct device_type gpio_dev_type = {\n * An initial reference count has been held in gpiochip_add_data_with_key().\n * The caller should drop the reference via gpio_device_put() on errors.\n */\n-static int gpiochip_setup_dev(struct gpio_device *gdev)\n+static int gpiochip_setup_dev(struct gpio_chip *gc)\n {\n+\tstruct gpio_device *gdev = gc->gpiodev;\n \tstruct fwnode_handle *fwnode = dev_fwnode(&gdev->dev);\n \tint ret;\n \n@@ -911,11 +912,11 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)\n \tif (fwnode && !fwnode->dev)\n \t\tfwnode_dev_initialized(fwnode, false);\n \n-\tret = gcdev_register(gdev, gpio_devt);\n+\tret = gcdev_register(gc, gpio_devt);\n \tif (ret)\n \t\treturn ret;\n \n-\tret = gpiochip_sysfs_register(gdev);\n+\tret = gpiochip_sysfs_register(gc);\n \tif (ret)\n \t\tgoto err_remove_device;\n \n@@ -962,13 +963,22 @@ static void machine_gpiochip_add(struct gpio_chip *gc)\n static void gpiochip_setup_devs(void)\n {\n \tstruct gpio_device *gdev;\n+\tstruct gpio_chip *gc;\n \tint ret;\n \n \tguard(srcu)(&gpio_devices_srcu);\n \n \tlist_for_each_entry_srcu(gdev, &gpio_devices, list,\n \t\t\t\t srcu_read_lock_held(&gpio_devices_srcu)) {\n-\t\tret = gpiochip_setup_dev(gdev);\n+\t\tguard(srcu)(&gdev->srcu);\n+\n+\t\tgc = srcu_dereference(gdev->chip, &gdev->srcu);\n+\t\tif (!gc) {\n+\t\t\tdev_err(&gdev->dev, \"Underlying GPIO chip is gone\\n\");\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tret = gpiochip_setup_dev(gc);\n \t\tif (ret) {\n \t\t\tgpio_device_put(gdev);\n \t\t\tdev_err(&gdev->dev,\n@@ -1226,7 +1236,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,\n \t * (i.e., `gpio_bus_type` is ready). Otherwise, defer until later.\n \t */\n \tif (gpiolib_initialized) {\n-\t\tret = gpiochip_setup_dev(gdev);\n+\t\tret = gpiochip_setup_dev(gc);\n \t\tif (ret)\n \t\t\tgoto err_teardown_shared;\n \t}\n", "prefixes": [ "v3", "04/11" ] }