From 73cc99a5a5ae43f3fc2a46189b733e3331eed1b2 Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Fri, 10 Jul 2020 19:53:50 +0900 Subject: do not alloc if mode conut is 0 always reset the modelist if mode count is not 0. Change-Id: I2cb8efd72cc76158d93434fe8b7bf68014d8b830 Signed-off-by: Junkyeong Kim --- src/tdm_vc4_display.c | 62 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/tdm_vc4_display.c b/src/tdm_vc4_display.c index 5910459..a5f753c 100644 --- a/src/tdm_vc4_display.c +++ b/src/tdm_vc4_display.c @@ -1194,17 +1194,17 @@ vc4_output_get_capability(tdm_output *output, tdm_caps_output *caps) } caps->mode_count = count; - caps->modes = calloc(1, sizeof(tdm_output_mode) * caps->mode_count); - if (!caps->modes) { - ret = TDM_ERROR_OUT_OF_MEMORY; - TDM_ERR("alloc failed\n"); - goto failed_get; - } + if (caps->mode_count != 0) { + caps->modes = calloc(1, sizeof(tdm_output_mode) * caps->mode_count); + if (!caps->modes) { + ret = TDM_ERROR_OUT_OF_MEMORY; + TDM_ERR("alloc failed\n"); + goto failed_get; + } - output_data->count_drm_modes = connector->count_modes; - output_data->count_modes = caps->mode_count; + output_data->count_drm_modes = connector->count_modes; + output_data->count_modes = caps->mode_count; - if (caps->mode_count != output_data->count_modes) { drmModeModeInfoPtr new_drm_modes; tdm_output_mode *new_output_modes; @@ -1223,27 +1223,41 @@ vc4_output_get_capability(tdm_output *output, tdm_caps_output *caps) free(new_drm_modes); goto failed_get; } - free(output_data->vc4_modes); - free(output_data->output_modes); + if (output_data->vc4_modes) + free(output_data->vc4_modes); + if (output_data->output_modes) + free(output_data->output_modes); output_data->vc4_modes = new_drm_modes; output_data->output_modes = new_output_modes; - } - count = 0; - for (i = 0; i < connector->count_modes; i++) { - output_data->vc4_modes[i] = connector->modes[i]; + count = 0; + for (i = 0; i < connector->count_modes; i++) { + output_data->vc4_modes[i] = connector->modes[i]; - if ((connector->modes[i].hdisplay > MODE_WIDTH_LIMIT) || - (connector->modes[i].vdisplay > MODE_HEIGHT_LIMIT)) - continue; - if (connector->modes[i].vrefresh > MODE_REFRESH_LIMIT) - continue; + if ((connector->modes[i].hdisplay > MODE_WIDTH_LIMIT) || + (connector->modes[i].vdisplay > MODE_HEIGHT_LIMIT)) + continue; + if (connector->modes[i].vrefresh > MODE_REFRESH_LIMIT) + continue; - _tdm_vc4_display_to_tdm_mode(&output_data->vc4_modes[i], - &output_data->output_modes[count]); - caps->modes[count] = output_data->output_modes[count]; - count++; + _tdm_vc4_display_to_tdm_mode(&output_data->vc4_modes[i], + &output_data->output_modes[count]); + caps->modes[count] = output_data->output_modes[count]; + count++; + } + } else { + caps->modes = NULL; + output_data->count_drm_modes = connector->count_modes; + output_data->count_modes = caps->mode_count; + + if (output_data->vc4_modes) + free(output_data->vc4_modes); + if (output_data->output_modes) + free(output_data->output_modes); + + output_data->vc4_modes = NULL; + output_data->output_modes = NULL; } caps->mmWidth = connector->mmWidth; -- cgit v1.2.3