Skip to contentSkip to conversation

drm/mediatek/dp: fix memory leak on ->get_edid callback error path

PATCH Applied Jani Nikula 4 participants 9 messages Sep 14, 2023 – Sep 24, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/mediatek/dp: fix memory leak on ->get_edid callback error path

Setting new_edid to NULL leaks the buffer.

Fixes f70ac097a2cf ("drm/mediatek: Add MT8195 Embedded DisplayPort driver")
Cc Markus Schneider-Pargmann <[email protected]>
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+

---

UNTESTED

---
 drivers/gpu/drm/mediatek/mtk_dp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/mediatek/mtk_dp.c +1 -0
index 2cb47f663756..8fc6eff68e30 100644
@@ -2049,6 +2049,7 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,
 	 */
 	if (mtk_dp_parse_capabilities(mtk_dp)) {
 		drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n");
+		kfree(new_edid);
 		new_edid = NULL;
 	}
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Jani Nikula

Setting new_edid to NULL leaks the buffer.

Fixes f70ac097a2cf ("drm/mediatek: Add MT8195 Embedded DisplayPort driver")
Cc Markus Schneider-Pargmann <[email protected]>
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+
Quoted 22 lines

---

UNTESTED
---
drivers/gpu/drm/mediatek/mtk_dp.c | 1 +

1 file changed, 1 insertion(+)
drivers/gpu/drm/mediatek/mtk_dp.c +1 -1
index 2cb47f663756..8fc6eff68e30 100644
@@ -2049,6 +2049,7 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,
 	 */
 	if (mtk_dp_parse_capabilities(mtk_dp)) {
 		drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n");
+		kfree(new_edid);
 		new_edid = NULL;
 	}
 
--

2.39.2

#2 lore raw

PATCH 1/1 drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection

In reply to Jani Nikula

The sads returned by drm_edid_to_sad() needs to be freed.

Fixes e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195")
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+

---

Found another one. UNTESTED.

---
 drivers/gpu/drm/mediatek/mtk_dp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_dp.c +4 -1
index 8fc6eff68e30..0e285df6577e 100644
@@ -2034,7 +2034,6 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,
 	bool enabled = mtk_dp->enabled;
 	struct edid *new_edid = NULL;
 	struct mtk_dp_audio_cfg *audio_caps = &mtk_dp->info.audio_cur_cfg;
-	struct cea_sad *sads;
 
 	if (!enabled) {
 		drm_atomic_bridge_chain_pre_enable(bridge, connector->state->state);
@@ -2054,7 +2053,11 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,
 	}
 
 	if (new_edid) {
+		struct cea_sad *sads;
+
 		audio_caps->sad_count = drm_edid_to_sad(new_edid, &sads);
+		kfree(sads);
+
 		audio_caps->detect_monitor = drm_detect_monitor_audio(new_edid);
 	}
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#3 lore raw

Re: [PATCH] drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection

Quoted 17 lines · Jani Nikula

The sads returned by drm_edid_to_sad() needs to be freed.

Fixes e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195")
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+

Looks correct to me.

#4 lore raw

Re: [PATCH] drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection

Quoted 19 lines · Chen-Yu Tsai
Quoted 17 lines · Jani Nikula

The sads returned by drm_edid_to_sad() needs to be freed.

Fixes e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195")
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+
Quoted 3 lines

Looks correct to me.

Thanks for the reviews Chen-Yu and Guillaume. Will you push this to drm-misc-next or shall I?

BR,
Jani.

Signature · 1 line
Jani Nikula, Intel
#5 lore raw

Re: [PATCH] drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection

Quoted 21 lines · Jani Nikula
Quoted 19 lines · Chen-Yu Tsai
Quoted 17 lines · Jani Nikula

The sads returned by drm_edid_to_sad() needs to be freed.

Fixes e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195")
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+
Quoted 6 lines
Quoted 3 lines

Looks correct to me.

Thanks for the reviews Chen-Yu and Guillaume. Will you push this to drm-misc-next or shall I?

Patches for the MediaTek drm driver go through their own separate tree, maintained by CK (Chun-Kuang).

ChenYu

#6 lore raw

Re: [PATCH] drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection

Quoted 24 lines · Chen-Yu Tsai
Quoted 23 lines · Jani Nikula
Quoted 21 lines · Chen-Yu Tsai
Quoted 17 lines · Jani Nikula

The sads returned by drm_edid_to_sad() needs to be freed.

Fixes e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195")
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+

Looks correct to me.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks for the reviews Chen-Yu and Guillaume. Will you push this to drm-misc-next or shall I?

Patches for the MediaTek drm driver go through their own separate tree, maintained by CK (Chun-Kuang).

Chun-Kuang, can you confirm picking up these two patches, please?

MAINTAINERS does not list a separate git repository for MediaTek drm drivers, so I don't know where that would be. It should probably be added to MAINTAINERS.

Thanks,
Jani.

Quoted 2 lines

ChenYu

Signature · 1 line
Jani Nikula, Intel
maintainer Applied
#7 lore raw

Re: [PATCH] drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection

Hi, Jani:

Jani Nikula <[email protected]> 於 2023年9月22日 週五 下午5:44寫道:

Quoted 31 lines · Chen-Yu Tsai
Quoted 29 lines · Jani Nikula
Quoted 27 lines · Chen-Yu Tsai
Quoted 19 lines · Jani Nikula
Quoted 17 lines

The sads returned by drm_edid_to_sad() needs to be freed.

Fixes e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195")
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+
Quoted 3 lines

Looks correct to me.

Thanks for the reviews Chen-Yu and Guillaume. Will you push this to drm-misc-next or shall I?

Quoted 8 lines
Quoted 2 lines

Patches for the MediaTek drm driver go through their own separate tree, maintained by CK (Chun-Kuang).

Chun-Kuang, can you confirm picking up these two patches, please?

MAINTAINERS does not list a separate git repository for MediaTek drm drivers, so I don't know where that would be. It should probably be added to MAINTAINERS.

Applied to mediatek-drm-next [1], thanks.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next

Regards,
Chun-Kuang.

Quoted 9 lines

Thanks,
Jani.

Quoted 2 lines

ChenYu

--
Jani Nikula, Intel

maintainer Applied
#8 lore raw
In reply to Jani Nikula

Hi, Jani:

Jani Nikula <[email protected]> 於 2023年9月14日 週四 下午9:13寫道:

Quoted 2 lines

Setting new_edid to NULL leaks the buffer.

Applied to mediatek-drm-next [1], thanks.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next

Regards,
Chun-Kuang.

Quoted 40 lines
Fixes f70ac097a2cf ("drm/mediatek: Add MT8195 Embedded DisplayPort driver")
Cc Markus Schneider-Pargmann <[email protected]>
Cc Guillaume Ranquet <[email protected]>
Cc Bo-Chen Chen <[email protected]>
Cc AngeloGioacchino Del Regno <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Chun-Kuang Hu <[email protected]>
Cc Philipp Zabel <[email protected]>
Cc Matthias Brugger <[email protected]>
Cc <[email protected]> # v6.1+

---

UNTESTED

---
 drivers/gpu/drm/mediatek/mtk_dp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/mediatek/mtk_dp.c +1 -1
index 2cb47f663756..8fc6eff68e30 100644
@@ -2049,6 +2049,7 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge,
         */
        if (mtk_dp_parse_capabilities(mtk_dp)) {
                drm_err(mtk_dp->drm_dev, "Can't parse capabilities\n");
+               kfree(new_edid);
                new_edid = NULL;
        }
 
--

2.39.2