Skip to content

Commit a0dda50

Browse files
author
Bartosz Golaszewski
committed
gpio: cdev: wake up linereq poll() on device unbind
Add a notifier block to the linereq 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 d2e2586 commit a0dda50

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ struct line {
555555
* @label: consumer label used to tag GPIO descriptors
556556
* @num_lines: the number of lines in the lines array
557557
* @wait: wait queue that handles blocking reads of events
558+
* @device_unregistered_nb: notifier block for receiving gdev unregister events
558559
* @event_buffer_size: the number of elements allocated in @events
559560
* @events: KFIFO for the GPIO events
560561
* @seqno: the sequence number for edge events generated on all lines in
@@ -569,6 +570,7 @@ struct linereq {
569570
const char *label;
570571
u32 num_lines;
571572
wait_queue_head_t wait;
573+
struct notifier_block device_unregistered_nb;
572574
u32 event_buffer_size;
573575
DECLARE_KFIFO_PTR(events, struct gpio_v2_line_event);
574576
atomic_t seqno;
@@ -610,6 +612,17 @@ struct linereq {
610612
GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE | \
611613
GPIO_V2_LINE_EDGE_FLAGS)
612614

615+
static int linereq_unregistered_notify(struct notifier_block *nb,
616+
unsigned long action, void *data)
617+
{
618+
struct linereq *lr = container_of(nb, struct linereq,
619+
device_unregistered_nb);
620+
621+
wake_up_poll(&lr->wait, EPOLLIN | EPOLLERR);
622+
623+
return NOTIFY_OK;
624+
}
625+
613626
static void linereq_put_event(struct linereq *lr,
614627
struct gpio_v2_line_event *le)
615628
{
@@ -1567,6 +1580,10 @@ static void linereq_free(struct linereq *lr)
15671580
{
15681581
unsigned int i;
15691582

1583+
if (lr->device_unregistered_nb.notifier_call)
1584+
blocking_notifier_chain_unregister(&lr->gdev->device_notifier,
1585+
&lr->device_unregistered_nb);
1586+
15701587
for (i = 0; i < lr->num_lines; i++) {
15711588
if (lr->lines[i].desc) {
15721589
edge_detector_stop(&lr->lines[i]);
@@ -1727,6 +1744,12 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
17271744
offset);
17281745
}
17291746

1747+
lr->device_unregistered_nb.notifier_call = linereq_unregistered_notify;
1748+
ret = blocking_notifier_chain_register(&gdev->device_notifier,
1749+
&lr->device_unregistered_nb);
1750+
if (ret)
1751+
goto out_free_linereq;
1752+
17301753
fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
17311754
if (fd < 0) {
17321755
ret = fd;

0 commit comments

Comments
 (0)