Skip to contentSkip to conversation

drm/amd/display: Build stream update and plane updates in dm

bug report Dan Carpenter 2 participants 2 messages Sep 28, 2018

lore
Share & tools
lore
#0 lore raw

Hello Bhawanpreet Lakha,

The patch a87fa9938749: "drm/amd/display: Build stream update and plane updates in dm" from Aug 20, 2018, leads to the following static checker warning:

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:5190 dm_determine_update_type_for_commit()
error: potential null dereference 'surface'. (kzalloc returns null)

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c

  5153          int i, j, num_plane;
  5154          struct drm_plane_state *old_plane_state, *new_plane_state;
  5155          struct dm_plane_state *new_dm_plane_state, *old_dm_plane_state;
  5156          struct drm_crtc *new_plane_crtc, *old_plane_crtc;
  5157          struct drm_plane *plane;
  5158  
  5159          struct drm_crtc *crtc;
  5160          struct drm_crtc_state *new_crtc_state, *old_crtc_state;
  5161          struct dm_crtc_state *new_dm_crtc_state, *old_dm_crtc_state;
  5162          struct dc_stream_status *status = NULL;
  5163  
  5164          struct dc_surface_update *updates = kzalloc(MAX_SURFACES * sizeof(struct dc_surface_update), GFP_KERNEL);
                                          ^^^^^^^^^^^^^^^^^
  5165          struct dc_plane_state *surface = kzalloc(MAX_SURFACES * sizeof(struct dc_plane_state), GFP_KERNEL);
                                       ^^^^^^^^^^^^^^^^^

No checks for NULL.

  5166          struct dc_stream_update stream_update;
  5167          enum surface_update_type update_type = UPDATE_TYPE_FAST;
  5168  
  5169  
  5170          for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  5171                  new_dm_crtc_state = to_dm_crtc_state(new_crtc_state);
  5172                  old_dm_crtc_state = to_dm_crtc_state(old_crtc_state);
  5173                  num_plane = 0;
  5174  
  5175                  if (new_dm_crtc_state->stream) {
  5176  
  5177                          for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, j) {
  5178                                  new_plane_crtc = new_plane_state->crtc;
  5179                                  old_plane_crtc = old_plane_state->crtc;
  5180                                  new_dm_plane_state = to_dm_plane_state(new_plane_state);
  5181                                  old_dm_plane_state = to_dm_plane_state(old_plane_state);
  5182  
  5183                                  if (plane->type == DRM_PLANE_TYPE_CURSOR)
  5184                                          continue;
  5185  
  5186                                  if (!state->allow_modeset)
  5187                                          continue;
  5188  
  5189                                  if (crtc == new_plane_crtc) {
  5190                                          updates[num_plane].surface = &surface[num_plane];
  5191  
  5192                                          if (new_crtc_state->mode_changed) {
  5193                                                  updates[num_plane].surface->src_rect =
  5194                                                                          new_dm_plane_state->dc_state->src_rect;
  5195                                                  updates[num_plane].surface->dst_rect =
  5196                                                                          new_dm_plane_state->dc_state->dst_rect;
  5197                                                  updates[num_plane].surface->rotation =

regards,
dan carpenter
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#1 lore raw

I had a patch ready and was going to send it in the next promotion patches. Will send it soon.

Bhawan

Quoted 60 lines · Dan Carpenter

Hello Bhawanpreet Lakha,

The patch a87fa9938749: "drm/amd/display: Build stream update and plane updates in dm" from Aug 20, 2018, leads to the following static checker warning:

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c:5190 dm_determine_update_type_for_commit()
error: potential null dereference 'surface'. (kzalloc returns null)

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm.c

   5153          int i, j, num_plane;
   5154          struct drm_plane_state *old_plane_state, *new_plane_state;
   5155          struct dm_plane_state *new_dm_plane_state, *old_dm_plane_state;
   5156          struct drm_crtc *new_plane_crtc, *old_plane_crtc;
   5157          struct drm_plane *plane;
   5158
   5159          struct drm_crtc *crtc;
   5160          struct drm_crtc_state *new_crtc_state, *old_crtc_state;
   5161          struct dm_crtc_state *new_dm_crtc_state, *old_dm_crtc_state;
   5162          struct dc_stream_status *status = NULL;
   5163
   5164          struct dc_surface_update *updates = kzalloc(MAX_SURFACES * sizeof(struct dc_surface_update), GFP_KERNEL);
                                           ^^^^^^^^^^^^^^^^^
   5165          struct dc_plane_state *surface = kzalloc(MAX_SURFACES * sizeof(struct dc_plane_state), GFP_KERNEL);
                                        ^^^^^^^^^^^^^^^^^

No checks for NULL.

   5166          struct dc_stream_update stream_update;
   5167          enum surface_update_type update_type = UPDATE_TYPE_FAST;
   5168
   5169
   5170          for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
   5171                  new_dm_crtc_state = to_dm_crtc_state(new_crtc_state);
   5172                  old_dm_crtc_state = to_dm_crtc_state(old_crtc_state);
   5173                  num_plane = 0;
   5174
   5175                  if (new_dm_crtc_state->stream) {
   5176
   5177                          for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, j) {
   5178                                  new_plane_crtc = new_plane_state->crtc;
   5179                                  old_plane_crtc = old_plane_state->crtc;
   5180                                  new_dm_plane_state = to_dm_plane_state(new_plane_state);
   5181                                  old_dm_plane_state = to_dm_plane_state(old_plane_state);
   5182
   5183                                  if (plane->type == DRM_PLANE_TYPE_CURSOR)
   5184                                          continue;
   5185
   5186                                  if (!state->allow_modeset)
   5187                                          continue;
   5188
   5189                                  if (crtc == new_plane_crtc) {
   5190                                          updates[num_plane].surface = &surface[num_plane];
   5191
   5192                                          if (new_crtc_state->mode_changed) {
   5193                                                  updates[num_plane].surface->src_rect =
   5194                                                                          new_dm_plane_state->dc_state->src_rect;
   5195                                                  updates[num_plane].surface->dst_rect =
   5196                                                                          new_dm_plane_state->dc_state->dst_rect;
   5197                                                  updates[num_plane].surface->rotation =
Quoted 2 lines

regards,
dan carpenter

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx