* [PATCH v2] gpiolib: cdev: add fdinfo output for line request file descriptors
@ 2022-09-22 9:51 Bartosz Golaszewski
2022-09-22 10:31 ` Kent Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Bartosz Golaszewski @ 2022-09-22 9:51 UTC (permalink / raw)
To: Kent Gibson, Linus Walleij, Andy Shevchenko
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
Add fdinfo output for file descriptors created for user-space line
requests in GPIO uAPI v2. The fdinfo file now contains the name of the
GPIO chip that is the "parent" of the request as well as offsets of
the lines requested. This allows user-space to parse the /proc/$PID/fdinfo
entries and deduce the PID of the process that requested a specific line.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
v1 -> v2:
- change `gpio-device` to `gpio-chip` in the fdinfo output
- change deduct into deduce as suggested by Kent in the commit message
drivers/gpio/gpiolib-cdev.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index f8041d4898d1..01c15e9e6896 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -1497,6 +1497,21 @@ static int linereq_release(struct inode *inode, struct file *file)
return 0;
}
+#ifdef CONFIG_PROC_FS
+static void linereq_show_fdinfo(struct seq_file *out, struct file *file)
+{
+ struct linereq *lr = file->private_data;
+ struct device *dev = &lr->gdev->dev;
+ u16 i;
+
+ seq_printf(out, "gpio-chip:\t%s\n", dev_name(dev));
+
+ for (i = 0; i < lr->num_lines; i++)
+ seq_printf(out, "gpio-line:\t%d\n",
+ gpio_chip_hwgpio(lr->lines[i].desc));
+}
+#endif
+
static const struct file_operations line_fileops = {
.release = linereq_release,
.read = linereq_read,
@@ -1507,6 +1522,9 @@ static const struct file_operations line_fileops = {
#ifdef CONFIG_COMPAT
.compat_ioctl = linereq_ioctl_compat,
#endif
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = linereq_show_fdinfo,
+#endif
};
static int linereq_create(struct gpio_device *gdev, void __user *ip)
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] gpiolib: cdev: add fdinfo output for line request file descriptors
2022-09-22 9:51 [PATCH v2] gpiolib: cdev: add fdinfo output for line request file descriptors Bartosz Golaszewski
@ 2022-09-22 10:31 ` Kent Gibson
0 siblings, 0 replies; 2+ messages in thread
From: Kent Gibson @ 2022-09-22 10:31 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Andy Shevchenko, linux-gpio, linux-kernel
On Thu, Sep 22, 2022 at 11:51:24AM +0200, Bartosz Golaszewski wrote:
> Add fdinfo output for file descriptors created for user-space line
> requests in GPIO uAPI v2. The fdinfo file now contains the name of the
> GPIO chip that is the "parent" of the request as well as offsets of
> the lines requested. This allows user-space to parse the /proc/$PID/fdinfo
> entries and deduce the PID of the process that requested a specific line.
>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
> v1 -> v2:
> - change `gpio-device` to `gpio-chip` in the fdinfo output
> - change deduct into deduce as suggested by Kent in the commit message
>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
> drivers/gpio/gpiolib-cdev.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
> index f8041d4898d1..01c15e9e6896 100644
> --- a/drivers/gpio/gpiolib-cdev.c
> +++ b/drivers/gpio/gpiolib-cdev.c
> @@ -1497,6 +1497,21 @@ static int linereq_release(struct inode *inode, struct file *file)
> return 0;
> }
>
> +#ifdef CONFIG_PROC_FS
> +static void linereq_show_fdinfo(struct seq_file *out, struct file *file)
> +{
> + struct linereq *lr = file->private_data;
> + struct device *dev = &lr->gdev->dev;
> + u16 i;
> +
> + seq_printf(out, "gpio-chip:\t%s\n", dev_name(dev));
> +
> + for (i = 0; i < lr->num_lines; i++)
> + seq_printf(out, "gpio-line:\t%d\n",
> + gpio_chip_hwgpio(lr->lines[i].desc));
> +}
> +#endif
> +
> static const struct file_operations line_fileops = {
> .release = linereq_release,
> .read = linereq_read,
> @@ -1507,6 +1522,9 @@ static const struct file_operations line_fileops = {
> #ifdef CONFIG_COMPAT
> .compat_ioctl = linereq_ioctl_compat,
> #endif
> +#ifdef CONFIG_PROC_FS
> + .show_fdinfo = linereq_show_fdinfo,
> +#endif
> };
>
> static int linereq_create(struct gpio_device *gdev, void __user *ip)
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-22 10:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-22 9:51 [PATCH v2] gpiolib: cdev: add fdinfo output for line request file descriptors Bartosz Golaszewski
2022-09-22 10:31 ` Kent Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox