[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOd=MviBd5iwSnhyt9aSZU+QTsBrBSGPcjsjt2eepfYC3KQ@mail.gmail.com>
Date: Mon, 7 Feb 2022 11:26:06 -0800
From: Nick Desaulniers <ndesaulniers@...gle.com>
To: trix@...hat.com
Cc: airlied@...hat.com, tzimmermann@...e.de, airlied@...ux.ie,
daniel@...ll.ch, nathan@...nel.org, maxime@...no.tech,
dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev
Subject: Re: [PATCH] drm/ast: fix using freed memory
On Thu, Feb 3, 2022 at 7:23 AM <trix@...hat.com> wrote:
>
> From: Tom Rix <trix@...hat.com>
>
> clang static analysis reports this problem
> ast_mode.c:1235:3: warning: Use of memory after it is freed
> drm_connector_update_edid_property(&ast_connector->base, edid);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The second condition on
>
> if (!flags && ast_connector->i2c)
>
> Means that the edid is not always set. If the previous block
> fails the freed edid value will be used. So set edid to NULL
> after freeing.
>
> Fixes: 55dc449a7c60 ("drm/ast: Handle failed I2C initialization gracefully")
> Signed-off-by: Tom Rix <trix@...hat.com>
> ---
> drivers/gpu/drm/ast/ast_mode.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> index ab52efb15670e..9131dc8a1a2fc 100644
> --- a/drivers/gpu/drm/ast/ast_mode.c
> +++ b/drivers/gpu/drm/ast/ast_mode.c
> @@ -1224,10 +1224,12 @@ static int ast_get_modes(struct drm_connector *connector)
> return -ENOMEM;
>
> flags = ast_dp501_read_edid(connector->dev, (u8 *)edid);
> - if (flags)
> + if (flags) {
> ast->dp501_maxclk = ast_get_dp501_max_clk(connector->dev);
> - else
> + } else {
> kfree(edid);
> + edid = NULL;
> + }
You probably didn't need to add the {} for the if, but it doesn't really matter.
Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>
> }
> if (!flags && ast_connector->i2c)
> edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
> --
> 2.26.3
>
--
Thanks,
~Nick Desaulniers
Powered by blists - more mailing lists