Skip to content

Commit 0cfe5a6

Browse files
committed
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 <[email protected]>
1 parent 73a395c commit 0cfe5a6

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

drivers/gpu/host1x/bus.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,29 @@ void host1x_driver_unregister(struct host1x_driver *driver)
735735
}
736736
EXPORT_SYMBOL(host1x_driver_unregister);
737737

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+
738761
/**
739762
* __host1x_client_register() - register a host1x client
740763
* @client: host1x client
@@ -747,16 +770,11 @@ EXPORT_SYMBOL(host1x_driver_unregister);
747770
* device and call host1x_device_init(), which will in turn call each client's
748771
* &host1x_client_ops.init implementation.
749772
*/
750-
int __host1x_client_register(struct host1x_client *client,
751-
struct lock_class_key *key)
773+
int __host1x_client_register(struct host1x_client *client)
752774
{
753775
struct host1x *host1x;
754776
int err;
755777

756-
INIT_LIST_HEAD(&client->list);
757-
__mutex_init(&client->lock, "host1x client lock", key);
758-
client->usecount = 0;
759-
760778
mutex_lock(&devices_lock);
761779

762780
list_for_each_entry(host1x, &devices, list) {

include/linux/host1x.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,30 @@ static inline struct host1x_device *to_host1x_device(struct device *dev)
332332
int host1x_device_init(struct host1x_device *device);
333333
int host1x_device_exit(struct host1x_device *device);
334334

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); \
341359
})
342360

343361
int host1x_client_unregister(struct host1x_client *client);

0 commit comments

Comments
 (0)