* [PATCH RESEND] drm/mediatek/dp: fix spurious kfree()
@ 2024-06-04 8:33 Michael Walle
2024-06-28 13:08 ` Chun-Kuang Hu
0 siblings, 1 reply; 2+ messages in thread
From: Michael Walle @ 2024-06-04 8:33 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Jani Nikula, Chen-Yu Tsai, linux-mediatek, linux-kernel,
linux-arm-kernel, Michael Walle
drm_edid_to_sad() might return an error or just zero. If that is the
case, we must not free the SADs because there was no allocation in
the first place.
Fixes: dab12fa8d2bd ("drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection")
Signed-off-by: Michael Walle <mwalle@kernel.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
---
drivers/gpu/drm/mediatek/mtk_dp.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index 536366956447..ada12927bbac 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -2073,9 +2073,15 @@ static const struct drm_edid *mtk_dp_edid_read(struct drm_bridge *bridge,
*/
const struct edid *edid = drm_edid_raw(drm_edid);
struct cea_sad *sads;
+ int ret;
- audio_caps->sad_count = drm_edid_to_sad(edid, &sads);
- kfree(sads);
+ ret = drm_edid_to_sad(edid, &sads);
+ /* Ignore any errors */
+ if (ret < 0)
+ ret = 0;
+ if (ret)
+ kfree(sads);
+ audio_caps->sad_count = ret;
/*
* FIXME: This should use connector->display_info.has_audio from
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND] drm/mediatek/dp: fix spurious kfree()
2024-06-04 8:33 [PATCH RESEND] drm/mediatek/dp: fix spurious kfree() Michael Walle
@ 2024-06-28 13:08 ` Chun-Kuang Hu
0 siblings, 0 replies; 2+ messages in thread
From: Chun-Kuang Hu @ 2024-06-28 13:08 UTC (permalink / raw)
To: Michael Walle
Cc: Chun-Kuang Hu, Philipp Zabel, David Airlie, Daniel Vetter,
Matthias Brugger, AngeloGioacchino Del Regno, Jani Nikula,
Chen-Yu Tsai, linux-mediatek, linux-kernel, linux-arm-kernel
Hi, Michael:
Michael Walle <mwalle@kernel.org> 於 2024年6月4日 週二 下午4:33寫道:
>
> drm_edid_to_sad() might return an error or just zero. If that is the
> case, we must not free the SADs because there was no allocation in
> the first place.
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
>
> Fixes: dab12fa8d2bd ("drm/mediatek/dp: fix memory leak on ->get_edid callback audio detection")
> Signed-off-by: Michael Walle <mwalle@kernel.org>
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> ---
> drivers/gpu/drm/mediatek/mtk_dp.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index 536366956447..ada12927bbac 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -2073,9 +2073,15 @@ static const struct drm_edid *mtk_dp_edid_read(struct drm_bridge *bridge,
> */
> const struct edid *edid = drm_edid_raw(drm_edid);
> struct cea_sad *sads;
> + int ret;
>
> - audio_caps->sad_count = drm_edid_to_sad(edid, &sads);
> - kfree(sads);
> + ret = drm_edid_to_sad(edid, &sads);
> + /* Ignore any errors */
> + if (ret < 0)
> + ret = 0;
> + if (ret)
> + kfree(sads);
> + audio_caps->sad_count = ret;
>
> /*
> * FIXME: This should use connector->display_info.has_audio from
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-28 13:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 8:33 [PATCH RESEND] drm/mediatek/dp: fix spurious kfree() Michael Walle
2024-06-28 13:08 ` Chun-Kuang Hu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®