media: cec-pin.c: disabling the adapter cannot call kthread_stop
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Fri, 6 May 2022 07:15:40 +0000 (09:15 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 13 May 2022 09:27:19 +0000 (11:27 +0200)
commit60965c6a1960988bcb5ad3b530ccd133af5cc85d
tree7a508d0238bc08a9537eecc79da4ad04d58c511e
parentdb264d4c66c0fe007b5d19fd007707cd0697603d
media: cec-pin.c: disabling the adapter cannot call kthread_stop

When the adap_enable callback is called the adap->lock is held.
When disabling the adapter it attempts to stop the kthread that
deals with receiving and transmitting messages. However, kthread_stop
waits for the thread to stop, so all that time adap->lock is held.

Unfortunately, the kernel thread itself can call functions that take
that same lock, so a deadlock can occur.

Change the logic to keep the kernel thread running and instead when
disabling the adapter, just set the pin to high, go to idle and then
to state OFF and disable the interrupt. Only stop the kernel thread
when the adapter is deleted.

This way disabling the adapter will not wait for anything and the
deadlock is avoided.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/cec/core/cec-pin.c