History

drm: introduce drm_dev_{get/put} functions

Reference counting functions in the kernel typically use get/put suffixes. For maintaining coding style consistency, introduce drm_dev_{get/put} functions. All callers of drm_dev_ref() API have been converted in this patch and hence it has been dropped while the drm_dev_unref() API with non-trivial number of users remains for compatibility. The semantic patch scripts/coccinelle/api/drm-get-put.cocci has been updated with the new helper for conversion of drm_dev_unref() to drm_dev_put()

Aishwarya Pant committed 9 years ago

Commit 9a96f551 parent f2a44dd4 files · +41 −22Browse files

Unified · Split

4 files
  1. drivers/gpu/drm/drm_drv.c +32 −19
  2. drivers/gpu/drm/drm_prime.c +1 −1
  3. include/drm/drm_drv.h +3 −2
  4. scripts/coccinelle/api/drm-get-put.cocci +5 −0
drivers/gpu/drm/drm_drv.c+32−19
@@ -286,13 +286,13 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id) · 285 unmodified lines
286286 spin_lock_irqsave(&drm_minor_lock, flags);
287287 minor = idr_find(&drm_minors_idr, minor_id);
288288 if (minor)
289− drm_dev_ref(minor->dev);
289+ drm_dev_get(minor->dev);
290290 spin_unlock_irqrestore(&drm_minor_lock, flags);
291291
292292 if (!minor) {
293293 return ERR_PTR(-ENODEV);
294294 } else if (drm_dev_is_unplugged(minor->dev)) {
295− drm_dev_unref(minor->dev);
295+ drm_dev_put(minor->dev);
296296 return ERR_PTR(-ENODEV);
297297 }
298298
@@ -301,7 +301,7 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id) · 2 unmodified lines
301301
302302 void drm_minor_release(struct drm_minor *minor)
303303 {
304− drm_dev_unref(minor->dev);
304+ drm_dev_put(minor->dev);
305305 }
306306
307307 /**
@@ -326,11 +326,11 @@ void drm_minor_release(struct drm_minor *minor) · 18 unmodified lines
326326 * When cleaning up a device instance everything needs to be done in reverse:
327327 * First unpublish the device instance with drm_dev_unregister(). Then clean up
328328 * any other resources allocated at device initialization and drop the driver's
329− * reference to &drm_device using drm_dev_unref().
329+ * reference to &drm_device using drm_dev_put().
330330 *
331331 * Note that the lifetime rules for &drm_device instance has still a lot of
332332 * historical baggage. Hence use the reference counting provided by
333− * drm_dev_ref() and drm_dev_unref() only carefully.
333+ * drm_dev_get() and drm_dev_put() only carefully.
334334 *
335335 * It is recommended that drivers embed &struct drm_device into their own device
336336 * structure, which is supported through drm_dev_init().
@@ -345,7 +345,7 @@ void drm_minor_release(struct drm_minor *minor) · 8 unmodified lines
345345 * Cleans up all DRM device, calling drm_lastclose().
346346 *
347347 * Note: Use of this function is deprecated. It will eventually go away
348− * completely. Please use drm_dev_unregister() and drm_dev_unref() explicitly
348+ * completely. Please use drm_dev_unregister() and drm_dev_put() explicitly
349349 * instead to make sure that the device isn't userspace accessible any more
350350 * while teardown is in progress, ensuring that userspace can't access an
351351 * inconsistent state.
@@ -360,7 +360,7 @@ void drm_put_dev(struct drm_device *dev) · 8 unmodified lines
360360 }
361361
362362 drm_dev_unregister(dev);
363− drm_dev_unref(dev);
363+ drm_dev_put(dev);
364364 }
365365 EXPORT_SYMBOL(drm_put_dev);
366366
@@ -386,7 +386,7 @@ void drm_dev_unplug(struct drm_device *dev) · 19 unmodified lines
386386 mutex_lock(&drm_global_mutex);
387387 drm_device_set_unplugged(dev);
388388 if (dev->open_count == 0)
389− drm_dev_unref(dev);
389+ drm_dev_put(dev);
390390 mutex_unlock(&drm_global_mutex);
391391 }
392392 EXPORT_SYMBOL(drm_dev_unplug);
@@ -475,8 +475,8 @@ static void drm_fs_inode_free(struct inode *inode) · 82 unmodified lines
475475 * initialization sequence to make sure userspace can't access an inconsistent
476476 * state.
477477 *
478− * The initial ref-count of the object is 1. Use drm_dev_ref() and
479− * drm_dev_unref() to take and drop further ref-counts.
478+ * The initial ref-count of the object is 1. Use drm_dev_get() and
479+ * drm_dev_put() to take and drop further ref-counts.
480480 *
481481 * Note that for purely virtual devices @parent can be NULL.
482482 *
@@ -626,8 +626,8 @@ EXPORT_SYMBOL(drm_dev_fini); · 143 unmodified lines
626626 * initialization sequence to make sure userspace can't access an inconsistent
627627 * state.
628628 *
629− * The initial ref-count of the object is 1. Use drm_dev_ref() and
630− * drm_dev_unref() to take and drop further ref-counts.
629+ * The initial ref-count of the object is 1. Use drm_dev_get() and
630+ * drm_dev_put() to take and drop further ref-counts.
631631 *
632632 * Note that for purely virtual devices @parent can be NULL.
633633 *
@@ -670,36 +670,49 @@ static void drm_dev_release(struct kref *ref) · 36 unmodified lines
670670 }
671671
672672 /**
673− * drm_dev_ref - Take reference of a DRM device
673+ * drm_dev_get - Take reference of a DRM device
674674 * @dev: device to take reference of or NULL
675675 *
676676 * This increases the ref-count of @dev by one. You *must* already own a
677− * reference when calling this. Use drm_dev_unref() to drop this reference
677+ * reference when calling this. Use drm_dev_put() to drop this reference
678678 * again.
679679 *
680680 * This function never fails. However, this function does not provide *any*
681681 * guarantee whether the device is alive or running. It only provides a
682682 * reference to the object and the memory associated with it.
683683 */
684−void drm_dev_ref(struct drm_device *dev)
684+void drm_dev_get(struct drm_device *dev)
685685 {
686686 if (dev)
687687 kref_get(&dev->ref);
688688 }
689−EXPORT_SYMBOL(drm_dev_ref);
689+EXPORT_SYMBOL(drm_dev_get);
690690
691691 /**
692− * drm_dev_unref - Drop reference of a DRM device
692+ * drm_dev_put - Drop reference of a DRM device
693693 * @dev: device to drop reference of or NULL
694694 *
695695 * This decreases the ref-count of @dev by one. The device is destroyed if the
696696 * ref-count drops to zero.
697697 */
698−void drm_dev_unref(struct drm_device *dev)
698+void drm_dev_put(struct drm_device *dev)
699699 {
700700 if (dev)
701701 kref_put(&dev->ref, drm_dev_release);
702702 }
703+EXPORT_SYMBOL(drm_dev_put);
704+
705+/**
706+ * drm_dev_unref - Drop reference of a DRM device
707+ * @dev: device to drop reference of or NULL
708+ *
709+ * This is a compatibility alias for drm_dev_put() and should not be used by new
710+ * code.
711+ */
712+void drm_dev_unref(struct drm_device *dev)
713+{
714+ drm_dev_put(dev);
715+}
703716 EXPORT_SYMBOL(drm_dev_unref);
704717
705718 static int create_compat_control_link(struct drm_device *dev)
@@ -839,7 +852,7 @@ EXPORT_SYMBOL(drm_dev_register); · 133 unmodified lines
839852 *
840853 * Unregister the DRM device from the system. This does the reverse of
841854 * drm_dev_register() but does not deallocate the device. The caller must call
842− * drm_dev_unref() to drop their final reference.
855+ * drm_dev_put() to drop their final reference.
843856 *
844857 * A special form of unregistering for hotpluggable devices is drm_dev_unplug(),
845858 * which can be called while there are still open users of @dev.
drivers/gpu/drm/drm_prime.c+1−1
@@ -318,7 +318,7 @@ struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev, · 317 unmodified lines
318318 if (IS_ERR(dma_buf))
319319 return dma_buf;
320320
321− drm_dev_ref(dev);
321+ drm_dev_get(dev);
322322 drm_gem_object_get(exp_info->priv);
323323
324324 return dma_buf;
include/drm/drm_drv.h+3−2
@@ -155,7 +155,7 @@ struct drm_driver { · 154 unmodified lines
155155 * reverse order of the initialization. Similarly to the load
156156 * hook, this handler is deprecated and its usage should be
157157 * dropped in favor of an open-coded teardown function at the
158− * driver layer. See drm_dev_unregister() and drm_dev_unref()
158+ * driver layer. See drm_dev_unregister() and drm_dev_put()
159159 * for the proper way to remove a &struct drm_device.
160160 *
161161 * The unload() hook is called right after unregistering
@@ -611,7 +611,8 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, · 449 unmodified lines
611611 int drm_dev_register(struct drm_device *dev, unsigned long flags);
612612 void drm_dev_unregister(struct drm_device *dev);
613613
614−void drm_dev_ref(struct drm_device *dev);
614+void drm_dev_get(struct drm_device *dev);
615+void drm_dev_put(struct drm_device *dev);
615616 void drm_dev_unref(struct drm_device *dev);
616617 void drm_put_dev(struct drm_device *dev);
617618 void drm_dev_unplug(struct drm_device *dev);
scripts/coccinelle/api/drm-get-put.cocci+5−0
@@ -50,6 +50,9 @@ expression object; · 49 unmodified lines
5050 |
5151 - drm_property_unreference_blob(object)
5252 + drm_property_blob_put(object)
53+|
54+- drm_dev_unref(object)
55++ drm_dev_put(object)
5356 )
5457
5558 @r depends on report@
@@ -81,6 +84,8 @@ drm_gem_object_unreference_unlocked(object) · 25 unmodified lines
8184 drm_property_unreference_blob@p(object)
8285 |
8386 drm_property_reference_blob@p(object)
87+|
88+drm_dev_unref@p(object)
8489 )
8590
8691 @script:python depends on report@