[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230816122032.15548-2-brgl@bgdev.pl>
Date: Wed, 16 Aug 2023 14:20:28 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Linus Walleij <linus.walleij@...aro.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Kent Gibson <warthog618@...il.com>
Cc: linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: [PATCH 1/5] gpio: cdev: ignore notifications other than line status changes
From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
In preparation for extending the role of the GPIO device's blocking
notifier, make sure the callback used by the character device's file
descriptor data checks the action argument and only reacts to one of the
line state change values. Also: relax the kerneldoc describing the
notifier as it will have more responsibilities soon.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
---
drivers/gpio/gpiolib-cdev.c | 35 +++++++++++++++++++++++------------
drivers/gpio/gpiolib.h | 3 +--
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 0a33971c964c..062521e1a9e0 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -2502,22 +2502,33 @@ static int lineinfo_changed_notify(struct notifier_block *nb,
{
struct gpio_chardev_data *cdev = to_gpio_chardev_data(nb);
struct gpio_v2_line_info_changed chg;
- struct gpio_desc *desc = data;
+ struct gpio_desc *desc;
int ret;
- if (!test_bit(gpio_chip_hwgpio(desc), cdev->watched_lines))
- return NOTIFY_DONE;
+ switch (action) {
+ case GPIO_V2_LINE_CHANGED_REQUESTED:
+ case GPIO_V2_LINE_CHANGED_RELEASED:
+ case GPIO_V2_LINE_CHANGED_CONFIG:
+ desc = data;
- memset(&chg, 0, sizeof(chg));
- chg.event_type = action;
- chg.timestamp_ns = ktime_get_ns();
- gpio_desc_to_lineinfo(desc, &chg.info);
+ if (!test_bit(gpio_chip_hwgpio(desc), cdev->watched_lines))
+ return NOTIFY_DONE;
- ret = kfifo_in_spinlocked(&cdev->events, &chg, 1, &cdev->wait.lock);
- if (ret)
- wake_up_poll(&cdev->wait, EPOLLIN);
- else
- pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n");
+ memset(&chg, 0, sizeof(chg));
+ chg.event_type = action;
+ chg.timestamp_ns = ktime_get_ns();
+ gpio_desc_to_lineinfo(desc, &chg.info);
+
+ ret = kfifo_in_spinlocked(&cdev->events, &chg, 1,
+ &cdev->wait.lock);
+ if (ret)
+ wake_up_poll(&cdev->wait, EPOLLIN);
+ else
+ pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n");
+ break;
+ default:
+ return NOTIFY_DONE;
+ }
return NOTIFY_OK;
}
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index cca81375f127..de7b3b60f7ca 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -38,8 +38,7 @@
* or name of the IP component in a System on Chip.
* @data: per-instance data assigned by the driver
* @list: links gpio_device:s together for traversal
- * @notifier: used to notify subscribers about lines being requested, released
- * or reconfigured
+ * @notifier: used to notify subscribers about gpio_device events
* @sem: protects the structure from a NULL-pointer dereference of @chip by
* user-space operations when the device gets unregistered during
* a hot-unplug event
--
2.39.2
Powered by blists - more mailing lists