Skip to content

Commit 020a218

Browse files
committed
drm: Introduce drm_mode_object_{get,put}()
For consistency with other reference counting APIs in the kernel, add drm_mode_object_get() and drm_mode_object_put() to reference count DRM mode objects. 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. A semantic patch is provided that can be used to convert all drivers to the 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-3-thierry.reding@gmail.com
1 parent 2135ea7 commit 020a218

5 files changed

Lines changed: 95 additions & 29 deletions

File tree

‎drivers/gpu/drm/drm_atomic.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,13 +2238,13 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
22382238
}
22392239

22402240
if (!obj->properties) {
2241-
drm_mode_object_unreference(obj);
2241+
drm_mode_object_put(obj);
22422242
ret = -ENOENT;
22432243
goto out;
22442244
}
22452245

22462246
if (get_user(count_props, count_props_ptr + copied_objs)) {
2247-
drm_mode_object_unreference(obj);
2247+
drm_mode_object_put(obj);
22482248
ret = -EFAULT;
22492249
goto out;
22502250
}
@@ -2257,29 +2257,29 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
22572257
struct drm_property *prop;
22582258

22592259
if (get_user(prop_id, props_ptr + copied_props)) {
2260-
drm_mode_object_unreference(obj);
2260+
drm_mode_object_put(obj);
22612261
ret = -EFAULT;
22622262
goto out;
22632263
}
22642264

22652265
prop = drm_mode_obj_find_prop_id(obj, prop_id);
22662266
if (!prop) {
2267-
drm_mode_object_unreference(obj);
2267+
drm_mode_object_put(obj);
22682268
ret = -ENOENT;
22692269
goto out;
22702270
}
22712271

22722272
if (copy_from_user(&prop_value,
22732273
prop_values_ptr + copied_props,
22742274
sizeof(prop_value))) {
2275-
drm_mode_object_unreference(obj);
2275+
drm_mode_object_put(obj);
22762276
ret = -EFAULT;
22772277
goto out;
22782278
}
22792279

22802280
ret = atomic_set_prop(state, obj, prop, prop_value);
22812281
if (ret) {
2282-
drm_mode_object_unreference(obj);
2282+
drm_mode_object_put(obj);
22832283
goto out;
22842284
}
22852285

@@ -2292,7 +2292,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
22922292
plane_mask |= (1 << drm_plane_index(plane));
22932293
plane->old_fb = plane->fb;
22942294
}
2295-
drm_mode_object_unreference(obj);
2295+
drm_mode_object_put(obj);
22962296
}
22972297

22982298
ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,

‎drivers/gpu/drm/drm_mode_object.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,
133133
*
134134
* This function is used to look up a modeset object. It will acquire a
135135
* reference for reference counted objects. This reference must be dropped again
136-
* by callind drm_mode_object_unreference().
136+
* by callind drm_mode_object_put().
137137
*/
138138
struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
139139
uint32_t id, uint32_t type)
@@ -146,38 +146,38 @@ struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
146146
EXPORT_SYMBOL(drm_mode_object_find);
147147

148148
/**
149-
* drm_mode_object_unreference - decr the object refcnt
150-
* @obj: mode_object
149+
* drm_mode_object_put - release a mode object reference
150+
* @obj: DRM mode object
151151
*
152152
* This function decrements the object's refcount if it is a refcounted modeset
153153
* object. It is a no-op on any other object. This is used to drop references
154-
* acquired with drm_mode_object_reference().
154+
* acquired with drm_mode_object_get().
155155
*/
156-
void drm_mode_object_unreference(struct drm_mode_object *obj)
156+
void drm_mode_object_put(struct drm_mode_object *obj)
157157
{
158158
if (obj->free_cb) {
159159
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
160160
kref_put(&obj->refcount, obj->free_cb);
161161
}
162162
}
163-
EXPORT_SYMBOL(drm_mode_object_unreference);
163+
EXPORT_SYMBOL(drm_mode_object_put);
164164

165165
/**
166-
* drm_mode_object_reference - incr the object refcnt
167-
* @obj: mode_object
166+
* drm_mode_object_get - acquire a mode object reference
167+
* @obj: DRM mode object
168168
*
169169
* This function increments the object's refcount if it is a refcounted modeset
170170
* object. It is a no-op on any other object. References should be dropped again
171-
* by calling drm_mode_object_unreference().
171+
* by calling drm_mode_object_put().
172172
*/
173-
void drm_mode_object_reference(struct drm_mode_object *obj)
173+
void drm_mode_object_get(struct drm_mode_object *obj)
174174
{
175175
if (obj->free_cb) {
176176
DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
177177
kref_get(&obj->refcount);
178178
}
179179
}
180-
EXPORT_SYMBOL(drm_mode_object_reference);
180+
EXPORT_SYMBOL(drm_mode_object_get);
181181

182182
/**
183183
* drm_object_attach_property - attach a property to a modeset object
@@ -363,7 +363,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
363363
&arg->count_props);
364364

365365
out_unref:
366-
drm_mode_object_unreference(obj);
366+
drm_mode_object_put(obj);
367367
out:
368368
drm_modeset_unlock_all(dev);
369369
return ret;
@@ -428,7 +428,7 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
428428
drm_property_change_valid_put(property, ref);
429429

430430
out_unref:
431-
drm_mode_object_unreference(arg_obj);
431+
drm_mode_object_put(arg_obj);
432432
out:
433433
drm_modeset_unlock_all(dev);
434434
return ret;

‎drivers/gpu/drm/drm_property.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ void drm_property_unreference_blob(struct drm_property_blob *blob)
597597
if (!blob)
598598
return;
599599

600-
drm_mode_object_unreference(&blob->base);
600+
drm_mode_object_put(&blob->base);
601601
}
602602
EXPORT_SYMBOL(drm_property_unreference_blob);
603603

@@ -625,7 +625,7 @@ void drm_property_destroy_user_blobs(struct drm_device *dev,
625625
*/
626626
struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob)
627627
{
628-
drm_mode_object_reference(&blob->base);
628+
drm_mode_object_get(&blob->base);
629629
return blob;
630630
}
631631
EXPORT_SYMBOL(drm_property_reference_blob);
@@ -906,7 +906,7 @@ void drm_property_change_valid_put(struct drm_property *property,
906906
return;
907907

908908
if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
909-
drm_mode_object_unreference(ref);
909+
drm_mode_object_put(ref);
910910
} else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
911911
drm_property_unreference_blob(obj_to_blob(ref));
912912
}

‎include/drm/drm_mode_object.h‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ struct drm_device;
4545
* drm_object_attach_property() before the object is visible to userspace.
4646
*
4747
* - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it
48-
* provides reference counting through drm_mode_object_reference() and
49-
* drm_mode_object_unreference(). This is used by &drm_framebuffer,
50-
* &drm_connector and &drm_property_blob. These objects provide specialized
51-
* reference counting wrappers.
48+
* provides reference counting through drm_mode_object_get() and
49+
* drm_mode_object_put(). This is used by &drm_framebuffer, &drm_connector
50+
* and &drm_property_blob. These objects provide specialized reference
51+
* counting wrappers.
5252
*/
5353
struct drm_mode_object {
5454
uint32_t id;
@@ -114,8 +114,32 @@ struct drm_object_properties {
114114

115115
struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
116116
uint32_t id, uint32_t type);
117-
void drm_mode_object_reference(struct drm_mode_object *obj);
118-
void drm_mode_object_unreference(struct drm_mode_object *obj);
117+
void drm_mode_object_get(struct drm_mode_object *obj);
118+
void drm_mode_object_put(struct drm_mode_object *obj);
119+
120+
/**
121+
* drm_mode_object_reference - acquire a mode object reference
122+
* @obj: DRM mode object
123+
*
124+
* This is a compatibility alias for drm_mode_object_get() and should not be
125+
* used by new code.
126+
*/
127+
static inline void drm_mode_object_reference(struct drm_mode_object *obj)
128+
{
129+
drm_mode_object_get(obj);
130+
}
131+
132+
/**
133+
* drm_mode_object_unreference - release a mode object reference
134+
* @obj: DRM mode object
135+
*
136+
* This is a compatibility alias for drm_mode_object_put() and should not be
137+
* used by new code.
138+
*/
139+
static inline void drm_mode_object_unreference(struct drm_mode_object *obj)
140+
{
141+
drm_mode_object_put(obj);
142+
}
119143

120144
int drm_object_property_set_value(struct drm_mode_object *obj,
121145
struct drm_property *property,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
///
2+
/// Use drm_*_get() and drm_*_put() helpers instead of drm_*_reference() and
3+
/// drm_*_unreference() helpers.
4+
///
5+
// Confidence: High
6+
// Copyright: (C) 2017 NVIDIA Corporation
7+
// Options: --no-includes --include-headers
8+
//
9+
10+
virtual patch
11+
virtual report
12+
13+
@depends on patch@
14+
expression object;
15+
@@
16+
17+
(
18+
- drm_mode_object_reference(object)
19+
+ drm_mode_object_get(object)
20+
|
21+
- drm_mode_object_unreference(object)
22+
+ drm_mode_object_put(object)
23+
)
24+
25+
@r depends on report@
26+
expression object;
27+
position p;
28+
@@
29+
30+
(
31+
drm_mode_object_unreference@p(object)
32+
|
33+
drm_mode_object_reference@p(object)
34+
)
35+
36+
@script:python depends on report@
37+
object << r.object;
38+
p << r.p;
39+
@@
40+
41+
msg="WARNING: use get/put helpers to reference and dereference %s" % (object)
42+
coccilib.report.print_report(p[0], msg)

0 commit comments

Comments
 (0)