greybus: op_cycle doesn't need to be atomic
authorAlex Elder <elder@linaro.org>
Wed, 12 Nov 2014 21:17:54 +0000 (15:17 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 Nov 2014 21:11:35 +0000 (13:11 -0800)
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 <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/operation.c

index 377ac7d..bb26157 100644 (file)
@@ -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;
index 861e066..3aa8695 100644 (file)
@@ -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, ...);
 
index cc49210..72e5ef9 100644 (file)
@@ -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)