All of lore.kernel.org
 help / color / mirror / Atom feed
* re: drm: fix blob pointer check
@ 2016-03-11 11:39 Dan Carpenter
  2016-03-11 11:52 ` Lionel Landwerlin
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2016-03-11 11:39 UTC (permalink / raw)
  To: lionel.g.landwerlin; +Cc: dri-devel

Hi Lionel Landwerlin,

The patch 562c5b4d8986: "drm: fix blob pointer check" from Mar 10,
2016, has a problem.

drivers/gpu/drm/drm_atomic_helper.c
  2924          blob = drm_property_create_blob(dev,
  2925                                          sizeof(struct drm_color_lut) * size,
  2926                                          NULL);
  2927          if (IS_ERR(blob)) {
  2928                  ret = PTR_ERR(blob);
  2929                  goto fail;

These types of goto fails are a trap for the unwary.

I deliberately reported the bug instead of fixing it because I am a jerk
and because last time when I did this jerky thing, people were not
convinced that they would fall for the trap every single time.

http://www.spinics.net/lists/cgroups/msg15262.html

  2930          }
  2931  

[ snip ]

  2973  fail:
  2974          if (ret == -EDEADLK)
  2975                  goto backoff;
  2976  
  2977          drm_atomic_state_free(state);
  2978          drm_property_unreference_blob(blob);
                                              ^^^^
Blob is an error pointer here so it will oops inside the function call.

The better way to write this is to unwind in the reverse order from the
allocations.  So since we allocated state first then we free it last.
Use explicit names based on what the goto does.  err_unreference:
err_free_state:.  Don't free things that haven't been allocated.

Or you could set "blob = NULL;" before the goto.

  2979  
  2980          return;
  2981  backoff:
  2982          drm_atomic_state_clear(state);
  2983          drm_atomic_legacy_backoff(state);
  2984  
  2985          goto retry;
  2986  }

regards,
dan carpenter
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-14  9:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-11 11:39 drm: fix blob pointer check Dan Carpenter
2016-03-11 11:52 ` Lionel Landwerlin
2016-03-11 12:01   ` David Herrmann
2016-03-14  9:06   ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.