ASoC hdmi-codec: fix HDMI jack reporting
Subsystems (5)
v2 cover ASoC hdmi-codec: fix HDMI jack reporting
With proper unbinding audio components and inserting the HDMI external display, kernel crashes as the following messages:
Unable to handle kernel NULL pointer dereference at virtual address ... [snip] Call trace: plugged_cb+0x1c/0x74 mtk_hdmi_update_plugged_status+0x48/0x6c hdmi_conn_detect+0x1c/0x28 drm_helper_probe_detect+0x110/0x170 drm_helper_probe_single_connector_modes+0xd4/0x608 drm_mode_getconnector+0x1e8/0x418
The 1st patch fixes the crash by notifying hdmi-codec's consumers to not report jack status anymore when component removing.
The 2nd patch fixes race condition in mediatek/mtk_hdmi.c.
Changes from v1:
(https://patchwork.kernel.org/patch/11379979/)
- added the 1st patch
- use mutex to protect plugged_cb and codec_dev in 2nd patch
Tzung-Bi Shih (2):
ASoC: hdmi-codec: set plugged_cb to NULL when component removing drm/mediatek: fix race condition for HDMI jack status reporting
drivers/gpu/drm/mediatek/mtk_hdmi.c | 11 ++++++++++- sound/soc/codecs/hdmi-codec.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
Signature · 7 lines
2.25.0.265.gbab2e86ba0-goog _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/2 ASoC: hdmi-codec: set plugged_cb to NULL when component removing
Sets plugged_cb to NULL when component removing to notify its consumers : no further plugged status report is required.
--- sound/soc/codecs/hdmi-codec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/soc/codecs/hdmi-codec.c +10 -0
@@ -779,7 +779,17 @@ static int hdmi_of_xlate_dai_id(struct snd_soc_component *component,return ret; } +static void hdmi_remove (struct snd_soc_component *component) +{ +struct hdmi_codec_priv *hcp =snd_soc_component_get_drvdata (component); + +if (hcp->hcd.ops->hook_plugged_cb) + hcp->hcd.ops->hook_plugged_cb (component->dev->parent, + hcp->hcd.data,NULL ,NULL ); +} +static const struct snd_soc_component_driver hdmi_driver = { + .remove = hdmi_remove, .dapm_widgets = hdmi_widgets, .num_dapm_widgets =ARRAY_SIZE (hdmi_widgets), .of_xlate_dai_id = hdmi_of_xlate_dai_id,
Signature · 7 lines
2.25.0.265.gbab2e86ba0-goog _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/2 drm/mediatek: fix race condition for HDMI jack status reporting
In reply to Tzung-Bi Shihhdmi_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.
--- drivers/gpu/drm/mediatek/mtk_hdmi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +10 -1
@@ -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);
Signature · 7 lines
2.25.0.265.gbab2e86ba0-goog _______________________________________________ Linux-mediatek mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-mediatek
Re: [alsa-devel] [PATCH v2 2/2] drm/mediatek: fix race condition for HDMI jack status reporting
Hi, Tzhung-Bi:
Quoted 11 lines · Tzung-Bi Shih
hdmi_conn_detectandmtk_hdmi_audio_hook_plugged_cbwould be called by different threads.Imaging the following calling sequence:
Thread A Thread B
--------------------------------------------------------------------mtk_hdmi_audio_hook_plugged_cb()mtk_cec_hpd_high()-> disconnectedhdmi_conn_detect() mtk_cec_hpd_high() -> connected plugged_cb(connected)
Quoted 8 lines
plugged_cb(disconnected)The latest disconnected is false reported. Makes
mtk_cec_hpd_highandplugged_cbatomic to fix.Also uses the same lock to protect read/write of
plugged_cbandcodec_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
Quoted 53 lines
Signed-off-by Tzung-Bi Shih <[email protected]>--- drivers/gpu/drm/mediatek/mtk_hdmi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_hdmi.c +9
-1@@ -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 ;
drivers/gpu/drm/mediatek/mtk_hdmi.c static int mtk_drm_hdmi_probe(struct platform_device *pdev) · line 1743
Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_hdmi.c +1
-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);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [alsa-devel] [PATCH v2 2/2] drm/mediatek: fix race condition for HDMI jack status reporting
Quoted 5 lines · CK Hu
Quoted 1 line · Tzung-Bi Shih
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.
5d3c64477392 ("drm/mediatek: support HDMI jack status reporting") has applied to ASoC for-next branch. This is a fixup patch.
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
CK Hu
Acked-byRe: [alsa-devel] [PATCH v2 2/2] drm/mediatek: fix race condition for HDMI jack status reporting
Quoted 9 lines · Tzung-Bi Shih
Quoted 5 lines · CK Hu
Quoted 1 line · Tzung-Bi Shih
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.
5d3c64477392("drm/mediatek: support HDMI jack status reporting") has applied to ASoC for-next branch. This is a fixup patch.
I thought a patch need an ack by the maintainer. OK, so I could do is, for this patch,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerApplied "drm/mediatek: fix race condition for HDMI jack status reporting" to the asoc tree
In reply to Tzung-Bi ShihThe patch
drm/mediatek: fix race condition for HDMI jack status reporting
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From f07980d4ed60fbb35857b655c94b111f4ddf2abf Mon Sep 17 00:00:00 2001
From: Tzung-Bi Shih <[email protected]>
Date: Mon, 17 Feb 2020 11:16:53 +0800
Subject: [PATCH] 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.
--- drivers/gpu/drm/mediatek/mtk_hdmi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +10 -1
@@ -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);
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerApplied "ASoC: hdmi-codec: set plugged_cb to NULL when component removing" to the asoc tree
In reply to Tzung-Bi ShihThe patch
ASoC: hdmi-codec: set plugged_cb to NULL when component removing
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
From 4aadf4b49ec7d80c5db842ca28479d07108c9484 Mon Sep 17 00:00:00 2001
From: Tzung-Bi Shih <[email protected]>
Date: Mon, 17 Feb 2020 11:16:52 +0800
Subject: [PATCH] ASoC: hdmi-codec: set plugged_cb to NULL when component
removing
Sets plugged_cb to NULL when component removing to notify its consumers : no further plugged status report is required.
--- sound/soc/codecs/hdmi-codec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
sound/soc/codecs/hdmi-codec.c +10 -0
@@ -779,7 +779,17 @@ static int hdmi_of_xlate_dai_id(struct snd_soc_component *component,return ret; } +static void hdmi_remove (struct snd_soc_component *component) +{ +struct hdmi_codec_priv *hcp =snd_soc_component_get_drvdata (component); + +if (hcp->hcd.ops->hook_plugged_cb) + hcp->hcd.ops->hook_plugged_cb (component->dev->parent, + hcp->hcd.data,NULL ,NULL ); +} +static const struct snd_soc_component_driver hdmi_driver = { + .remove = hdmi_remove, .dapm_widgets = hdmi_widgets, .num_dapm_widgets =ARRAY_SIZE (hdmi_widgets), .of_xlate_dai_id = hdmi_of_xlate_dai_id,
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel