Merge pull request #312 from versusvoid/fix-drm-initialization

Fix index computation in DRM output scan and CRTC match
master
Scott Anderson 7 years ago committed by GitHub
commit 018cd98620

@ -319,9 +319,10 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
memset(possible_crtc, 0, sizeof(possible_crtc)); memset(possible_crtc, 0, sizeof(possible_crtc));
ssize_t index = -1, i = 0; ssize_t index = -1, i = -1;
struct wlr_drm_connector *c; struct wlr_drm_connector *c;
wl_list_for_each(c, &drm->outputs, link) { wl_list_for_each(c, &drm->outputs, link) {
i++;
if (c == conn) { if (c == conn) {
index = i; index = i;
} }
@ -332,7 +333,6 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
possible_crtc[i] = c->possible_crtc; possible_crtc[i] = c->possible_crtc;
crtc[c->crtc - drm->crtcs] = i; crtc[c->crtc - drm->crtcs] = i;
i++;
} }
assert(index != -1); assert(index != -1);
@ -686,7 +686,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
} }
size_t seen_len = wl_list_length(&drm->outputs); size_t seen_len = wl_list_length(&drm->outputs);
// +1 so it can never be 0 // +1 so length can never be 0, which is undefined behaviour.
// Last element isn't used.
bool seen[seen_len + 1]; bool seen[seen_len + 1];
memset(seen, 0, sizeof(seen)); memset(seen, 0, sizeof(seen));
@ -697,7 +698,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wlr_log_errno(L_ERROR, "Failed to get DRM connector"); wlr_log_errno(L_ERROR, "Failed to get DRM connector");
continue; continue;
} }
int index = 0; int index = -1;
struct wlr_drm_connector *c, *wlr_conn = NULL; struct wlr_drm_connector *c, *wlr_conn = NULL;
wl_list_for_each(c, &drm->outputs, link) { wl_list_for_each(c, &drm->outputs, link) {
index++; index++;
@ -794,13 +795,12 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
drmModeFreeResources(res); drmModeFreeResources(res);
struct wlr_drm_connector *conn, *tmp_conn; struct wlr_drm_connector *conn, *tmp_conn;
size_t index = seen_len - 1; size_t index = wl_list_length(&drm->outputs);
wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) { wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) {
if (seen[index]) { index--;
index--; if (index >= seen_len || seen[index]) {
continue; continue;
} }
index--;
wlr_log(L_INFO, "'%s' disappeared", conn->output.name); wlr_log(L_INFO, "'%s' disappeared", conn->output.name);
wlr_drm_connector_cleanup(conn); wlr_drm_connector_cleanup(conn);

Loading…
Cancel
Save