Re: [PATCH v4 12/13] gpiolib: add new ioctl() for monitoring changes in line info

Andy Shevchenko
2020-01-08T12:46:53Z

On Tue, Dec 24, 2019 at 01:07:08PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Currently there is no way for user-space to be informed about changes
> in status of GPIO lines e.g. when someone else requests the line or its
> config changes. We can only periodically re-read the line-info. This
> is fine for simple one-off user-space tools, but any daemon that provides
> a centralized access to GPIO chips would benefit hugely from an event
> driven line info synchronization.
>
> This patch adds a new ioctl() that allows user-space processes to reuse
> the file descriptor associated with the character device for watching
> any changes in line properties. Every such event contains the updated
> line information.
>
> Currently the events are generated on three types of status changes: when
> a line is requested, when it's released and when its config is changed.
> The first two are self-explanatory. For the third one: this will only
> happen when another user-space process calls the new SET_CONFIG ioctl()
> as any changes that can happen from within the kernel (i.e.
> set_transitory() or set_debounce()) are of no interest to user-space.

...

> - } else if (cmd == GPIO_GET_LINEINFO_IOCTL) {
> + } else if (cmd == GPIO_GET_LINEINFO_IOCTL ||
> + cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) {

What about to split the functionality to something like lineinfo_get() and...

> struct gpioline_info lineinfo;

> - struct gpio_desc *desc;

Hmm... Is it correct patch for this change?

>
> if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
> return -EFAULT;
> @@ -1246,11 +1260,25 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>
> if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))
> return -EFAULT;
> +
> + if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL)
> + set_bit(desc_to_gpio(desc), priv->watched_lines);
> +

...simple use

} else if (cmd == GPIO_GET_LINEINFO_IOCTL) {
return lineinfo_get();
} else if {cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) {
ret = lineinfo_get()
set_bit();
return ret;
}

?

> return 0;

--
With Best Regards,
Andy Shevchenko