From 360a8779d96c7c592ee79d035afe9bdf05695204 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Wed, 12 Nov 2014 15:17:54 -0600 Subject: [PATCH] greybus: op_cycle doesn't need to be atomic We can update a connection's operation id counter under spinlock, and thereby avoid the need to maintain it in an atomic variable. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/connection.c | 6 ------ drivers/staging/greybus/connection.h | 4 +--- drivers/staging/greybus/operation.c | 15 ++++++++------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 377ac7d..bb26157 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -210,7 +210,6 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface, INIT_LIST_HEAD(&connection->operations); INIT_LIST_HEAD(&connection->pending); - atomic_set(&connection->op_cycle, 0); return connection; } @@ -244,11 +243,6 @@ void gb_connection_destroy(struct gb_connection *connection) device_del(&connection->dev); } -u16 gb_connection_operation_id(struct gb_connection *connection) -{ - return (u16)(atomic_inc_return(&connection->op_cycle) & (int)U16_MAX); -} - void gb_connection_err(struct gb_connection *connection, const char *fmt, ...) { struct va_format vaf; diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index 861e066..3aa8695 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -35,9 +35,9 @@ struct gb_connection { enum gb_connection_state state; + u16 op_cycle; struct list_head operations; struct list_head pending; /* awaiting reponse */ - atomic_t op_cycle; void *private; }; @@ -53,8 +53,6 @@ void gb_connection_exit(struct gb_connection *connection); struct gb_connection *gb_hd_connection_find(struct greybus_host_device *hd, u16 cport_id); -u16 gb_connection_operation_id(struct gb_connection *connection); - __printf(2, 3) void gb_connection_err(struct gb_connection *connection, const char *fmt, ...); diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index cc49210..72e5ef9 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -61,17 +61,18 @@ static void gb_pending_operation_insert(struct gb_operation *operation) struct gb_connection *connection = operation->connection; struct gb_operation_msg_hdr *header; - /* Assign the operation's id, and store it in the header of - * the request message header. + /* + * Assign the operation's id and move it into its + * connection's pending list. */ - operation->id = gb_connection_operation_id(connection); - header = operation->request->transfer_buffer; - header->id = cpu_to_le16(operation->id); - - /* Insert the operation into its connection's pending list */ spin_lock_irq(&gb_operations_lock); + operation->id = ++connection->op_cycle; list_move_tail(&operation->links, &connection->pending); spin_unlock_irq(&gb_operations_lock); + + /* Store the operation id in the request header */ + header = operation->request->transfer_buffer; + header->id = cpu_to_le16(operation->id); } static void gb_pending_operation_remove(struct gb_operation *operation) -- 2.7.4