* [PATCH] drm/ast: fix using freed memory
@ 2022-02-03 15:23 trix
2022-02-07 19:26 ` Nick Desaulniers
2022-02-10 18:55 ` Thomas Zimmermann
0 siblings, 2 replies; 3+ messages in thread
From: trix @ 2022-02-03 15:23 UTC (permalink / raw)
To: airlied, tzimmermann, airlied, daniel, nathan, ndesaulniers, maxime
Cc: dri-devel, linux-kernel, llvm, Tom Rix
From: Tom Rix <trix@redhat.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@redhat.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;
+ }
}
if (!flags && ast_connector->i2c)
edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
--
2.26.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/ast: fix using freed memory
2022-02-03 15:23 [PATCH] drm/ast: fix using freed memory trix
@ 2022-02-07 19:26 ` Nick Desaulniers
2022-02-10 18:55 ` Thomas Zimmermann
1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2022-02-07 19:26 UTC (permalink / raw)
To: trix
Cc: airlied, tzimmermann, airlied, daniel, nathan, maxime, dri-devel,
linux-kernel, llvm
On Thu, Feb 3, 2022 at 7:23 AM <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.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@redhat.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@google.com>
> }
> if (!flags && ast_connector->i2c)
> edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
> --
> 2.26.3
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/ast: fix using freed memory
2022-02-03 15:23 [PATCH] drm/ast: fix using freed memory trix
2022-02-07 19:26 ` Nick Desaulniers
@ 2022-02-10 18:55 ` Thomas Zimmermann
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Zimmermann @ 2022-02-10 18:55 UTC (permalink / raw)
To: trix, airlied, airlied, daniel, nathan, ndesaulniers, maxime
Cc: llvm, linux-kernel, dri-devel
[-- Attachment #1.1: Type: text/plain, Size: 1795 bytes --]
Hi
Am 03.02.22 um 16:23 schrieb trix@redhat.com:
> From: Tom Rix <trix@redhat.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.
Thanks for your patch. We have meanwhile merges a change that replaces
the code entirely.
Best regards
Thomas
>
> Fixes: 55dc449a7c60 ("drm/ast: Handle failed I2C initialization gracefully")
> Signed-off-by: Tom Rix <trix@redhat.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;
> + }
> }
> if (!flags && ast_connector->i2c)
> edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-10 18:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 15:23 [PATCH] drm/ast: fix using freed memory trix
2022-02-07 19:26 ` Nick Desaulniers
2022-02-10 18:55 ` Thomas Zimmermann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).