Skip to content

Commit a4a69da

Browse files
committed
drm: Introduce drm_framebuffer_{get,put}()
For consistency with other reference counting APIs in the kernel, add drm_framebuffer_get() and drm_framebuffer_put() to reference count DRM framebuffers. Compatibility aliases are added to keep existing code working. To help speed up the transition, all the instances of the old functions in the DRM core are already replaced in this commit. The existing semantic patch for the DRM subsystem-wide conversion is extended to account for these new helpers. Reviewed-by: Sean Paul <seanpaul@chromium.org> Acked-by: Christian König <christian.koenig@amd.com> Signed-off-by: Thierry Reding <treding@nvidia.com> Link: http://patchwork.freedesktop.org/patch/msgid/20170228144643.5668-5-thierry.reding@gmail.com
1 parent ad09360 commit a4a69da

7 files changed

Lines changed: 79 additions & 44 deletions

File tree

‎drivers/gpu/drm/drm_atomic.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ int drm_atomic_plane_set_property(struct drm_plane *plane,
737737
struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val);
738738
drm_atomic_set_fb_for_plane(state, fb);
739739
if (fb)
740-
drm_framebuffer_unreference(fb);
740+
drm_framebuffer_put(fb);
741741
} else if (property == config->prop_in_fence_fd) {
742742
if (state->fence)
743743
return -EINVAL;
@@ -1865,12 +1865,12 @@ void drm_atomic_clean_old_fb(struct drm_device *dev,
18651865
if (ret == 0) {
18661866
struct drm_framebuffer *new_fb = plane->state->fb;
18671867
if (new_fb)
1868-
drm_framebuffer_reference(new_fb);
1868+
drm_framebuffer_get(new_fb);
18691869
plane->fb = new_fb;
18701870
plane->crtc = plane->state->crtc;
18711871

18721872
if (plane->old_fb)
1873-
drm_framebuffer_unreference(plane->old_fb);
1873+
drm_framebuffer_put(plane->old_fb);
18741874
}
18751875
plane->old_fb = NULL;
18761876
}

‎drivers/gpu/drm/drm_atomic_helper.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,7 +3230,7 @@ void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
32303230
memcpy(state, plane->state, sizeof(*state));
32313231

32323232
if (state->fb)
3233-
drm_framebuffer_reference(state->fb);
3233+
drm_framebuffer_get(state->fb);
32343234

32353235
state->fence = NULL;
32363236
}
@@ -3270,7 +3270,7 @@ EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
32703270
void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
32713271
{
32723272
if (state->fb)
3273-
drm_framebuffer_unreference(state->fb);
3273+
drm_framebuffer_put(state->fb);
32743274

32753275
if (state->fence)
32763276
dma_fence_put(state->fence);

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ int drm_mode_set_config_internal(struct drm_mode_set *set)
471471

472472
drm_for_each_crtc(tmp, crtc->dev) {
473473
if (tmp->primary->fb)
474-
drm_framebuffer_reference(tmp->primary->fb);
474+
drm_framebuffer_get(tmp->primary->fb);
475475
if (tmp->primary->old_fb)
476-
drm_framebuffer_unreference(tmp->primary->old_fb);
476+
drm_framebuffer_put(tmp->primary->old_fb);
477477
tmp->primary->old_fb = NULL;
478478
}
479479

@@ -567,7 +567,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
567567
}
568568
fb = crtc->primary->fb;
569569
/* Make refcounting symmetric with the lookup path. */
570-
drm_framebuffer_reference(fb);
570+
drm_framebuffer_get(fb);
571571
} else {
572572
fb = drm_framebuffer_lookup(dev, crtc_req->fb_id);
573573
if (!fb) {
@@ -680,7 +680,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
680680

681681
out:
682682
if (fb)
683-
drm_framebuffer_unreference(fb);
683+
drm_framebuffer_put(fb);
684684

685685
if (connector_set) {
686686
for (i = 0; i < crtc_req->count_connectors; i++) {

‎drivers/gpu/drm/drm_framebuffer.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@
5252
* metadata fields.
5353
*
5454
* The lifetime of a drm framebuffer is controlled with a reference count,
55-
* drivers can grab additional references with drm_framebuffer_reference() and
56-
* drop them again with drm_framebuffer_unreference(). For driver-private
57-
* framebuffers for which the last reference is never dropped (e.g. for the
58-
* fbdev framebuffer when the struct &struct drm_framebuffer is embedded into
59-
* the fbdev helper struct) drivers can manually clean up a framebuffer at
60-
* module unload time with drm_framebuffer_unregister_private(). But doing this
61-
* is not recommended, and it's better to have a normal free-standing &struct
55+
* drivers can grab additional references with drm_framebuffer_get() and drop
56+
* them again with drm_framebuffer_put(). For driver-private framebuffers for
57+
* which the last reference is never dropped (e.g. for the fbdev framebuffer
58+
* when the struct &struct drm_framebuffer is embedded into the fbdev helper
59+
* struct) drivers can manually clean up a framebuffer at module unload time
60+
* with drm_framebuffer_unregister_private(). But doing this is not
61+
* recommended, and it's better to have a normal free-standing &struct
6262
* drm_framebuffer.
6363
*/
6464

@@ -374,7 +374,7 @@ int drm_mode_rmfb(struct drm_device *dev,
374374
mutex_unlock(&file_priv->fbs_lock);
375375

376376
/* drop the reference we picked up in framebuffer lookup */
377-
drm_framebuffer_unreference(fb);
377+
drm_framebuffer_put(fb);
378378

379379
/*
380380
* we now own the reference that was stored in the fbs list
@@ -394,12 +394,12 @@ int drm_mode_rmfb(struct drm_device *dev,
394394
flush_work(&arg.work);
395395
destroy_work_on_stack(&arg.work);
396396
} else
397-
drm_framebuffer_unreference(fb);
397+
drm_framebuffer_put(fb);
398398

399399
return 0;
400400

401401
fail_unref:
402-
drm_framebuffer_unreference(fb);
402+
drm_framebuffer_put(fb);
403403
return -ENOENT;
404404
}
405405

@@ -453,7 +453,7 @@ int drm_mode_getfb(struct drm_device *dev,
453453
ret = -ENODEV;
454454
}
455455

456-
drm_framebuffer_unreference(fb);
456+
drm_framebuffer_put(fb);
457457

458458
return ret;
459459
}
@@ -540,7 +540,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
540540
out_err2:
541541
kfree(clips);
542542
out_err1:
543-
drm_framebuffer_unreference(fb);
543+
drm_framebuffer_put(fb);
544544

545545
return ret;
546546
}
@@ -580,7 +580,7 @@ void drm_fb_release(struct drm_file *priv)
580580
list_del_init(&fb->filp_head);
581581

582582
/* This drops the fpriv->fbs reference. */
583-
drm_framebuffer_unreference(fb);
583+
drm_framebuffer_put(fb);
584584
}
585585
}
586586

@@ -661,7 +661,7 @@ EXPORT_SYMBOL(drm_framebuffer_init);
661661
*
662662
* If successful, this grabs an additional reference to the framebuffer -
663663
* callers need to make sure to eventually unreference the returned framebuffer
664-
* again, using @drm_framebuffer_unreference.
664+
* again, using drm_framebuffer_put().
665665
*/
666666
struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
667667
uint32_t id)
@@ -687,8 +687,8 @@ EXPORT_SYMBOL(drm_framebuffer_lookup);
687687
*
688688
* NOTE: This function is deprecated. For driver-private framebuffers it is not
689689
* recommended to embed a framebuffer struct info fbdev struct, instead, a
690-
* framebuffer pointer is preferred and drm_framebuffer_unreference() should be
691-
* called when the framebuffer is to be cleaned up.
690+
* framebuffer pointer is preferred and drm_framebuffer_put() should be called
691+
* when the framebuffer is to be cleaned up.
692692
*/
693693
void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
694694
{
@@ -797,7 +797,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
797797
}
798798

799799
out:
800-
drm_framebuffer_unreference(fb);
800+
drm_framebuffer_put(fb);
801801
}
802802
EXPORT_SYMBOL(drm_framebuffer_remove);
803803

‎drivers/gpu/drm/drm_plane.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void drm_plane_force_disable(struct drm_plane *plane)
293293
return;
294294
}
295295
/* disconnect the plane from the fb and crtc: */
296-
drm_framebuffer_unreference(plane->old_fb);
296+
drm_framebuffer_put(plane->old_fb);
297297
plane->old_fb = NULL;
298298
plane->fb = NULL;
299299
plane->crtc = NULL;
@@ -520,9 +520,9 @@ static int __setplane_internal(struct drm_plane *plane,
520520

521521
out:
522522
if (fb)
523-
drm_framebuffer_unreference(fb);
523+
drm_framebuffer_put(fb);
524524
if (plane->old_fb)
525-
drm_framebuffer_unreference(plane->old_fb);
525+
drm_framebuffer_put(plane->old_fb);
526526
plane->old_fb = NULL;
527527

528528
return ret;
@@ -638,7 +638,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
638638
} else {
639639
fb = crtc->cursor->fb;
640640
if (fb)
641-
drm_framebuffer_reference(fb);
641+
drm_framebuffer_get(fb);
642642
}
643643

644644
if (req->flags & DRM_MODE_CURSOR_MOVE) {
@@ -902,9 +902,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
902902
if (ret && crtc->funcs->page_flip_target)
903903
drm_crtc_vblank_put(crtc);
904904
if (fb)
905-
drm_framebuffer_unreference(fb);
905+
drm_framebuffer_put(fb);
906906
if (crtc->primary->old_fb)
907-
drm_framebuffer_unreference(crtc->primary->old_fb);
907+
drm_framebuffer_put(crtc->primary->old_fb);
908908
crtc->primary->old_fb = NULL;
909909
drm_modeset_unlock_crtc(crtc);
910910

‎include/drm/drm_framebuffer.h‎

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ struct drm_framebuffer_funcs {
101101
* cleanup (like releasing the reference(s) on the backing GEM bo(s))
102102
* should be deferred. In cases like this, the driver would like to
103103
* hold a ref to the fb even though it has already been removed from
104-
* userspace perspective. See drm_framebuffer_reference() and
105-
* drm_framebuffer_unreference().
104+
* userspace perspective. See drm_framebuffer_get() and
105+
* drm_framebuffer_put().
106106
*
107107
* The refcount is stored inside the mode object @base.
108108
*/
@@ -204,25 +204,50 @@ void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
204204
void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
205205

206206
/**
207-
* drm_framebuffer_reference - incr the fb refcnt
208-
* @fb: framebuffer
207+
* drm_framebuffer_get - acquire a framebuffer reference
208+
* @fb: DRM framebuffer
209+
*
210+
* This function increments the framebuffer's reference count.
211+
*/
212+
static inline void drm_framebuffer_get(struct drm_framebuffer *fb)
213+
{
214+
drm_mode_object_get(&fb->base);
215+
}
216+
217+
/**
218+
* drm_framebuffer_put - release a framebuffer reference
219+
* @fb: DRM framebuffer
220+
*
221+
* This function decrements the framebuffer's reference count and frees the
222+
* framebuffer if the reference count drops to zero.
223+
*/
224+
static inline void drm_framebuffer_put(struct drm_framebuffer *fb)
225+
{
226+
drm_mode_object_put(&fb->base);
227+
}
228+
229+
/**
230+
* drm_framebuffer_reference - acquire a framebuffer reference
231+
* @fb: DRM framebuffer
209232
*
210-
* This functions increments the fb's refcount.
233+
* This is a compatibility alias for drm_framebuffer_get() and should not be
234+
* used by new code.
211235
*/
212236
static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
213237
{
214-
drm_mode_object_reference(&fb->base);
238+
drm_framebuffer_get(fb);
215239
}
216240

217241
/**
218-
* drm_framebuffer_unreference - unref a framebuffer
219-
* @fb: framebuffer to unref
242+
* drm_framebuffer_unreference - release a framebuffer reference
243+
* @fb: DRM framebuffer
220244
*
221-
* This functions decrements the fb's refcount and frees it if it drops to zero.
245+
* This is a compatibility alias for drm_framebuffer_put() and should not be
246+
* used by new code.
222247
*/
223248
static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
224249
{
225-
drm_mode_object_unreference(&fb->base);
250+
drm_framebuffer_put(fb);
226251
}
227252

228253
/**
@@ -248,9 +273,9 @@ static inline void drm_framebuffer_assign(struct drm_framebuffer **p,
248273
struct drm_framebuffer *fb)
249274
{
250275
if (fb)
251-
drm_framebuffer_reference(fb);
276+
drm_framebuffer_get(fb);
252277
if (*p)
253-
drm_framebuffer_unreference(*p);
278+
drm_framebuffer_put(*p);
254279
*p = fb;
255280
}
256281

‎scripts/coccinelle/api/drm-get-put.cocci‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ expression object;
2626
|
2727
- drm_connector_unreference(object)
2828
+ drm_connector_put(object)
29+
|
30+
- drm_framebuffer_reference(object)
31+
+ drm_framebuffer_get(object)
32+
|
33+
- drm_framebuffer_unreference(object)
34+
+ drm_framebuffer_put(object)
2935
)
3036

3137
@r depends on report@
@@ -41,6 +47,10 @@ drm_mode_object_reference@p(object)
4147
drm_connector_unreference@p(object)
4248
|
4349
drm_connector_reference@p(object)
50+
|
51+
drm_framebuffer_unreference@p(object)
52+
|
53+
drm_framebuffer_reference@p(object)
4454
)
4555

4656
@script:python depends on report@

0 commit comments

Comments
 (0)