Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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

+78 -43
+8 -8
drivers/gpu/drm/drm_atomic.c
··· 324 324 if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0) 325 325 return 0; 326 326 327 - drm_property_unreference_blob(state->mode_blob); 327 + drm_property_blob_put(state->mode_blob); 328 328 state->mode_blob = NULL; 329 329 330 330 if (mode) { ··· 370 370 if (blob == state->mode_blob) 371 371 return 0; 372 372 373 - drm_property_unreference_blob(state->mode_blob); 373 + drm_property_blob_put(state->mode_blob); 374 374 state->mode_blob = NULL; 375 375 376 376 memset(&state->mode, 0, sizeof(state->mode)); ··· 382 382 blob->data)) 383 383 return -EINVAL; 384 384 385 - state->mode_blob = drm_property_reference_blob(blob); 385 + state->mode_blob = drm_property_blob_get(blob); 386 386 state->enable = true; 387 387 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", 388 388 state->mode.name, state); ··· 415 415 if (old_blob == new_blob) 416 416 return; 417 417 418 - drm_property_unreference_blob(old_blob); 418 + drm_property_blob_put(old_blob); 419 419 if (new_blob) 420 - drm_property_reference_blob(new_blob); 420 + drm_property_blob_get(new_blob); 421 421 *blob = new_blob; 422 422 *replaced = true; 423 423 ··· 439 439 return -EINVAL; 440 440 441 441 if (expected_size > 0 && expected_size != new_blob->length) { 442 - drm_property_unreference_blob(new_blob); 442 + drm_property_blob_put(new_blob); 443 443 return -EINVAL; 444 444 } 445 445 } 446 446 447 447 drm_atomic_replace_property_blob(blob, new_blob, replaced); 448 - drm_property_unreference_blob(new_blob); 448 + drm_property_blob_put(new_blob); 449 449 450 450 return 0; 451 451 } ··· 480 480 struct drm_property_blob *mode = 481 481 drm_property_lookup_blob(dev, val); 482 482 ret = drm_atomic_set_mode_prop_for_crtc(state, mode); 483 - drm_property_unreference_blob(mode); 483 + drm_property_blob_put(mode); 484 484 return ret; 485 485 } else if (property == config->degamma_lut_property) { 486 486 ret = drm_atomic_replace_property_blob_from_id(crtc,
+9 -9
drivers/gpu/drm/drm_atomic_helper.c
··· 3120 3120 memcpy(state, crtc->state, sizeof(*state)); 3121 3121 3122 3122 if (state->mode_blob) 3123 - drm_property_reference_blob(state->mode_blob); 3123 + drm_property_blob_get(state->mode_blob); 3124 3124 if (state->degamma_lut) 3125 - drm_property_reference_blob(state->degamma_lut); 3125 + drm_property_blob_get(state->degamma_lut); 3126 3126 if (state->ctm) 3127 - drm_property_reference_blob(state->ctm); 3127 + drm_property_blob_get(state->ctm); 3128 3128 if (state->gamma_lut) 3129 - drm_property_reference_blob(state->gamma_lut); 3129 + drm_property_blob_get(state->gamma_lut); 3130 3130 state->mode_changed = false; 3131 3131 state->active_changed = false; 3132 3132 state->planes_changed = false; ··· 3171 3171 */ 3172 3172 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) 3173 3173 { 3174 - drm_property_unreference_blob(state->mode_blob); 3175 - drm_property_unreference_blob(state->degamma_lut); 3176 - drm_property_unreference_blob(state->ctm); 3177 - drm_property_unreference_blob(state->gamma_lut); 3174 + drm_property_blob_put(state->mode_blob); 3175 + drm_property_blob_put(state->degamma_lut); 3176 + drm_property_blob_put(state->ctm); 3177 + drm_property_blob_put(state->gamma_lut); 3178 3178 } 3179 3179 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); 3180 3180 ··· 3572 3572 goto backoff; 3573 3573 3574 3574 drm_atomic_state_put(state); 3575 - drm_property_unreference_blob(blob); 3575 + drm_property_blob_put(blob); 3576 3576 return ret; 3577 3577 3578 3578 backoff:
+1 -1
drivers/gpu/drm/drm_mode_config.c
··· 444 444 445 445 list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, 446 446 head_global) { 447 - drm_property_unreference_blob(blob); 447 + drm_property_blob_put(blob); 448 448 } 449 449 450 450 /*
+20 -20
drivers/gpu/drm/drm_property.c
··· 587 587 EXPORT_SYMBOL(drm_property_create_blob); 588 588 589 589 /** 590 - * drm_property_unreference_blob - Unreference a blob property 591 - * @blob: Pointer to blob property 590 + * drm_property_blob_put - release a blob property reference 591 + * @blob: DRM blob property 592 592 * 593 - * Drop a reference on a blob property. May free the object. 593 + * Releases a reference to a blob property. May free the object. 594 594 */ 595 - void drm_property_unreference_blob(struct drm_property_blob *blob) 595 + void drm_property_blob_put(struct drm_property_blob *blob) 596 596 { 597 597 if (!blob) 598 598 return; 599 599 600 600 drm_mode_object_put(&blob->base); 601 601 } 602 - EXPORT_SYMBOL(drm_property_unreference_blob); 602 + EXPORT_SYMBOL(drm_property_blob_put); 603 603 604 604 void drm_property_destroy_user_blobs(struct drm_device *dev, 605 605 struct drm_file *file_priv) ··· 612 612 */ 613 613 list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) { 614 614 list_del_init(&blob->head_file); 615 - drm_property_unreference_blob(blob); 615 + drm_property_blob_put(blob); 616 616 } 617 617 } 618 618 619 619 /** 620 - * drm_property_reference_blob - Take a reference on an existing property 621 - * @blob: Pointer to blob property 620 + * drm_property_blob_get - acquire blob property reference 621 + * @blob: DRM blob property 622 622 * 623 - * Take a new reference on an existing blob property. Returns @blob, which 623 + * Acquires a reference to an existing blob property. Returns @blob, which 624 624 * allows this to be used as a shorthand in assignments. 625 625 */ 626 - struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob) 626 + struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob) 627 627 { 628 628 drm_mode_object_get(&blob->base); 629 629 return blob; 630 630 } 631 - EXPORT_SYMBOL(drm_property_reference_blob); 631 + EXPORT_SYMBOL(drm_property_blob_get); 632 632 633 633 /** 634 634 * drm_property_lookup_blob - look up a blob property and take a reference ··· 637 637 * 638 638 * If successful, this takes an additional reference to the blob property. 639 639 * callers need to make sure to eventually unreference the returned property 640 - * again, using @drm_property_unreference_blob. 640 + * again, using drm_property_blob_put(). 641 641 * 642 642 * Return: 643 643 * NULL on failure, pointer to the blob on success. ··· 712 712 goto err_created; 713 713 } 714 714 715 - drm_property_unreference_blob(old_blob); 715 + drm_property_blob_put(old_blob); 716 716 *replace = new_blob; 717 717 718 718 return 0; 719 719 720 720 err_created: 721 - drm_property_unreference_blob(new_blob); 721 + drm_property_blob_put(new_blob); 722 722 return ret; 723 723 } 724 724 EXPORT_SYMBOL(drm_property_replace_global_blob); ··· 747 747 } 748 748 out_resp->length = blob->length; 749 749 unref: 750 - drm_property_unreference_blob(blob); 750 + drm_property_blob_put(blob); 751 751 752 752 return ret; 753 753 } ··· 784 784 return 0; 785 785 786 786 out_blob: 787 - drm_property_unreference_blob(blob); 787 + drm_property_blob_put(blob); 788 788 return ret; 789 789 } 790 790 ··· 823 823 mutex_unlock(&dev->mode_config.blob_lock); 824 824 825 825 /* One reference from lookup, and one from the filp. */ 826 - drm_property_unreference_blob(blob); 827 - drm_property_unreference_blob(blob); 826 + drm_property_blob_put(blob); 827 + drm_property_blob_put(blob); 828 828 829 829 return 0; 830 830 831 831 err: 832 832 mutex_unlock(&dev->mode_config.blob_lock); 833 - drm_property_unreference_blob(blob); 833 + drm_property_blob_put(blob); 834 834 835 835 return ret; 836 836 } ··· 908 908 if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { 909 909 drm_mode_object_put(ref); 910 910 } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) 911 - drm_property_unreference_blob(obj_to_blob(ref)); 911 + drm_property_blob_put(obj_to_blob(ref)); 912 912 }
+30 -5
include/drm/drm_property.h
··· 200 200 * Blobs are used to store bigger values than what fits directly into the 64 201 201 * bits available for a &drm_property. 202 202 * 203 - * Blobs are reference counted using drm_property_reference_blob() and 204 - * drm_property_unreference_blob(). They are created using 205 - * drm_property_create_blob(). 203 + * Blobs are reference counted using drm_property_blob_get() and 204 + * drm_property_blob_put(). They are created using drm_property_create_blob(). 206 205 */ 207 206 struct drm_property_blob { 208 207 struct drm_mode_object base; ··· 273 274 const void *data, 274 275 struct drm_mode_object *obj_holds_id, 275 276 struct drm_property *prop_holds_id); 276 - struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob); 277 - void drm_property_unreference_blob(struct drm_property_blob *blob); 277 + struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob); 278 + void drm_property_blob_put(struct drm_property_blob *blob); 279 + 280 + /** 281 + * drm_property_reference_blob - acquire a blob property reference 282 + * @blob: DRM blob property 283 + * 284 + * This is a compatibility alias for drm_property_blob_get() and should not be 285 + * used by new code. 286 + */ 287 + static inline struct drm_property_blob * 288 + drm_property_reference_blob(struct drm_property_blob *blob) 289 + { 290 + return drm_property_blob_get(blob); 291 + } 292 + 293 + /** 294 + * drm_property_unreference_blob - release a blob property reference 295 + * @blob: DRM blob property 296 + * 297 + * This is a compatibility alias for drm_property_blob_put() and should not be 298 + * used by new code. 299 + */ 300 + static inline void 301 + drm_property_unreference_blob(struct drm_property_blob *blob) 302 + { 303 + drm_property_blob_put(blob); 304 + } 278 305 279 306 /** 280 307 * drm_connector_find - find property object
+10
scripts/coccinelle/api/drm-get-put.cocci
··· 44 44 | 45 45 - drm_gem_object_unreference_unlocked(object) 46 46 + drm_gem_object_put_unlocked(object) 47 + | 48 + - drm_property_reference_blob(object) 49 + + drm_property_blob_get(object) 50 + | 51 + - drm_property_unreference_blob(object) 52 + + drm_property_blob_put(object) 47 53 ) 48 54 49 55 @r depends on report@ ··· 77 71 __drm_gem_object_unreference(object) 78 72 | 79 73 drm_gem_object_unreference_unlocked(object) 74 + | 75 + drm_property_unreference_blob@p(object) 76 + | 77 + drm_property_reference_blob@p(object) 80 78 ) 81 79 82 80 @script:python depends on report@