Skip to content

Commit

Permalink
drm/exynos/hdmi: Fix unsafe list iteration
Browse files Browse the repository at this point in the history
Function hdmi_mode_fixup() used bare list_for_each entry, which was
unsafe and caused memory corruption detected by kasan.
It now uses drm_for_each_connector_iter macro, which is now recommended
by the documentation and safe.

Signed-off-by: Maciej Purski <m.purski@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
  • Loading branch information
Maciej Purski authored and Inki Dae committed Sep 20, 2017
1 parent 9ac30ef commit 04fc52f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/gpu/drm/exynos/exynos_hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,22 +944,27 @@ static bool hdmi_mode_fixup(struct drm_encoder *encoder,
struct drm_device *dev = encoder->dev;
struct drm_connector *connector;
struct drm_display_mode *m;
struct drm_connector_list_iter conn_iter;
int mode_ok;

drm_mode_set_crtcinfo(adjusted_mode, 0);

list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
drm_connector_list_iter_begin(dev, &conn_iter);
drm_for_each_connector_iter(connector, &conn_iter) {
if (connector->encoder == encoder)
break;
}
if (connector)
drm_connector_get(connector);
drm_connector_list_iter_end(&conn_iter);

if (connector->encoder != encoder)
if (!connector)
return true;

mode_ok = hdmi_mode_valid(connector, adjusted_mode);

if (mode_ok == MODE_OK)
return true;
goto cleanup;

/*
* Find the most suitable mode and copy it to adjusted_mode.
Expand All @@ -979,6 +984,9 @@ static bool hdmi_mode_fixup(struct drm_encoder *encoder,
}
}

cleanup:
drm_connector_put(connector);

return true;
}

Expand Down

0 comments on commit 04fc52f

Please sign in to comment.