drm/ast: fix using freed memory
Subsystems (3)
PATCH 1/1 drm/ast: fix using freed memory
From: Tom Rix <[email protected]>
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.
--- drivers/gpu/drm/ast/ast_mode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +4 -2
@@ -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);
Signature · 1 line
2.26.3
Quoted 28 lines · On Thu, Feb 3, 2022 at 7:23 AM <[email protected]> wrote:
From: Tom Rix <[email protected]>
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 <[email protected]>--- drivers/gpu/drm/ast/ast_mode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/ast/ast_mode.c +0
-0@@ -1224,10 +1224,12 @@ static int ast_get_modes(struct drm_connector *connector)return -ENOMEM ;
drivers/gpu/drm/ast/ast_mode.c static int ast_get_modes(struct drm_connector *connector) · line 1232
Quoted 10 lines
drivers/gpu/drm/ast/ast_mode.c +4
-2flags =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.
Quoted 6 lines
drivers/gpu/drm/ast/ast_mode.c +0
-1}if (!flags && ast_connector->i2c) edid =drm_get_edid (connector, &ast_connector->i2c->adapter); --2.26.3
Signature · 2 lines
Thanks, ~Nick Desaulniers
Thomas Zimmermann
maintainerHi
Am 03.02.22 um 16:23 schrieb [email protected]:
Quoted 7 lines
From: Tom Rix <[email protected]>
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); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines
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
Quoted 26 lines
Fixes 55dc449a7c60 ("drm/ast: Handle failed I2C initialization gracefully")Signed-off-by Tom Rix <[email protected]>--- drivers/gpu/drm/ast/ast_mode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/ast/ast_mode.c +4
-2@@ -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);
Signature · 6 lines
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