drm/mediatek: fix race condition for HDMI jack status reporting
authorTzung-Bi Shih <tzungbi@google.com>
Mon, 17 Feb 2020 03:16:53 +0000 (11:16 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 17 Feb 2020 17:39:13 +0000 (17:39 +0000)
commitf07980d4ed60fbb35857b655c94b111f4ddf2abf
treee347800766e82f56eff798f1e6951ba27d2bcea4
parent2f0b42034bd75a938cdf144149d6db4fa4d51208
drm/mediatek: fix race condition for HDMI jack status reporting

hdmi_conn_detect and mtk_hdmi_audio_hook_plugged_cb would be called
by different threads.

Imaging the following calling sequence:
           Thread A                            Thread B
--------------------------------------------------------------------
mtk_hdmi_audio_hook_plugged_cb()
mtk_cec_hpd_high() -> disconnected
                                     hdmi_conn_detect()
                                     mtk_cec_hpd_high() -> connected
                                     plugged_cb(connected)
plugged_cb(disconnected)

The latest disconnected is false reported.  Makes mtk_cec_hpd_high
and plugged_cb atomic to fix.

Also uses the same lock to protect read/write of plugged_cb and codec_dev.

Fixes: 5d3c64477392 ("drm/mediatek: support HDMI jack status reporting")
Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
Acked-by: CK Hu <ck.hu@mediatek.com>
Link: https://lore.kernel.org/r/20200217105513.2.I477092c2f104fd589133436c3ae4590e6fc6323b@changeid
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/gpu/drm/mediatek/mtk_hdmi.c