Looks much better without gotos. Signed-off-by: Daniel Martin <consume.no...@gmail.com> --- hw/xfree86/drivers/modesetting/drmmode_display.c | 75 +++++++++++------------- 1 file changed, 34 insertions(+), 41 deletions(-)
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c index 7ff55ef24..38314ed18 100644 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c @@ -1636,53 +1636,46 @@ static xf86OutputPtr find_output(ScrnInfoPtr pScrn, int id) return NULL; } -static Bool -parse_path_blob(drmModePropertyBlobPtr path_blob, - int *conn_base_id, char **extra_path) -{ - char *colon, *dash; - - if (!path_blob) - return FALSE; - - colon = strchr(path_blob->data, ':'); - dash = strchr(path_blob->data, '-'); - - if (colon && dash) { - *conn_base_id = strtoul(colon + 1, NULL, 10); - *extra_path = dash + 1; - - return TRUE; - } - - return FALSE; -} - static void drmmode_create_name(ScrnInfoPtr pScrn, drmModeConnectorPtr koutput, char *name, drmModePropertyBlobPtr path_blob) { - char *extra_path; - int conn_id; - xf86OutputPtr output; + char prefix[32], suffix[32]; - if (!parse_path_blob(path_blob, &conn_id, &extra_path)) - goto fallback; - - output = find_output(pScrn, conn_id); - if (!output) - goto fallback; - - snprintf(name, 32, "%s-%s", output->name, extra_path); - return; - - fallback: - if (koutput->connector_type >= ARRAY_SIZE(output_names)) - snprintf(name, 32, "Unknown%d-%d", koutput->connector_type, koutput->connector_type_id); - else if (pScrn->is_gpu) - snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id); + /* Initialize prefix and suffix with the most commonly used values. */ + if (koutput->connector_type < ARRAY_SIZE(output_names)) + snprintf(prefix, 32, "%s", output_names[koutput->connector_type]); else - snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id); + snprintf(prefix, 32, "Unknown%d", koutput->connector_type); + + snprintf(suffix, 32, "%d", koutput->connector_type_id); + + /* Override prefix and suffix, if we find our base connector, which is + * encoded within the MST path. */ + if (path_blob) { + xf86OutputPtr output = NULL; + char *colon, *dash, *extra_path; + + colon = strchr(path_blob->data, ':'); + dash = strchr(path_blob->data, '-'); + + if (colon && dash) { + int base_id = strtoul(colon + 1, NULL, 10); + extra_path = dash + 1; + output = find_output(pScrn, base_id); + } + + if (output) { + snprintf(prefix, 32, "%s", output->name); + snprintf(suffix, 32, "%s", extra_path); + } + } + + if (pScrn->is_gpu) { + int gpu_scrn = pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1; + snprintf(name, 32, "%s-%d-%s", prefix, gpu_scrn, suffix); + } else + snprintf(name, 32, "%s-%s", prefix, suffix); } static unsigned int -- 2.13.6 _______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: https://lists.x.org/mailman/listinfo/xorg-devel