[bug report] drm/ast: Handle failed I2C initialization gracefully

Dan Carpenter dan.carpenter at oracle.com
Thu Jan 6 10:19:46 UTC 2022


Hello Thomas Zimmermann,

The patch 55dc449a7c60: "drm/ast: Handle failed I2C initialization
gracefully" from Dec 6, 2021, leads to the following Smatch static
checker warning:

	drivers/gpu/drm/ast/ast_mode.c:1232 ast_get_modes()
	warn: passing freed memory 'edid'

drivers/gpu/drm/ast/ast_mode.c
    1209 static int ast_get_modes(struct drm_connector *connector)
    1210 {
    1211         struct ast_connector *ast_connector = to_ast_connector(connector);
    1212         struct ast_private *ast = to_ast_private(connector->dev);
    1213         struct edid *edid = NULL;
    1214         bool flags = false;
    1215         int ret;
    1216 
    1217         if (ast->tx_chip_type == AST_TX_DP501) {
    1218                 ast->dp501_maxclk = 0xff;
    1219                 edid = kmalloc(128, GFP_KERNEL);
    1220                 if (!edid)
    1221                         return -ENOMEM;
    1222 
    1223                 flags = ast_dp501_read_edid(connector->dev, (u8 *)edid);
    1224                 if (flags)
    1225                         ast->dp501_maxclk = ast_get_dp501_max_clk(connector->dev);
    1226                 else
    1227                         kfree(edid);

kfree

    1228         }
    1229         if (!flags && ast_connector->i2c)
    1230                 edid = drm_get_edid(connector, &ast_connector->i2c->adapter);

If "!flags" is true but "ast_connector->i2c" is false

    1231         if (edid) {
--> 1232                 drm_connector_update_edid_property(&ast_connector->base, edid);

Then perhaps "edid" is free here.

    1233                 ret = drm_add_edid_modes(connector, edid);
    1234                 kfree(edid);
    1235                 return ret;
    1236         }
    1237         drm_connector_update_edid_property(&ast_connector->base, NULL);
    1238         return 0;
    1239 }

regards,
dan carpenter


More information about the dri-devel mailing list