Commit e7bd95a7 authored by Douglas Anderson's avatar Douglas Anderson

drm/edid: Fix crash with zero/invalid EDID

In the commit bac9c294 ("drm/edid: Break out reading block 0 of
the EDID") I broke out reading the base block of the EDID to its own
function. Unfortunately, when I did that I messed up the handling when
drm_edid_is_zero() indicated that we had an EDID that was all 0x00 or
when we went through 4 loops and didn't get a valid EDID. Specifically
I needed to pass the broken EDID to connector_bad_edid() but now I was
passing an error-pointer.

Let's re-jigger things so we can pass the bad EDID in properly.

Fixes: bac9c294 ("drm/edid: Break out reading block 0 of the EDID")
Reported-by: default avatarkernel test robot <oliver.sang@intel.com>
Reported-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
Reviewed-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Tested-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Link: https://patchwork.freedesktop.org/patch/msgid/20211004092100.1.Ic90a5ebd44c75db963112be167a03cc96f9fb249@changeid
parent 61bae132
...@@ -1911,13 +1911,15 @@ int drm_add_override_edid_modes(struct drm_connector *connector) ...@@ -1911,13 +1911,15 @@ int drm_add_override_edid_modes(struct drm_connector *connector)
} }
EXPORT_SYMBOL(drm_add_override_edid_modes); EXPORT_SYMBOL(drm_add_override_edid_modes);
static struct edid *drm_do_get_edid_base_block( static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector,
int (*get_edid_block)(void *data, u8 *buf, unsigned int block, int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
size_t len), size_t len),
void *data, bool *edid_corrupt, int *null_edid_counter) void *data)
{ {
int i; int *null_edid_counter = connector ? &connector->null_edid_counter : NULL;
bool *edid_corrupt = connector ? &connector->edid_corrupt : NULL;
void *edid; void *edid;
int i;
edid = kmalloc(EDID_LENGTH, GFP_KERNEL); edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
if (edid == NULL) if (edid == NULL)
...@@ -1941,9 +1943,8 @@ static struct edid *drm_do_get_edid_base_block( ...@@ -1941,9 +1943,8 @@ static struct edid *drm_do_get_edid_base_block(
return edid; return edid;
carp: carp:
kfree(edid); if (connector)
return ERR_PTR(-EINVAL); connector_bad_edid(connector, edid, 1);
out: out:
kfree(edid); kfree(edid);
return NULL; return NULL;
...@@ -1982,14 +1983,9 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, ...@@ -1982,14 +1983,9 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
if (override) if (override)
return override; return override;
edid = (u8 *)drm_do_get_edid_base_block(get_edid_block, data, edid = (u8 *)drm_do_get_edid_base_block(connector, get_edid_block, data);
&connector->edid_corrupt, if (!edid)
&connector->null_edid_counter);
if (IS_ERR_OR_NULL(edid)) {
if (IS_ERR(edid))
connector_bad_edid(connector, edid, 1);
return NULL; return NULL;
}
/* if there's no extensions or no connector, we're done */ /* if there's no extensions or no connector, we're done */
valid_extensions = edid[0x7e]; valid_extensions = edid[0x7e];
...@@ -2142,14 +2138,13 @@ u32 drm_edid_get_panel_id(struct i2c_adapter *adapter) ...@@ -2142,14 +2138,13 @@ u32 drm_edid_get_panel_id(struct i2c_adapter *adapter)
struct edid *edid; struct edid *edid;
u32 panel_id; u32 panel_id;
edid = drm_do_get_edid_base_block(drm_do_probe_ddc_edid, adapter, edid = drm_do_get_edid_base_block(NULL, drm_do_probe_ddc_edid, adapter);
NULL, NULL);
/* /*
* There are no manufacturer IDs of 0, so if there is a problem reading * There are no manufacturer IDs of 0, so if there is a problem reading
* the EDID then we'll just return 0. * the EDID then we'll just return 0.
*/ */
if (IS_ERR_OR_NULL(edid)) if (!edid)
return 0; return 0;
panel_id = edid_extract_panel_id(edid); panel_id = edid_extract_panel_id(edid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment