2023-09-14 19:47:41

by Jani Nikula

[permalink] [raw]
Subject: [PATCH] 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: CK Hu <[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]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: <[email protected]> # v6.1+
Signed-off-by: Jani Nikula <[email protected]>

---

UNTESTED
---
drivers/gpu/drm/mediatek/mtk_dp.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index 2cb47f663756..8fc6eff68e30 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -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


2023-09-14 23:25:46

by Jani Nikula

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

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]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: <[email protected]> # v6.1+
Signed-off-by: Jani Nikula <[email protected]>

---

Found another one. UNTESTED.
---
drivers/gpu/drm/mediatek/mtk_dp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index 8fc6eff68e30..0e285df6577e 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -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);
}

--
2.39.2

2023-09-15 08:31:53

by Chen-Yu Tsai

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

On Thu, Sep 14, 2023 at 11:53 PM Jani Nikula <[email protected]> wrote:
>
> 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]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: <[email protected]> # v6.1+
> Signed-off-by: Jani Nikula <[email protected]>

Looks correct to me.

Reviewed-by: Chen-Yu Tsai <[email protected]>

2023-09-19 14:50:18

by Chen-Yu Tsai

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

On Tue, Sep 19, 2023 at 7:02 PM Jani Nikula <[email protected]> wrote:
>
> On Fri, 15 Sep 2023, Chen-Yu Tsai <[email protected]> wrote:
> > On Thu, Sep 14, 2023 at 11:53 PM Jani Nikula <[email protected]> wrote:
> >>
> >> 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]
> >> Cc: [email protected]
> >> Cc: [email protected]
> >> Cc: [email protected]
> >> Cc: <[email protected]> # v6.1+
> >> Signed-off-by: Jani Nikula <[email protected]>
> >
> > Looks correct to me.
> >
> > Reviewed-by: Chen-Yu Tsai <[email protected]>
>
> 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

2023-09-19 17:23:04

by Jani Nikula

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

On Fri, 15 Sep 2023, Chen-Yu Tsai <[email protected]> wrote:
> On Thu, Sep 14, 2023 at 11:53 PM Jani Nikula <[email protected]> wrote:
>>
>> 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]
>> Cc: [email protected]
>> Cc: [email protected]
>> Cc: [email protected]
>> Cc: <[email protected]> # v6.1+
>> Signed-off-by: Jani Nikula <[email protected]>
>
> Looks correct to me.
>
> Reviewed-by: Chen-Yu Tsai <[email protected]>

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

BR,
Jani.


--
Jani Nikula, Intel

2023-09-22 09:56:01

by Jani Nikula

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

On Tue, 19 Sep 2023, Chen-Yu Tsai <[email protected]> wrote:
> On Tue, Sep 19, 2023 at 7:02 PM Jani Nikula <[email protected]> wrote:
>>
>> On Fri, 15 Sep 2023, Chen-Yu Tsai <[email protected]> wrote:
>> > On Thu, Sep 14, 2023 at 11:53 PM Jani Nikula <[email protected]> wrote:
>> >>
>> >> 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]
>> >> Cc: [email protected]
>> >> Cc: [email protected]
>> >> Cc: [email protected]
>> >> Cc: <[email protected]> # v6.1+
>> >> Signed-off-by: Jani Nikula <[email protected]>
>> >
>> > Looks correct to me.
>> >
>> > Reviewed-by: Chen-Yu Tsai <[email protected]>
>>
>> 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.

>
> ChenYu

--
Jani Nikula, Intel

2023-09-24 14:27:38

by Chun-Kuang Hu

[permalink] [raw]
Subject: 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寫道:
>
> On Tue, 19 Sep 2023, Chen-Yu Tsai <[email protected]> wrote:
> > On Tue, Sep 19, 2023 at 7:02 PM Jani Nikula <[email protected]> wrote:
> >>
> >> On Fri, 15 Sep 2023, Chen-Yu Tsai <[email protected]> wrote:
> >> > On Thu, Sep 14, 2023 at 11:53 PM Jani Nikula <[email protected]> wrote:
> >> >>
> >> >> 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]
> >> >> Cc: [email protected]
> >> >> Cc: [email protected]
> >> >> Cc: [email protected]
> >> >> Cc: <[email protected]> # v6.1+
> >> >> Signed-off-by: Jani Nikula <[email protected]>
> >> >
> >> > Looks correct to me.
> >> >
> >> > Reviewed-by: Chen-Yu Tsai <[email protected]>
> >>
> >> 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.

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.

>
> Thanks,
> Jani.
>
> >
> > ChenYu
>
> --
> Jani Nikula, Intel

2023-09-24 14:41:52

by Chun-Kuang Hu

[permalink] [raw]
Subject: Re: [PATCH] drm/mediatek/dp: fix memory leak on ->get_edid callback error path

Hi, Jani:

Jani Nikula <[email protected]> 於 2023年9月14日 週四 下午9:13寫道:
>
> 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.

>
> 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: CK Hu <[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]
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Cc: <[email protected]> # v6.1+
> Signed-off-by: Jani Nikula <[email protected]>
>
> ---
>
> UNTESTED
> ---
> drivers/gpu/drm/mediatek/mtk_dp.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 2cb47f663756..8fc6eff68e30 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -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
>