From nobody Mon Feb 9 14:31:49 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0D372F5A27; Fri, 16 Jan 2026 08:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768551113; cv=none; b=VaK09bAi8ZzK8hwNA5ahamhwFUvz4OhqtJ9fZYbJrDBnZJrH6EJ8YIJsvTYa5Nzr7+Hwx1NbZUrOivRcQz4EW1uiLhGFUrav1bS9ojRqcy9yQz5C4zwhdmvgZXGELyhsVQGVIE5oRGiC9F8wLaAyu1Imdj7ukgYrzJjSrIphTSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768551113; c=relaxed/simple; bh=vsSvq8AguO7TYYELrmF0WwiB1WEaAYbIowbsd3ctUKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KUqKbnOC10PH1ni6eEh29uA88uW+oE4IjCJFdAhVLvUMpGl7Hsk+V+Updr8RAUoecmaLrmP5z/Af/LMD0AZNN0l/gRB+Q1FOoKT4/c0MBOLmiBVH9BeyvDhF0Zb3eYw2i1/gcPMYKC36MoR0MqbvJ+tv1gWQ8fQ1RCrP6ELJ9Dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sFCRuAMA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sFCRuAMA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56EFEC116C6; Fri, 16 Jan 2026 08:11:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768551113; bh=vsSvq8AguO7TYYELrmF0WwiB1WEaAYbIowbsd3ctUKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sFCRuAMAmXyNlDMSxgF5Vmx5Hw8eoG7f0iNw0kqJpA9hySctghyaFbhiviINZJTuM wXDFvoZEXCrqHf/BnZnm1iCMzPVMAgiwhGvArXcShjC3MsIdaYGL3i+SFPuj4FbNLt 5MVEQW2BtpBS5eDdf9YnVBQrlLXdzYPDpI2tTzVjKAoCuOP70+9naiWeBOOOJCeYRB xzzVb9UMKfH5MpnpfeO63uw+Xrd/pvuDE701GhcNEEsIqSU4YeIxFT0B9r9VA2IfAY W8qosJg+paNa/vw2BJjuT6lzN/eqMBgFQOApCBi33fPxZycodPLEiEFRqigkqOsXw5 qHpDq5yFNpRXA== From: Tzung-Bi Shih To: Benson Leung , Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Bartosz Golaszewski , Linus Walleij Cc: Jonathan Corbet , Shuah Khan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, linux-kselftest@vger.kernel.org, tzungbi@kernel.org, Laurent Pinchart , Wolfram Sang , Simona Vetter , Dan Williams , Jason Gunthorpe , linux-gpio@vger.kernel.org Subject: [PATCH 15/23] gpiolib: cdev: Leverage revocable for line_fileops Date: Fri, 16 Jan 2026 08:10:28 +0000 Message-ID: <20260116081036.352286-16-tzungbi@kernel.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog In-Reply-To: <20260116081036.352286-1-tzungbi@kernel.org> References: <20260116081036.352286-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Struct gpio_device now provides a revocable provider to the underlying struct gpio_chip. Leverage revocable for line_fileops so that it doesn't need to handle the synchronization by accessing the SRCU explicitly. Also, it's unneeded to hold a reference count to the struct gpio_device while the file is opening. The struct gpio_device (i.e., (struct gpio_chip *)->gpiodev)) is valid as long as struct gpio_chip is valid. Signed-off-by: Tzung-Bi Shih --- drivers/gpio/gpiolib-cdev.c | 53 +++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index f7c6f1367235..f078d135a581 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -488,7 +488,7 @@ struct line { =20 /** * struct linereq - contains the state of a userspace line request - * @gdev: the GPIO device the line request pertains to + * @chip_rev: revocable consumer handle for the corresponding struct gpio_= chip * @label: consumer label used to tag GPIO descriptors * @num_lines: the number of lines in the lines array * @wait: wait queue that handles blocking reads of events @@ -503,7 +503,7 @@ struct line { * @lines: the lines held by this line request, with @num_lines elements. */ struct linereq { - struct gpio_device *gdev; + struct revocable *chip_rev; const char *label; u32 num_lines; wait_queue_head_t wait; @@ -1437,10 +1437,10 @@ static long linereq_ioctl(struct file *file, unsign= ed int cmd, { struct linereq *lr =3D file->private_data; void __user *ip =3D (void __user *)arg; + struct gpio_chip *gc; =20 - guard(srcu)(&lr->gdev->srcu); - - if (!rcu_access_pointer(lr->gdev->chip)) + REVOCABLE_TRY_ACCESS_WITH(lr->chip_rev, gc); + if (!gc) return -ENODEV; =20 switch (cmd) { @@ -1468,10 +1468,10 @@ static __poll_t linereq_poll(struct file *file, { struct linereq *lr =3D file->private_data; __poll_t events =3D 0; + struct gpio_chip *gc; =20 - guard(srcu)(&lr->gdev->srcu); - - if (!rcu_access_pointer(lr->gdev->chip)) + REVOCABLE_TRY_ACCESS_WITH(lr->chip_rev, gc); + if (!gc) return EPOLLHUP | EPOLLERR; =20 poll_wait(file, &lr->wait, wait); @@ -1490,10 +1490,10 @@ static ssize_t linereq_read(struct file *file, char= __user *buf, struct gpio_v2_line_event le; ssize_t bytes_read =3D 0; int ret; + struct gpio_chip *gc; =20 - guard(srcu)(&lr->gdev->srcu); - - if (!rcu_access_pointer(lr->gdev->chip)) + REVOCABLE_TRY_ACCESS_WITH(lr->chip_rev, gc); + if (!gc) return -ENODEV; =20 if (count < sizeof(le)) @@ -1537,9 +1537,17 @@ static void linereq_free(struct linereq *lr) { unsigned int i; =20 - if (lr->device_unregistered_nb.notifier_call) - blocking_notifier_chain_unregister(&lr->gdev->device_notifier, - &lr->device_unregistered_nb); + if (lr->device_unregistered_nb.notifier_call) { + struct gpio_chip *gc; + + REVOCABLE_TRY_ACCESS_WITH(lr->chip_rev, gc); + if (gc) { + struct gpio_device *gdev =3D gc->gpiodev; + + blocking_notifier_chain_unregister(&gdev->device_notifier, + &lr->device_unregistered_nb); + } + } =20 for (i =3D 0; i < lr->num_lines; i++) { if (lr->lines[i].desc) { @@ -1549,7 +1557,8 @@ static void linereq_free(struct linereq *lr) } kfifo_free(&lr->events); kfree(lr->label); - gpio_device_put(lr->gdev); + if (lr->chip_rev) + revocable_free(lr->chip_rev); kvfree(lr); } =20 @@ -1565,9 +1574,15 @@ static int linereq_release(struct inode *inode, stru= ct file *file) static void linereq_show_fdinfo(struct seq_file *out, struct file *file) { struct linereq *lr =3D file->private_data; - struct device *dev =3D &lr->gdev->dev; + struct gpio_chip *gc; + struct device *dev; u16 i; =20 + REVOCABLE_TRY_ACCESS_WITH(lr->chip_rev, gc); + if (!gc) + return; + dev =3D &gc->gpiodev->dev; + seq_printf(out, "gpio-chip:\t%s\n", dev_name(dev)); =20 for (i =3D 0; i < lr->num_lines; i++) @@ -1620,7 +1635,11 @@ static int linereq_create(struct gpio_device *gdev, = void __user *ip) return -ENOMEM; lr->num_lines =3D ulr.num_lines; =20 - lr->gdev =3D gpio_device_get(gdev); + lr->chip_rev =3D revocable_alloc(gdev->chip_rp); + if (!lr->chip_rev) { + ret =3D -ENOMEM; + goto out_free_linereq; + } =20 for (i =3D 0; i < ulr.num_lines; i++) { lr->lines[i].req =3D lr; --=20 2.52.0.457.g6b5491de43-goog