Skip to content

Commit 91043f5

Browse files
author
Bartosz Golaszewski
committed
gpio: cdev: wake up lineevent poll() on device unbind
Add a notifier block to the lineevent_state structure and register it with the gpio_device's device notifier. Upon reception of an event, wake up the wait queue so that the user-space be forced out of poll() and need to go into a new system call which will then fail due to the chip being gone. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Kent Gibson <[email protected]>
1 parent a0dda50 commit 91043f5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
18021802
* @eflags: the event flags this line was requested with
18031803
* @irq: the interrupt that trigger in response to events on this GPIO
18041804
* @wait: wait queue that handles blocking reads of events
1805+
* @device_unregistered_nb: notifier block for receiving gdev unregister events
18051806
* @events: KFIFO for the GPIO events
18061807
* @timestamp: cache for the timestamp storing it between hardirq
18071808
* and IRQ thread, used to bring the timestamp close to the actual
@@ -1814,6 +1815,7 @@ struct lineevent_state {
18141815
u32 eflags;
18151816
int irq;
18161817
wait_queue_head_t wait;
1818+
struct notifier_block device_unregistered_nb;
18171819
DECLARE_KFIFO(events, struct gpioevent_data, 16);
18181820
u64 timestamp;
18191821
};
@@ -1847,6 +1849,17 @@ static __poll_t lineevent_poll(struct file *file,
18471849
return call_poll_locked(file, wait, le->gdev, lineevent_poll_unlocked);
18481850
}
18491851

1852+
static int lineevent_unregistered_notify(struct notifier_block *nb,
1853+
unsigned long action, void *data)
1854+
{
1855+
struct lineevent_state *le = container_of(nb, struct lineevent_state,
1856+
device_unregistered_nb);
1857+
1858+
wake_up_poll(&le->wait, EPOLLIN | EPOLLERR);
1859+
1860+
return NOTIFY_OK;
1861+
}
1862+
18501863
struct compat_gpioeevent_data {
18511864
compat_u64 timestamp;
18521865
u32 id;
@@ -1932,6 +1945,9 @@ static ssize_t lineevent_read(struct file *file, char __user *buf,
19321945

19331946
static void lineevent_free(struct lineevent_state *le)
19341947
{
1948+
if (le->device_unregistered_nb.notifier_call)
1949+
blocking_notifier_chain_unregister(&le->gdev->device_notifier,
1950+
&le->device_unregistered_nb);
19351951
if (le->irq)
19361952
free_irq(le->irq, le);
19371953
if (le->desc)
@@ -2160,6 +2176,12 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
21602176
INIT_KFIFO(le->events);
21612177
init_waitqueue_head(&le->wait);
21622178

2179+
le->device_unregistered_nb.notifier_call = lineevent_unregistered_notify;
2180+
ret = blocking_notifier_chain_register(&gdev->device_notifier,
2181+
&le->device_unregistered_nb);
2182+
if (ret)
2183+
goto out_free_le;
2184+
21632185
/* Request a thread to read the events */
21642186
ret = request_threaded_irq(irq,
21652187
lineevent_irq_handler,

0 commit comments

Comments
 (0)