• Hans Verkuil's avatar
    [media] cec: fix race between configuring and unconfiguring · f60f3560
    Hans Verkuil authored
    This race was discovered by running cec-compliance -A with the cec module debug
    parameter set to 2: suddenly the test would fail.
    
    It turns out that this happens when the test configures the adapter in
    non-blocking mode, then it waits for the CEC_EVENT_STATE_CHANGE event and once
    the event is received it unconfigures the adapter.
    
    What happened was that the unconfigure was executed while the configure was
    still transmitting the Report Features and Report Physical Address messages.
    This messed up the internal state of the cec_adapter.
    
    The fix is to transmit those messages with the adap->lock mutex held (this will
    just queue them up in the internal transmit queue, and not actually transmit
    anything yet). Only unlock the mutex once everything is done. The main thread
    will dequeue the messages from the internal transmit queue and transmit them
    one by one, unless an unconfigure was done, and in that case any messages are
    just dropped.
    Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
    f60f3560
cec-adap.c 54.1 KB