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
286 spin_lock_irqsave(&drm_minor_lock, flags);286 spin_lock_irqsave(&drm_minor_lock, flags);
287 minor = idr_find(&drm_minors_idr, minor_id);287 minor = idr_find(&drm_minors_idr, minor_id);
288 if (minor)288 if (minor)
289 drm_dev_ref(minor->dev);289 drm_dev_get(minor->dev);
290 spin_unlock_irqrestore(&drm_minor_lock, flags);290 spin_unlock_irqrestore(&drm_minor_lock, flags);
291 291
292 if (!minor) {292 if (!minor) {
293 return ERR_PTR(-ENODEV);293 return ERR_PTR(-ENODEV);
294 } else if (drm_dev_is_unplugged(minor->dev)) {294 } else if (drm_dev_is_unplugged(minor->dev)) {
295 drm_dev_unref(minor->dev);295 drm_dev_put(minor->dev);
296 return ERR_PTR(-ENODEV);296 return ERR_PTR(-ENODEV);
297 }297 }
298 298
@@ -301,7 +301,7 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id) · 2 unmodified lines
301 301
302void drm_minor_release(struct drm_minor *minor)302void drm_minor_release(struct drm_minor *minor)
303{303{
304 drm_dev_unref(minor->dev);304 drm_dev_put(minor->dev);
305}305}
306 306
307/**307/**
@@ -326,11 +326,11 @@ void drm_minor_release(struct drm_minor *minor) · 18 unmodified lines
326 * When cleaning up a device instance everything needs to be done in reverse:326 * When cleaning up a device instance everything needs to be done in reverse:
327 * First unpublish the device instance with drm_dev_unregister(). Then clean up327 * First unpublish the device instance with drm_dev_unregister(). Then clean up
328 * any other resources allocated at device initialization and drop the driver's328 * 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().
330 *330 *
331 * Note that the lifetime rules for &drm_device instance has still a lot of331 * Note that the lifetime rules for &drm_device instance has still a lot of
332 * historical baggage. Hence use the reference counting provided by332 * 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.
334 *334 *
335 * It is recommended that drivers embed &struct drm_device into their own device335 * It is recommended that drivers embed &struct drm_device into their own device
336 * structure, which is supported through drm_dev_init().336 * structure, which is supported through drm_dev_init().
@@ -345,7 +345,7 @@ void drm_minor_release(struct drm_minor *minor) · 8 unmodified lines
345 * Cleans up all DRM device, calling drm_lastclose().345 * Cleans up all DRM device, calling drm_lastclose().
346 *346 *
347 * Note: Use of this function is deprecated. It will eventually go away347 * Note: Use of this function is deprecated. It will eventually go away
348 * completely. Please use drm_dev_unregister() and drm_dev_unref() explicitly348 * completely. Please use drm_dev_unregister() and drm_dev_put() explicitly
349 * instead to make sure that the device isn't userspace accessible any more349 * instead to make sure that the device isn't userspace accessible any more
350 * while teardown is in progress, ensuring that userspace can't access an350 * while teardown is in progress, ensuring that userspace can't access an
351 * inconsistent state.351 * inconsistent state.
@@ -360,7 +360,7 @@ void drm_put_dev(struct drm_device *dev) · 8 unmodified lines
360 }360 }
361 361
362 drm_dev_unregister(dev);362 drm_dev_unregister(dev);
363 drm_dev_unref(dev);363 drm_dev_put(dev);
364}364}
365EXPORT_SYMBOL(drm_put_dev);365EXPORT_SYMBOL(drm_put_dev);
366 366
@@ -386,7 +386,7 @@ void drm_dev_unplug(struct drm_device *dev) · 19 unmodified lines
386 mutex_lock(&drm_global_mutex);386 mutex_lock(&drm_global_mutex);
387 drm_device_set_unplugged(dev);387 drm_device_set_unplugged(dev);
388 if (dev->open_count == 0)388 if (dev->open_count == 0)
389 drm_dev_unref(dev);389 drm_dev_put(dev);
390 mutex_unlock(&drm_global_mutex);390 mutex_unlock(&drm_global_mutex);
391}391}
392EXPORT_SYMBOL(drm_dev_unplug);392EXPORT_SYMBOL(drm_dev_unplug);
@@ -475,8 +475,8 @@ static void drm_fs_inode_free(struct inode *inode) · 82 unmodified lines
475 * initialization sequence to make sure userspace can't access an inconsistent475 * initialization sequence to make sure userspace can't access an inconsistent
476 * state.476 * state.
477 *477 *
478 * The initial ref-count of the object is 1. Use drm_dev_ref() and478 * The initial ref-count of the object is 1. Use drm_dev_get() and
479 * drm_dev_unref() to take and drop further ref-counts.479 * drm_dev_put() to take and drop further ref-counts.
480 *480 *
481 * Note that for purely virtual devices @parent can be NULL.481 * Note that for purely virtual devices @parent can be NULL.
482 *482 *
@@ -626,8 +626,8 @@ EXPORT_SYMBOL(drm_dev_fini); · 143 unmodified lines
626 * initialization sequence to make sure userspace can't access an inconsistent626 * initialization sequence to make sure userspace can't access an inconsistent
627 * state.627 * state.
628 *628 *
629 * The initial ref-count of the object is 1. Use drm_dev_ref() and629 * The initial ref-count of the object is 1. Use drm_dev_get() and
630 * drm_dev_unref() to take and drop further ref-counts.630 * drm_dev_put() to take and drop further ref-counts.
631 *631 *
632 * Note that for purely virtual devices @parent can be NULL.632 * Note that for purely virtual devices @parent can be NULL.
633 *633 *
@@ -670,36 +670,49 @@ static void drm_dev_release(struct kref *ref) · 36 unmodified lines
670}670}
671 671
672/**672/**
673 * drm_dev_ref - Take reference of a DRM device673 * drm_dev_get - Take reference of a DRM device
674 * @dev: device to take reference of or NULL674 * @dev: device to take reference of or NULL
675 *675 *
676 * This increases the ref-count of @dev by one. You *must* already own a676 * 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 reference677 * reference when calling this. Use drm_dev_put() to drop this reference
678 * again.678 * again.
679 *679 *
680 * This function never fails. However, this function does not provide *any*680 * This function never fails. However, this function does not provide *any*
681 * guarantee whether the device is alive or running. It only provides a681 * guarantee whether the device is alive or running. It only provides a
682 * reference to the object and the memory associated with it.682 * reference to the object and the memory associated with it.
683 */683 */
684void drm_dev_ref(struct drm_device *dev)684void drm_dev_get(struct drm_device *dev)
685{685{
686 if (dev)686 if (dev)
687 kref_get(&dev->ref);687 kref_get(&dev->ref);
688}688}
689EXPORT_SYMBOL(drm_dev_ref);689EXPORT_SYMBOL(drm_dev_get);
690 690
691/**691/**
692 * drm_dev_unref - Drop reference of a DRM device692 * drm_dev_put - Drop reference of a DRM device
693 * @dev: device to drop reference of or NULL693 * @dev: device to drop reference of or NULL
694 *694 *
695 * This decreases the ref-count of @dev by one. The device is destroyed if the695 * This decreases the ref-count of @dev by one. The device is destroyed if the
696 * ref-count drops to zero.696 * ref-count drops to zero.
697 */697 */
698void drm_dev_unref(struct drm_device *dev)698void drm_dev_put(struct drm_device *dev)
699{699{
700 if (dev)700 if (dev)
701 kref_put(&dev->ref, drm_dev_release);701 kref_put(&dev->ref, drm_dev_release);
702}702}
703EXPORT_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 */
712void drm_dev_unref(struct drm_device *dev)
713{
714 drm_dev_put(dev);
715}
703EXPORT_SYMBOL(drm_dev_unref);716EXPORT_SYMBOL(drm_dev_unref);
704 717
705static int create_compat_control_link(struct drm_device *dev)718static int create_compat_control_link(struct drm_device *dev)
@@ -839,7 +852,7 @@ EXPORT_SYMBOL(drm_dev_register); · 133 unmodified lines
839 *852 *
840 * Unregister the DRM device from the system. This does the reverse of853 * Unregister the DRM device from the system. This does the reverse of
841 * drm_dev_register() but does not deallocate the device. The caller must call854 * 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.
843 *856 *
844 * A special form of unregistering for hotpluggable devices is drm_dev_unplug(),857 * A special form of unregistering for hotpluggable devices is drm_dev_unplug(),
845 * which can be called while there are still open users of @dev.858 * 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
318 if (IS_ERR(dma_buf))318 if (IS_ERR(dma_buf))
319 return dma_buf;319 return dma_buf;
320 320
321 drm_dev_ref(dev);321 drm_dev_get(dev);
322 drm_gem_object_get(exp_info->priv);322 drm_gem_object_get(exp_info->priv);
323 323
324 return dma_buf;324 return dma_buf;
include/drm/drm_drv.h+3−2
@@ -155,7 +155,7 @@ struct drm_driver { · 154 unmodified lines
155 * reverse order of the initialization. Similarly to the load155 * reverse order of the initialization. Similarly to the load
156 * hook, this handler is deprecated and its usage should be156 * hook, this handler is deprecated and its usage should be
157 * dropped in favor of an open-coded teardown function at the157 * 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()
159 * for the proper way to remove a &struct drm_device.159 * for the proper way to remove a &struct drm_device.
160 *160 *
161 * The unload() hook is called right after unregistering161 * 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
611int drm_dev_register(struct drm_device *dev, unsigned long flags);611int drm_dev_register(struct drm_device *dev, unsigned long flags);
612void drm_dev_unregister(struct drm_device *dev);612void drm_dev_unregister(struct drm_device *dev);
613 613
614void drm_dev_ref(struct drm_device *dev);614void drm_dev_get(struct drm_device *dev);
615void drm_dev_put(struct drm_device *dev);
615void drm_dev_unref(struct drm_device *dev);616void drm_dev_unref(struct drm_device *dev);
616void drm_put_dev(struct drm_device *dev);617void drm_put_dev(struct drm_device *dev);
617void drm_dev_unplug(struct drm_device *dev);618void 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
50|50|
51- drm_property_unreference_blob(object)51- drm_property_unreference_blob(object)
52+ drm_property_blob_put(object)52+ drm_property_blob_put(object)
53|
54- drm_dev_unref(object)
55+ drm_dev_put(object)
53)56)
54 57
55@r depends on report@58@r depends on report@
@@ -81,6 +84,8 @@ drm_gem_object_unreference_unlocked(object) · 25 unmodified lines
81drm_property_unreference_blob@p(object)84drm_property_unreference_blob@p(object)
82|85|
83drm_property_reference_blob@p(object)86drm_property_reference_blob@p(object)
87|
88drm_dev_unref@p(object)
84)89)
85 90
86@script:python depends on report@91@script:python depends on report@