]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm: Introduce drm_property_blob_{get,put}()
authorThierry Reding <treding@nvidia.com>
Tue, 28 Feb 2017 14:46:42 +0000 (15:46 +0100)
committerThierry Reding <treding@nvidia.com>
Tue, 28 Feb 2017 15:16:46 +0000 (16:16 +0100)
For consistency with other reference counting APIs in the kernel, add
drm_property_blob_get() and drm_property_blob_put() to reference count
DRM blob properties.

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-7-thierry.reding@gmail.com
drivers/gpu/drm/drm_atomic.c
drivers/gpu/drm/drm_atomic_helper.c
drivers/gpu/drm/drm_mode_config.c
drivers/gpu/drm/drm_property.c
include/drm/drm_property.h
scripts/coccinelle/api/drm-get-put.cocci

index 38cf374e7552efba1eafde909cb389f9c79be992..aea8bbad16744d2a440e2d4090697eae229f252b 100644 (file)
@@ -324,7 +324,7 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
        if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0)
                return 0;
 
-       drm_property_unreference_blob(state->mode_blob);
+       drm_property_blob_put(state->mode_blob);
        state->mode_blob = NULL;
 
        if (mode) {
@@ -370,7 +370,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
        if (blob == state->mode_blob)
                return 0;
 
-       drm_property_unreference_blob(state->mode_blob);
+       drm_property_blob_put(state->mode_blob);
        state->mode_blob = NULL;
 
        memset(&state->mode, 0, sizeof(state->mode));
@@ -382,7 +382,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
                                            blob->data))
                        return -EINVAL;
 
-               state->mode_blob = drm_property_reference_blob(blob);
+               state->mode_blob = drm_property_blob_get(blob);
                state->enable = true;
                DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
                                 state->mode.name, state);
@@ -415,9 +415,9 @@ drm_atomic_replace_property_blob(struct drm_property_blob **blob,
        if (old_blob == new_blob)
                return;
 
-       drm_property_unreference_blob(old_blob);
+       drm_property_blob_put(old_blob);
        if (new_blob)
-               drm_property_reference_blob(new_blob);
+               drm_property_blob_get(new_blob);
        *blob = new_blob;
        *replaced = true;
 
@@ -439,13 +439,13 @@ drm_atomic_replace_property_blob_from_id(struct drm_crtc *crtc,
                        return -EINVAL;
 
                if (expected_size > 0 && expected_size != new_blob->length) {
-                       drm_property_unreference_blob(new_blob);
+                       drm_property_blob_put(new_blob);
                        return -EINVAL;
                }
        }
 
        drm_atomic_replace_property_blob(blob, new_blob, replaced);
-       drm_property_unreference_blob(new_blob);
+       drm_property_blob_put(new_blob);
 
        return 0;
 }
@@ -480,7 +480,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
                struct drm_property_blob *mode =
                        drm_property_lookup_blob(dev, val);
                ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
-               drm_property_unreference_blob(mode);
+               drm_property_blob_put(mode);
                return ret;
        } else if (property == config->degamma_lut_property) {
                ret = drm_atomic_replace_property_blob_from_id(crtc,
index 01b2dddbd431c82b62176ae9356b6f14048be302..ffcae3fa94f97a92262b55e248a8a8c068548513 100644 (file)
@@ -3120,13 +3120,13 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
        memcpy(state, crtc->state, sizeof(*state));
 
        if (state->mode_blob)
-               drm_property_reference_blob(state->mode_blob);
+               drm_property_blob_get(state->mode_blob);
        if (state->degamma_lut)
-               drm_property_reference_blob(state->degamma_lut);
+               drm_property_blob_get(state->degamma_lut);
        if (state->ctm)
-               drm_property_reference_blob(state->ctm);
+               drm_property_blob_get(state->ctm);
        if (state->gamma_lut)
-               drm_property_reference_blob(state->gamma_lut);
+               drm_property_blob_get(state->gamma_lut);
        state->mode_changed = false;
        state->active_changed = false;
        state->planes_changed = false;
@@ -3171,10 +3171,10 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
  */
 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
 {
-       drm_property_unreference_blob(state->mode_blob);
-       drm_property_unreference_blob(state->degamma_lut);
-       drm_property_unreference_blob(state->ctm);
-       drm_property_unreference_blob(state->gamma_lut);
+       drm_property_blob_put(state->mode_blob);
+       drm_property_blob_put(state->degamma_lut);
+       drm_property_blob_put(state->ctm);
+       drm_property_blob_put(state->gamma_lut);
 }
 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
 
@@ -3572,7 +3572,7 @@ fail:
                goto backoff;
 
        drm_atomic_state_put(state);
-       drm_property_unreference_blob(blob);
+       drm_property_blob_put(blob);
        return ret;
 
 backoff:
index 20aec165abd7ce67b9535dadac04864f7042a940..37779b9f0c1e6cb648d1b5823664f49fcab5f798 100644 (file)
@@ -444,7 +444,7 @@ void drm_mode_config_cleanup(struct drm_device *dev)
 
        list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
                                 head_global) {
-               drm_property_unreference_blob(blob);
+               drm_property_blob_put(blob);
        }
 
        /*
index 15af0d42e8be37c6bbb7e59d287a0475274996fb..b17959c3e099ae1b3d24145eb01e51416b93e19f 100644 (file)
@@ -587,19 +587,19 @@ drm_property_create_blob(struct drm_device *dev, size_t length,
 EXPORT_SYMBOL(drm_property_create_blob);
 
 /**
- * drm_property_unreference_blob - Unreference a blob property
- * @blob: Pointer to blob property
+ * drm_property_blob_put - release a blob property reference
+ * @blob: DRM blob property
  *
- * Drop a reference on a blob property. May free the object.
+ * Releases a reference to a blob property. May free the object.
  */
-void drm_property_unreference_blob(struct drm_property_blob *blob)
+void drm_property_blob_put(struct drm_property_blob *blob)
 {
        if (!blob)
                return;
 
        drm_mode_object_put(&blob->base);
 }
-EXPORT_SYMBOL(drm_property_unreference_blob);
+EXPORT_SYMBOL(drm_property_blob_put);
 
 void drm_property_destroy_user_blobs(struct drm_device *dev,
                                     struct drm_file *file_priv)
@@ -612,23 +612,23 @@ void drm_property_destroy_user_blobs(struct drm_device *dev,
         */
        list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) {
                list_del_init(&blob->head_file);
-               drm_property_unreference_blob(blob);
+               drm_property_blob_put(blob);
        }
 }
 
 /**
- * drm_property_reference_blob - Take a reference on an existing property
- * @blob: Pointer to blob property
+ * drm_property_blob_get - acquire blob property reference
+ * @blob: DRM blob property
  *
- * Take a new reference on an existing blob property. Returns @blob, which
+ * Acquires a reference to an existing blob property. Returns @blob, which
  * allows this to be used as a shorthand in assignments.
  */
-struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob)
+struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob)
 {
        drm_mode_object_get(&blob->base);
        return blob;
 }
-EXPORT_SYMBOL(drm_property_reference_blob);
+EXPORT_SYMBOL(drm_property_blob_get);
 
 /**
  * drm_property_lookup_blob - look up a blob property and take a reference
@@ -637,7 +637,7 @@ EXPORT_SYMBOL(drm_property_reference_blob);
  *
  * If successful, this takes an additional reference to the blob property.
  * callers need to make sure to eventually unreference the returned property
- * again, using @drm_property_unreference_blob.
+ * again, using drm_property_blob_put().
  *
  * Return:
  * NULL on failure, pointer to the blob on success.
@@ -712,13 +712,13 @@ int drm_property_replace_global_blob(struct drm_device *dev,
                        goto err_created;
        }
 
-       drm_property_unreference_blob(old_blob);
+       drm_property_blob_put(old_blob);
        *replace = new_blob;
 
        return 0;
 
 err_created:
-       drm_property_unreference_blob(new_blob);
+       drm_property_blob_put(new_blob);
        return ret;
 }
 EXPORT_SYMBOL(drm_property_replace_global_blob);
@@ -747,7 +747,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
        }
        out_resp->length = blob->length;
 unref:
-       drm_property_unreference_blob(blob);
+       drm_property_blob_put(blob);
 
        return ret;
 }
@@ -784,7 +784,7 @@ int drm_mode_createblob_ioctl(struct drm_device *dev,
        return 0;
 
 out_blob:
-       drm_property_unreference_blob(blob);
+       drm_property_blob_put(blob);
        return ret;
 }
 
@@ -823,14 +823,14 @@ int drm_mode_destroyblob_ioctl(struct drm_device *dev,
        mutex_unlock(&dev->mode_config.blob_lock);
 
        /* One reference from lookup, and one from the filp. */
-       drm_property_unreference_blob(blob);
-       drm_property_unreference_blob(blob);
+       drm_property_blob_put(blob);
+       drm_property_blob_put(blob);
 
        return 0;
 
 err:
        mutex_unlock(&dev->mode_config.blob_lock);
-       drm_property_unreference_blob(blob);
+       drm_property_blob_put(blob);
 
        return ret;
 }
@@ -908,5 +908,5 @@ void drm_property_change_valid_put(struct drm_property *property,
        if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
                drm_mode_object_put(ref);
        } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
-               drm_property_unreference_blob(obj_to_blob(ref));
+               drm_property_blob_put(obj_to_blob(ref));
 }
index f66fdb47551cea64146b568303d3e164ab47ddde..13e8c17d1c79b0704018e2ccbe32af7b6e2d723d 100644 (file)
@@ -200,9 +200,8 @@ struct drm_property {
  * Blobs are used to store bigger values than what fits directly into the 64
  * bits available for a &drm_property.
  *
- * Blobs are reference counted using drm_property_reference_blob() and
- * drm_property_unreference_blob(). They are created using
- * drm_property_create_blob().
+ * Blobs are reference counted using drm_property_blob_get() and
+ * drm_property_blob_put(). They are created using drm_property_create_blob().
  */
 struct drm_property_blob {
        struct drm_mode_object base;
@@ -274,8 +273,34 @@ int drm_property_replace_global_blob(struct drm_device *dev,
                                     const void *data,
                                     struct drm_mode_object *obj_holds_id,
                                     struct drm_property *prop_holds_id);
-struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
-void drm_property_unreference_blob(struct drm_property_blob *blob);
+struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob);
+void drm_property_blob_put(struct drm_property_blob *blob);
+
+/**
+ * drm_property_reference_blob - acquire a blob property reference
+ * @blob: DRM blob property
+ *
+ * This is a compatibility alias for drm_property_blob_get() and should not be
+ * used by new code.
+ */
+static inline struct drm_property_blob *
+drm_property_reference_blob(struct drm_property_blob *blob)
+{
+       return drm_property_blob_get(blob);
+}
+
+/**
+ * drm_property_unreference_blob - release a blob property reference
+ * @blob: DRM blob property
+ *
+ * This is a compatibility alias for drm_property_blob_put() and should not be
+ * used by new code.
+ */
+static inline void
+drm_property_unreference_blob(struct drm_property_blob *blob)
+{
+       drm_property_blob_put(blob);
+}
 
 /**
  * drm_connector_find - find property object
index 24882547b4d121f875770d9d17b05141faec6077..0c7a9265c07e903b70542644ee0d4a445a49fafe 100644 (file)
@@ -44,6 +44,12 @@ expression object;
 |
 - drm_gem_object_unreference_unlocked(object)
 + drm_gem_object_put_unlocked(object)
+|
+- drm_property_reference_blob(object)
++ drm_property_blob_get(object)
+|
+- drm_property_unreference_blob(object)
++ drm_property_blob_put(object)
 )
 
 @r depends on report@
@@ -71,6 +77,10 @@ drm_gem_object_reference@p(object)
 __drm_gem_object_unreference(object)
 |
 drm_gem_object_unreference_unlocked(object)
+|
+drm_property_unreference_blob@p(object)
+|
+drm_property_reference_blob@p(object)
 )
 
 @script:python depends on report@