lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260116081036.352286-18-tzungbi@kernel.org>
Date: Fri, 16 Jan 2026 08:10:30 +0000
From: Tzung-Bi Shih <tzungbi@...nel.org>
To: Benson Leung <bleung@...omium.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	"Rafael J . Wysocki" <rafael@...nel.org>,
	Danilo Krummrich <dakr@...nel.org>,
	Bartosz Golaszewski <brgl@...ev.pl>,
	Linus Walleij <linusw@...nel.org>
Cc: Jonathan Corbet <corbet@....net>,
	Shuah Khan <shuah@...nel.org>,
	linux-doc@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	chrome-platform@...ts.linux.dev,
	linux-kselftest@...r.kernel.org,
	tzungbi@...nel.org,
	Laurent Pinchart <laurent.pinchart@...asonboard.com>,
	Wolfram Sang <wsa+renesas@...g-engineering.com>,
	Simona Vetter <simona.vetter@...ll.ch>,
	Dan Williams <dan.j.williams@...el.com>,
	Jason Gunthorpe <jgg@...dia.com>,
	linux-gpio@...r.kernel.org
Subject: [PATCH 17/23] gpiolib: cdev: Leverage revocable for lineinfo_changed_notify

Struct gpio_device now provides a revocable provider to the underlying
struct gpio_chip.  Leverage revocable for lineinfo_changed_notify so
that it doesn't need to handle the synchronization by accessing the SRCU
explicitly.

Signed-off-by: Tzung-Bi Shih <tzungbi@...nel.org>
---
 drivers/gpio/gpiolib-cdev.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 54150d718931..1a4dde56dc0c 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -2522,6 +2522,7 @@ struct lineinfo_changed_ctx {
 	struct gpio_v2_line_info_changed chg;
 	struct gpio_device *gdev;
 	struct gpio_chardev_data *cdev;
+	struct revocable *chip_rev;
 };
 
 static void lineinfo_changed_func(struct work_struct *work)
@@ -2538,12 +2539,9 @@ static void lineinfo_changed_func(struct work_struct *work)
 		 * Pin functions are in general much more static and while it's
 		 * not 100% bullet-proof, it's good enough for most cases.
 		 */
-		scoped_guard(srcu, &ctx->gdev->srcu) {
-			gc = srcu_dereference(ctx->gdev->chip, &ctx->gdev->srcu);
-			if (gc &&
-			    !pinctrl_gpio_can_use_line(gc, ctx->chg.info.offset))
-				ctx->chg.info.flags |= GPIO_V2_LINE_FLAG_USED;
-		}
+		REVOCABLE_TRY_ACCESS_WITH(ctx->chip_rev, gc);
+		if (gc && !pinctrl_gpio_can_use_line(gc, ctx->chg.info.offset))
+			ctx->chg.info.flags |= GPIO_V2_LINE_FLAG_USED;
 	}
 
 	ret = kfifo_in_spinlocked(&ctx->cdev->events, &ctx->chg, 1,
@@ -2553,6 +2551,7 @@ static void lineinfo_changed_func(struct work_struct *work)
 	else
 		pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n");
 
+	revocable_free(ctx->chip_rev);
 	gpio_device_put(ctx->gdev);
 	fput(ctx->cdev->fp);
 	kfree(ctx);
@@ -2599,11 +2598,19 @@ static int lineinfo_changed_notify(struct notifier_block *nb,
 	/* Keep the GPIO device alive until we emit the event. */
 	ctx->gdev = gpio_device_get(desc->gdev);
 	ctx->cdev = cdev;
+	ctx->chip_rev = revocable_alloc(desc->gdev->chip_rp);
+	if (!ctx->chip_rev) {
+		pr_err("Failed to allocate memory for revocable handle\n");
+		goto err_put_device;
+	}
 
 	INIT_WORK(&ctx->work, lineinfo_changed_func);
 	queue_work(ctx->gdev->line_state_wq, &ctx->work);
 
 	return NOTIFY_OK;
+err_put_device:
+	gpio_device_put(desc->gdev);
+	kfree(ctx);
 err_put_fp:
 	fput(fp);
 	return NOTIFY_DONE;
-- 
2.52.0.457.g6b5491de43-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ