diff mbox series

cec-core: first mark device unregistered, then wake up fhs

Message ID 77df9930-f50a-be6d-0d12-04e44cc350b0@xs4all.nl
State New
Headers show
Series cec-core: first mark device unregistered, then wake up fhs | expand

Commit Message

Hans Verkuil Oct. 9, 2020, 9:16 a.m. UTC
If a CEC device node is unregistered, then it should be marked as
unregistered before waking up any filehandles that are waiting for
an event.

This ensures that there is no race condition where an application can
call CEC_DQEVENT and have the ioctl return 0 instead of ENODEV.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
diff mbox series

Patch

diff --git a/drivers/media/cec/core/cec-core.c b/drivers/media/cec/core/cec-core.c
index ece236291f35..551689d371a7 100644
--- a/drivers/media/cec/core/cec-core.c
+++ b/drivers/media/cec/core/cec-core.c
@@ -166,12 +166,12 @@  static void cec_devnode_unregister(struct cec_adapter *adap)
 		mutex_unlock(&devnode->lock);
 		return;
 	}
+	devnode->registered = false;
+	devnode->unregistered = true;

 	list_for_each_entry(fh, &devnode->fhs, list)
 		wake_up_interruptible(&fh->wait);

-	devnode->registered = false;
-	devnode->unregistered = true;
 	mutex_unlock(&devnode->lock);

 	mutex_lock(&adap->lock);