All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: Michael Walle <mwalle@kernel.org>,
	Chun-Kuang Hu <chunkuang.hu@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>
Cc: Chen-Yu Tsai <wenst@chromium.org>,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Michael Walle <mwalle@kernel.org>
Subject: Re: [PATCH] drm/mediatek/dp: fix spurious kfree()
Date: Fri, 17 May 2024 16:12:25 +0300	[thread overview]
Message-ID: <87v83ca8g6.fsf@intel.com> (raw)
In-Reply-To: <20240517093024.1702750-1-mwalle@kernel.org>

On Fri, 17 May 2024, Michael Walle <mwalle@kernel.org> wrote:
> 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>
> ---
>  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;

I suppose I would've just initialized sads = NULL; and be done with it.

But *shrug*.

Reviewed-by: Jani Nikula <jani.nikula@intel.com>


> +		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

-- 
Jani Nikula, Intel


WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@intel.com>
To: Michael Walle <mwalle@kernel.org>,
	Chun-Kuang Hu <chunkuang.hu@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>
Cc: Chen-Yu Tsai <wenst@chromium.org>,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Michael Walle <mwalle@kernel.org>
Subject: Re: [PATCH] drm/mediatek/dp: fix spurious kfree()
Date: Fri, 17 May 2024 16:12:25 +0300	[thread overview]
Message-ID: <87v83ca8g6.fsf@intel.com> (raw)
In-Reply-To: <20240517093024.1702750-1-mwalle@kernel.org>

On Fri, 17 May 2024, Michael Walle <mwalle@kernel.org> wrote:
> 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>
> ---
>  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;

I suppose I would've just initialized sads = NULL; and be done with it.

But *shrug*.

Reviewed-by: Jani Nikula <jani.nikula@intel.com>


> +		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

-- 
Jani Nikula, Intel

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

  parent reply	other threads:[~2024-05-17 13:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17  9:30 [PATCH] drm/mediatek/dp: fix spurious kfree() Michael Walle
2024-05-17  9:30 ` Michael Walle
2024-05-17 10:35 ` AngeloGioacchino Del Regno
2024-05-17 10:35   ` AngeloGioacchino Del Regno
2024-05-17 11:07   ` Michael Walle
2024-05-17 11:07     ` Michael Walle
2024-05-17 11:09     ` AngeloGioacchino Del Regno
2024-05-17 11:09       ` AngeloGioacchino Del Regno
2024-05-17 11:21       ` Michael Walle
2024-05-17 11:21         ` Michael Walle
2024-05-17 11:23         ` AngeloGioacchino Del Regno
2024-05-17 11:23           ` AngeloGioacchino Del Regno
2024-05-17 13:12 ` Jani Nikula [this message]
2024-05-17 13:12   ` Jani Nikula

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=87v83ca8g6.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mwalle@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=wenst@chromium.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.