public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: CK Hu <ck.hu@mediatek.com>
To: Tzung-Bi Shih <tzungbi@google.com>
Cc: alsa-devel@alsa-project.org, p.zabel@pengutronix.de,
	airlied@linux.ie, dri-devel@lists.freedesktop.org,
	broonie@kernel.org, linux-mediatek@lists.infradead.org,
	daniel@ffwll.ch, matthias.bgg@gmail.com, dgreid@google.com,
	linux-arm-kernel@lists.infradead.org, cychiang@google.com
Subject: Re: [PATCH v2 2/2] drm/mediatek: fix race condition for HDMI jack status reporting
Date: Mon, 17 Feb 2020 11:44:18 +0800	[thread overview]
Message-ID: <1581911058.12629.1.camel@mtksdaap41> (raw)
In-Reply-To: <20200217105513.2.I477092c2f104fd589133436c3ae4590e6fc6323b@changeid>

Hi, Tzhung-Bi:

On Mon, 2020-02-17 at 11:16 +0800, Tzung-Bi Shih wrote:
> 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")

This patch looks good to me, but please merge this patch with the patch
it fix.

Regards,
CK

> Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_hdmi.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c
> index 03aeb73005ef..d80017e3d84a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
> @@ -12,6 +12,7 @@
>  #include <linux/io.h>
>  #include <linux/kernel.h>
>  #include <linux/mfd/syscon.h>
> +#include <linux/mutex.h>
>  #include <linux/of_platform.h>
>  #include <linux/of.h>
>  #include <linux/of_gpio.h>
> @@ -171,6 +172,7 @@ struct mtk_hdmi {
>  	bool enabled;
>  	hdmi_codec_plugged_cb plugged_cb;
>  	struct device *codec_dev;
> +	struct mutex update_plugged_status_lock;
>  };
>  
>  static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b)
> @@ -1199,10 +1201,13 @@ static void mtk_hdmi_clk_disable_audio(struct mtk_hdmi *hdmi)
>  static enum drm_connector_status
>  mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi)
>  {
> -	bool connected = mtk_cec_hpd_high(hdmi->cec_dev);
> +	bool connected;
>  
> +	mutex_lock(&hdmi->update_plugged_status_lock);
> +	connected = mtk_cec_hpd_high(hdmi->cec_dev);
>  	if (hdmi->plugged_cb && hdmi->codec_dev)
>  		hdmi->plugged_cb(hdmi->codec_dev, connected);
> +	mutex_unlock(&hdmi->update_plugged_status_lock);
>  
>  	return connected ?
>  	       connector_status_connected : connector_status_disconnected;
> @@ -1669,8 +1674,11 @@ static int mtk_hdmi_audio_hook_plugged_cb(struct device *dev, void *data,
>  {
>  	struct mtk_hdmi *hdmi = data;
>  
> +	mutex_lock(&hdmi->update_plugged_status_lock);
>  	hdmi->plugged_cb = fn;
>  	hdmi->codec_dev = codec_dev;
> +	mutex_unlock(&hdmi->update_plugged_status_lock);
> +
>  	mtk_hdmi_update_plugged_status(hdmi);
>  
>  	return 0;
> @@ -1729,6 +1737,7 @@ static int mtk_drm_hdmi_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	mutex_init(&hdmi->update_plugged_status_lock);
>  	platform_set_drvdata(pdev, hdmi);
>  
>  	ret = mtk_hdmi_output_init(hdmi);

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-02-17  3:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-17  3:16 [PATCH v2 0/2] ASoC hdmi-codec: fix HDMI jack reporting Tzung-Bi Shih
2020-02-17  3:16 ` [PATCH v2 1/2] ASoC: hdmi-codec: set plugged_cb to NULL when component removing Tzung-Bi Shih
2020-02-17 22:04   ` Applied "ASoC: hdmi-codec: set plugged_cb to NULL when component removing" to the asoc tree Mark Brown
2020-02-17  3:16 ` [PATCH v2 2/2] drm/mediatek: fix race condition for HDMI jack status reporting Tzung-Bi Shih
2020-02-17  3:44   ` CK Hu [this message]
2020-02-17  3:55     ` Tzung-Bi Shih
2020-02-17  4:49       ` CK Hu
2020-02-17 22:03   ` Applied "drm/mediatek: fix race condition for HDMI jack status reporting" to the asoc tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1581911058.12629.1.camel@mtksdaap41 \
    --to=ck.hu@mediatek.com \
    --cc=airlied@linux.ie \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cychiang@google.com \
    --cc=daniel@ffwll.ch \
    --cc=dgreid@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=tzungbi@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox