diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 6503546ccc01..7fbfcdc22307 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -192,7 +192,6 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface, spin_unlock_irq(&gb_connections_lock); INIT_LIST_HEAD(&connection->operations); - INIT_LIST_HEAD(&connection->pending); return connection; } diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index 8cde114f5ac2..035fced12edc 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -37,7 +37,6 @@ struct gb_connection { u16 op_cycle; struct list_head operations; - struct list_head pending; /* awaiting response */ void *private; }; diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index c0e206db9ed7..6ed1d479b117 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -144,44 +144,14 @@ int gb_operation_result(struct gb_operation *operation) return result; } -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 move it into its - * connection's pending list. Zero is a reserved operation - * id. - */ - spin_lock_irq(&gb_operations_lock); - operation->id = ++connection->op_cycle % U16_MAX + 1; - list_move_tail(&operation->links, &connection->pending); - spin_unlock_irq(&gb_operations_lock); - - /* Store the operation id in the request header */ - header = operation->request->header; - header->operation_id = cpu_to_le16(operation->id); -} - -static void gb_pending_operation_remove(struct gb_operation *operation) -{ - struct gb_connection *connection = operation->connection; - - /* Take us off of the list of pending operations */ - spin_lock_irq(&gb_operations_lock); - list_move_tail(&operation->links, &connection->operations); - spin_unlock_irq(&gb_operations_lock); -} - static struct gb_operation * -gb_pending_operation_find(struct gb_connection *connection, u16 operation_id) +gb_operation_find(struct gb_connection *connection, u16 operation_id) { struct gb_operation *operation; bool found = false; spin_lock_irq(&gb_operations_lock); - list_for_each_entry(operation, &connection->pending, links) + list_for_each_entry(operation, &connection->operations, links) if (operation->id == operation_id) { found = true; break; @@ -667,10 +637,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation) int gb_operation_request_send(struct gb_operation *operation, gb_operation_callback callback) { + struct gb_connection *connection = operation->connection; + struct gb_operation_msg_hdr *header; unsigned long timeout; int ret; - if (operation->connection->state != GB_CONNECTION_STATE_ENABLED) + if (connection->state != GB_CONNECTION_STATE_ENABLED) return -ENOTCONN; /* @@ -684,7 +656,16 @@ int gb_operation_request_send(struct gb_operation *operation, operation->callback = callback; else operation->callback = gb_operation_sync_callback; - gb_pending_operation_insert(operation); + + /* + * Assign the operation's id, and store it in the request header. + * Zero is a reserved operation id. + */ + spin_lock_irq(&gb_operations_lock); + operation->id = ++connection->op_cycle % U16_MAX + 1; + spin_unlock_irq(&gb_operations_lock); + header = operation->request->header; + header->operation_id = cpu_to_le16(operation->id); /* * We impose a time limit for requests to complete. We need @@ -826,14 +807,13 @@ static void gb_connection_recv_response(struct gb_connection *connection, struct gb_message *message; int errno = gb_operation_status_map(result); - operation = gb_pending_operation_find(connection, operation_id); + operation = gb_operation_find(connection, operation_id); if (!operation) { gb_connection_err(connection, "operation not found"); return; } cancel_delayed_work(&operation->timeout_work); - gb_pending_operation_remove(operation); message = operation->response; if (!errno && size != message->size) { diff --git a/drivers/staging/greybus/operation.h b/drivers/staging/greybus/operation.h index 40b2e7d68b87..c73d9b92b5c5 100644 --- a/drivers/staging/greybus/operation.h +++ b/drivers/staging/greybus/operation.h @@ -92,7 +92,7 @@ struct gb_operation { struct delayed_work timeout_work; struct kref kref; - struct list_head links; /* connection->{operations,pending} */ + struct list_head links; /* connection->operations */ }; void gb_connection_recv(struct gb_connection *connection,