diff options
author | Junkyeong Kim <jk0430.kim@samsung.com> | 2020-07-10 19:53:50 +0900 |
---|---|---|
committer | Junkyeong Kim <jk0430.kim@samsung.com> | 2020-07-10 19:53:54 +0900 |
commit | 73cc99a5a5ae43f3fc2a46189b733e3331eed1b2 (patch) | |
tree | d9058d69268b41221673117b46bab209bc419f33 | |
parent | 744228f6b2fee6978b711ec574d86b620159e4ce (diff) | |
download | libtdm-vc4-73cc99a5a5ae43f3fc2a46189b733e3331eed1b2.tar.gz libtdm-vc4-73cc99a5a5ae43f3fc2a46189b733e3331eed1b2.tar.bz2 libtdm-vc4-73cc99a5a5ae43f3fc2a46189b733e3331eed1b2.zip |
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 <jk0430.kim@samsung.com>
-rw-r--r-- | src/tdm_vc4_display.c | 62 |
1 files 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; |