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

gpu: host1x: Split up client initalization and registration

In some cases we may need to initialize the host1x client first before
registering it. This commit adds a new helper that will do nothing but
the initialization of the data structure.

At the same time, the initialization is removed from the registration
function. Note, however, that for simplicity we explicitly initialize
the client when the host1x_client_register() function is called, as
opposed to the low-level __host1x_client_register() function. This
allows existing callers to remain unchanged.

Signed-off-by: Thierry Reding <treding@nvidia.com>

+48 -12
+24 -6
drivers/gpu/host1x/bus.c
··· 736 736 EXPORT_SYMBOL(host1x_driver_unregister); 737 737 738 738 /** 739 + * __host1x_client_init() - initialize a host1x client 740 + * @client: host1x client 741 + * @key: lock class key for the client-specific mutex 742 + */ 743 + void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key) 744 + { 745 + INIT_LIST_HEAD(&client->list); 746 + __mutex_init(&client->lock, "host1x client lock", key); 747 + client->usecount = 0; 748 + } 749 + EXPORT_SYMBOL(__host1x_client_init); 750 + 751 + /** 752 + * host1x_client_exit() - uninitialize a host1x client 753 + * @client: host1x client 754 + */ 755 + void host1x_client_exit(struct host1x_client *client) 756 + { 757 + mutex_destroy(&client->lock); 758 + } 759 + EXPORT_SYMBOL(host1x_client_exit); 760 + 761 + /** 739 762 * __host1x_client_register() - register a host1x client 740 763 * @client: host1x client 741 764 * @key: lock class key for the client-specific mutex ··· 770 747 * device and call host1x_device_init(), which will in turn call each client's 771 748 * &host1x_client_ops.init implementation. 772 749 */ 773 - int __host1x_client_register(struct host1x_client *client, 774 - struct lock_class_key *key) 750 + int __host1x_client_register(struct host1x_client *client) 775 751 { 776 752 struct host1x *host1x; 777 753 int err; 778 - 779 - INIT_LIST_HEAD(&client->list); 780 - __mutex_init(&client->lock, "host1x client lock", key); 781 - client->usecount = 0; 782 754 783 755 mutex_lock(&devices_lock); 784 756
+24 -6
include/linux/host1x.h
··· 332 332 int host1x_device_init(struct host1x_device *device); 333 333 int host1x_device_exit(struct host1x_device *device); 334 334 335 - int __host1x_client_register(struct host1x_client *client, 336 - struct lock_class_key *key); 337 - #define host1x_client_register(class) \ 338 - ({ \ 339 - static struct lock_class_key __key; \ 340 - __host1x_client_register(class, &__key); \ 335 + void __host1x_client_init(struct host1x_client *client, struct lock_class_key *key); 336 + void host1x_client_exit(struct host1x_client *client); 337 + 338 + #define host1x_client_init(client) \ 339 + ({ \ 340 + static struct lock_class_key __key; \ 341 + __host1x_client_init(client, &__key); \ 342 + }) 343 + 344 + int __host1x_client_register(struct host1x_client *client); 345 + 346 + /* 347 + * Note that this wrapper calls __host1x_client_init() for compatibility 348 + * with existing callers. Callers that want to separately initialize and 349 + * register a host1x client must first initialize using either of the 350 + * __host1x_client_init() or host1x_client_init() functions and then use 351 + * the low-level __host1x_client_register() function to avoid the client 352 + * getting reinitialized. 353 + */ 354 + #define host1x_client_register(client) \ 355 + ({ \ 356 + static struct lock_class_key __key; \ 357 + __host1x_client_init(client, &__key); \ 358 + __host1x_client_register(client); \ 341 359 }) 342 360 343 361 int host1x_client_unregister(struct host1x_client *client);