[PATCH AUTOSEL 4.9 17/48] media: cec-core: first mark device unregistered, then wake up fhs

From: Sasha Levin
Date: Tue Dec 22 2020 - 21:33:33 EST


From: Hans Verkuil <hverkuil-cisco@xxxxxxxxx>

[ Upstream commit e91c255733d9bbb4978a372f44fb5ed689ccdbd1 ]

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@xxxxxxxxx>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/staging/media/cec/cec-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/cec/cec-core.c b/drivers/staging/media/cec/cec-core.c
index b0137e247dc9a..bb189f753c3ac 100644
--- a/drivers/staging/media/cec/cec-core.c
+++ b/drivers/staging/media/cec/cec-core.c
@@ -183,12 +183,12 @@ static void cec_devnode_unregister(struct cec_devnode *devnode)
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);

device_del(&devnode->dev);
--
2.27.0