check drm mode get function fail 53/198553/1
authorJunkyeong Kim <jk0430.kim@samsung.com>
Fri, 25 Jan 2019 09:26:46 +0000 (18:26 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Fri, 25 Jan 2019 09:26:50 +0000 (18:26 +0900)
Change-Id: I14ec663eefbba1ae0bb651340a5020159e560e46
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/tdm_vc4_display.c

index 981376d..5a3954b 100644 (file)
@@ -586,7 +586,8 @@ _tdm_vc4_display_wait_vblank(int fd, int pipe, uint *target_msc, void *data)
        return TDM_ERROR_NONE;
 }
 
-static int _tdm_vc4_display_get_properties(int drm_fd, uint32_t connector_id, uint32_t crtc_id,
+static tdm_error
+_tdm_vc4_display_get_properties(int drm_fd, uint32_t connector_id, uint32_t crtc_id,
                                        uint32_t plane_id, struct display_properties_ids *ids)
 {
        drmModeObjectPropertiesPtr properties = NULL;
@@ -654,7 +655,8 @@ finish:
        return ret;
 }
 
-static int _tdm_vc4_display_get_plane_id(int drm_fd, uint32_t crtc_id)
+static tdm_error
+_tdm_vc4_display_get_plane_id(int drm_fd, uint32_t crtc_id, uint32_t *id)
 {
        drmModeResPtr ressources = NULL;
        drmModePlaneResPtr plane_resources;
@@ -662,9 +664,13 @@ static int _tdm_vc4_display_get_plane_id(int drm_fd, uint32_t crtc_id)
        uint32_t plane_id = 0;
        uint32_t found_primary = 0;
        int i, j;
+       tdm_error ret = TDM_ERROR_NONE;
+
+       if (id) *id = 0;
 
        ressources = drmModeGetResources(drm_fd);
        if (ressources == NULL) {
+               ret = TDM_ERROR_OPERATION_FAILED;
                goto finish;
        }
 
@@ -676,11 +682,13 @@ static int _tdm_vc4_display_get_plane_id(int drm_fd, uint32_t crtc_id)
        }
 
        if (i == ressources->count_crtcs) {
+               ret = TDM_ERROR_OPERATION_FAILED;
                goto free_resource;
        }
 
        plane_resources = drmModeGetPlaneResources(drm_fd);
        if (!plane_resources) {
+               ret = TDM_ERROR_OPERATION_FAILED;
                goto free_resource;
        }
 
@@ -694,10 +702,17 @@ static int _tdm_vc4_display_get_plane_id(int drm_fd, uint32_t crtc_id)
                if (plane->possible_crtcs & (1 << crtc_index)) {
                        drmModeObjectPropertiesPtr props =
                                drmModeObjectGetProperties(drm_fd, plane_id, DRM_MODE_OBJECT_PLANE);
+                       if (!props) {
+                               ret = TDM_ERROR_OPERATION_FAILED;
+                               goto free_resource;
+                       }
 
                        for (j = 0; j < props->count_props; j++) {
                                drmModePropertyPtr p = drmModeGetProperty(drm_fd, props->props[j]);
 
+                               if (!p)
+                                       continue;
+
                                if ((strcmp(p->name, "type") == 0) &&
                                                (props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY)) {
                                        found_primary = 1;
@@ -712,11 +727,18 @@ static int _tdm_vc4_display_get_plane_id(int drm_fd, uint32_t crtc_id)
                drmModeFreePlane(plane);
        }
 
+       if (found_primary) {
+               if (id)
+                       *id = plane_id;
+       } else {
+               ret = TDM_ERROR_OPERATION_FAILED;
+       }
+
        drmModeFreePlaneResources(plane_resources);
 free_resource:
        drmModeFreeResources(ressources);
 finish:
-       return plane_id;
+       return ret;
 }
 
 static tdm_error
@@ -727,6 +749,7 @@ _tdm_vc4_display_commit_layer(tdm_vc4_layer_data *layer_data, void *event_data)
        uint32_t fx, fy, fw, fh;
        drmModeAtomicReqPtr request;
        uint32_t flags =  0;
+       tdm_error ret = TDM_ERROR_NONE;
 
        if (!layer_data->display_buffer_changed && !layer_data->info_changed)
                return TDM_ERROR_NONE;
@@ -738,10 +761,12 @@ _tdm_vc4_display_commit_layer(tdm_vc4_layer_data *layer_data, void *event_data)
                drmSetClientCap(vc4_data->drm_fd, DRM_CLIENT_CAP_ATOMIC, 1);
                drmSetClientCap(vc4_data->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 
-               output_data->output_plane = _tdm_vc4_display_get_plane_id(vc4_data->drm_fd, output_data->crtc_id);
+               ret = _tdm_vc4_display_get_plane_id(vc4_data->drm_fd, output_data->crtc_id, &output_data->output_plane);
+               if (ret != TDM_ERROR_NONE) return ret;
 
-               _tdm_vc4_display_get_properties(vc4_data->drm_fd, output_data->connector_id,
+               ret = _tdm_vc4_display_get_properties(vc4_data->drm_fd, output_data->connector_id,
                                                        output_data->crtc_id, output_data->output_plane, &output_data->props);
+               if (ret != TDM_ERROR_NONE) return ret;
 
                output_data->crtc_enabled = 1;
        }