Commit 6472e509 authored by Thierry Reding's avatar Thierry Reding

drm: Introduce drm_property_blob_{get,put}()

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: default avatarSean Paul <seanpaul@chromium.org>
Acked-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170228144643.5668-7-thierry.reding@gmail.com
parent e6b62714
...@@ -324,7 +324,7 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, ...@@ -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) if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0)
return 0; return 0;
drm_property_unreference_blob(state->mode_blob); drm_property_blob_put(state->mode_blob);
state->mode_blob = NULL; state->mode_blob = NULL;
if (mode) { if (mode) {
...@@ -370,7 +370,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, ...@@ -370,7 +370,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
if (blob == state->mode_blob) if (blob == state->mode_blob)
return 0; return 0;
drm_property_unreference_blob(state->mode_blob); drm_property_blob_put(state->mode_blob);
state->mode_blob = NULL; state->mode_blob = NULL;
memset(&state->mode, 0, sizeof(state->mode)); memset(&state->mode, 0, sizeof(state->mode));
...@@ -382,7 +382,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, ...@@ -382,7 +382,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
blob->data)) blob->data))
return -EINVAL; return -EINVAL;
state->mode_blob = drm_property_reference_blob(blob); state->mode_blob = drm_property_blob_get(blob);
state->enable = true; state->enable = true;
DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
state->mode.name, state); state->mode.name, state);
...@@ -415,9 +415,9 @@ drm_atomic_replace_property_blob(struct drm_property_blob **blob, ...@@ -415,9 +415,9 @@ drm_atomic_replace_property_blob(struct drm_property_blob **blob,
if (old_blob == new_blob) if (old_blob == new_blob)
return; return;
drm_property_unreference_blob(old_blob); drm_property_blob_put(old_blob);
if (new_blob) if (new_blob)
drm_property_reference_blob(new_blob); drm_property_blob_get(new_blob);
*blob = new_blob; *blob = new_blob;
*replaced = true; *replaced = true;
...@@ -439,13 +439,13 @@ drm_atomic_replace_property_blob_from_id(struct drm_crtc *crtc, ...@@ -439,13 +439,13 @@ drm_atomic_replace_property_blob_from_id(struct drm_crtc *crtc,
return -EINVAL; return -EINVAL;
if (expected_size > 0 && expected_size != new_blob->length) { if (expected_size > 0 && expected_size != new_blob->length) {
drm_property_unreference_blob(new_blob); drm_property_blob_put(new_blob);
return -EINVAL; return -EINVAL;
} }
} }
drm_atomic_replace_property_blob(blob, new_blob, replaced); drm_atomic_replace_property_blob(blob, new_blob, replaced);
drm_property_unreference_blob(new_blob); drm_property_blob_put(new_blob);
return 0; return 0;
} }
...@@ -480,7 +480,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, ...@@ -480,7 +480,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
struct drm_property_blob *mode = struct drm_property_blob *mode =
drm_property_lookup_blob(dev, val); drm_property_lookup_blob(dev, val);
ret = drm_atomic_set_mode_prop_for_crtc(state, mode); ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
drm_property_unreference_blob(mode); drm_property_blob_put(mode);
return ret; return ret;
} else if (property == config->degamma_lut_property) { } else if (property == config->degamma_lut_property) {
ret = drm_atomic_replace_property_blob_from_id(crtc, ret = drm_atomic_replace_property_blob_from_id(crtc,
......
...@@ -3120,13 +3120,13 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, ...@@ -3120,13 +3120,13 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
memcpy(state, crtc->state, sizeof(*state)); memcpy(state, crtc->state, sizeof(*state));
if (state->mode_blob) if (state->mode_blob)
drm_property_reference_blob(state->mode_blob); drm_property_blob_get(state->mode_blob);
if (state->degamma_lut) if (state->degamma_lut)
drm_property_reference_blob(state->degamma_lut); drm_property_blob_get(state->degamma_lut);
if (state->ctm) if (state->ctm)
drm_property_reference_blob(state->ctm); drm_property_blob_get(state->ctm);
if (state->gamma_lut) if (state->gamma_lut)
drm_property_reference_blob(state->gamma_lut); drm_property_blob_get(state->gamma_lut);
state->mode_changed = false; state->mode_changed = false;
state->active_changed = false; state->active_changed = false;
state->planes_changed = false; state->planes_changed = false;
...@@ -3171,10 +3171,10 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); ...@@ -3171,10 +3171,10 @@ EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
*/ */
void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
{ {
drm_property_unreference_blob(state->mode_blob); drm_property_blob_put(state->mode_blob);
drm_property_unreference_blob(state->degamma_lut); drm_property_blob_put(state->degamma_lut);
drm_property_unreference_blob(state->ctm); drm_property_blob_put(state->ctm);
drm_property_unreference_blob(state->gamma_lut); drm_property_blob_put(state->gamma_lut);
} }
EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
...@@ -3572,7 +3572,7 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, ...@@ -3572,7 +3572,7 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
goto backoff; goto backoff;
drm_atomic_state_put(state); drm_atomic_state_put(state);
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
return ret; return ret;
backoff: backoff:
......
...@@ -444,7 +444,7 @@ void drm_mode_config_cleanup(struct drm_device *dev) ...@@ -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, list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
head_global) { head_global) {
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
} }
/* /*
......
...@@ -587,19 +587,19 @@ drm_property_create_blob(struct drm_device *dev, size_t length, ...@@ -587,19 +587,19 @@ drm_property_create_blob(struct drm_device *dev, size_t length,
EXPORT_SYMBOL(drm_property_create_blob); EXPORT_SYMBOL(drm_property_create_blob);
/** /**
* drm_property_unreference_blob - Unreference a blob property * drm_property_blob_put - release a blob property reference
* @blob: Pointer to blob property * @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) if (!blob)
return; return;
drm_mode_object_put(&blob->base); 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, void drm_property_destroy_user_blobs(struct drm_device *dev,
struct drm_file *file_priv) struct drm_file *file_priv)
...@@ -612,23 +612,23 @@ void drm_property_destroy_user_blobs(struct drm_device *dev, ...@@ -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_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) {
list_del_init(&blob->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 * drm_property_blob_get - acquire blob property reference
* @blob: Pointer to blob property * @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. * 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); drm_mode_object_get(&blob->base);
return blob; 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 * drm_property_lookup_blob - look up a blob property and take a reference
...@@ -637,7 +637,7 @@ EXPORT_SYMBOL(drm_property_reference_blob); ...@@ -637,7 +637,7 @@ EXPORT_SYMBOL(drm_property_reference_blob);
* *
* If successful, this takes an additional reference to the blob property. * If successful, this takes an additional reference to the blob property.
* callers need to make sure to eventually unreference the returned 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: * Return:
* NULL on failure, pointer to the blob on success. * NULL on failure, pointer to the blob on success.
...@@ -712,13 +712,13 @@ int drm_property_replace_global_blob(struct drm_device *dev, ...@@ -712,13 +712,13 @@ int drm_property_replace_global_blob(struct drm_device *dev,
goto err_created; goto err_created;
} }
drm_property_unreference_blob(old_blob); drm_property_blob_put(old_blob);
*replace = new_blob; *replace = new_blob;
return 0; return 0;
err_created: err_created:
drm_property_unreference_blob(new_blob); drm_property_blob_put(new_blob);
return ret; return ret;
} }
EXPORT_SYMBOL(drm_property_replace_global_blob); EXPORT_SYMBOL(drm_property_replace_global_blob);
...@@ -747,7 +747,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev, ...@@ -747,7 +747,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
} }
out_resp->length = blob->length; out_resp->length = blob->length;
unref: unref:
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
return ret; return ret;
} }
...@@ -784,7 +784,7 @@ int drm_mode_createblob_ioctl(struct drm_device *dev, ...@@ -784,7 +784,7 @@ int drm_mode_createblob_ioctl(struct drm_device *dev,
return 0; return 0;
out_blob: out_blob:
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
return ret; return ret;
} }
...@@ -823,14 +823,14 @@ int drm_mode_destroyblob_ioctl(struct drm_device *dev, ...@@ -823,14 +823,14 @@ int drm_mode_destroyblob_ioctl(struct drm_device *dev,
mutex_unlock(&dev->mode_config.blob_lock); mutex_unlock(&dev->mode_config.blob_lock);
/* One reference from lookup, and one from the filp. */ /* One reference from lookup, and one from the filp. */
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
return 0; return 0;
err: err:
mutex_unlock(&dev->mode_config.blob_lock); mutex_unlock(&dev->mode_config.blob_lock);
drm_property_unreference_blob(blob); drm_property_blob_put(blob);
return ret; return ret;
} }
...@@ -908,5 +908,5 @@ void drm_property_change_valid_put(struct drm_property *property, ...@@ -908,5 +908,5 @@ void drm_property_change_valid_put(struct drm_property *property,
if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
drm_mode_object_put(ref); drm_mode_object_put(ref);
} else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) } 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));
} }
...@@ -200,9 +200,8 @@ struct drm_property { ...@@ -200,9 +200,8 @@ struct drm_property {
* Blobs are used to store bigger values than what fits directly into the 64 * Blobs are used to store bigger values than what fits directly into the 64
* bits available for a &drm_property. * bits available for a &drm_property.
* *
* Blobs are reference counted using drm_property_reference_blob() and * Blobs are reference counted using drm_property_blob_get() and
* drm_property_unreference_blob(). They are created using * drm_property_blob_put(). They are created using drm_property_create_blob().
* drm_property_create_blob().
*/ */
struct drm_property_blob { struct drm_property_blob {
struct drm_mode_object base; struct drm_mode_object base;
...@@ -274,8 +273,34 @@ int drm_property_replace_global_blob(struct drm_device *dev, ...@@ -274,8 +273,34 @@ int drm_property_replace_global_blob(struct drm_device *dev,
const void *data, const void *data,
struct drm_mode_object *obj_holds_id, struct drm_mode_object *obj_holds_id,
struct drm_property *prop_holds_id); struct drm_property *prop_holds_id);
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);
void drm_property_unreference_blob(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 * drm_connector_find - find property object
......
...@@ -44,6 +44,12 @@ expression object; ...@@ -44,6 +44,12 @@ expression object;
| |
- drm_gem_object_unreference_unlocked(object) - drm_gem_object_unreference_unlocked(object)
+ drm_gem_object_put_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@ @r depends on report@
...@@ -71,6 +77,10 @@ drm_gem_object_reference@p(object) ...@@ -71,6 +77,10 @@ drm_gem_object_reference@p(object)
__drm_gem_object_unreference(object) __drm_gem_object_unreference(object)
| |
drm_gem_object_unreference_unlocked(object) drm_gem_object_unreference_unlocked(object)
|
drm_property_unreference_blob@p(object)
|
drm_property_reference_blob@p(object)
) )
@script:python depends on report@ @script:python depends on report@
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment