From: Alex Elder Date: Tue, 25 Nov 2014 17:33:13 +0000 (-0600) Subject: greybus: encapsulate operation result access X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1818 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ba986b5ab97f59669cc5d174a8a7359b8600e2e5;p=karo-tx-linux.git greybus: encapsulate operation result access Hide the setting and getting of the operation result (stored in operation->errno) behind a pair of accessor functions. Only the operation core should be setting the result, but operations that complete asynchronously will need access to the result so expose the function that provides that. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 35fcb882bfde..f42e6d29f827 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -66,6 +66,16 @@ struct gb_operation_msg_hdr { /* XXX Could be per-host device, per-module, or even per-connection */ static DEFINE_SPINLOCK(gb_operations_lock); +static void gb_operation_result_set(struct gb_operation *operation, int result) +{ + operation->errno = result; +} + +int gb_operation_result(struct gb_operation *operation) +{ + return operation->errno; +} + static void gb_pending_operation_insert(struct gb_operation *operation) { struct gb_connection *connection = operation->connection; @@ -164,7 +174,7 @@ static void gb_operation_request_handle(struct gb_operation *operation) gb_connection_err(operation->connection, "unexpected incoming request type 0x%02hhx\n", header->type); - operation->errno = -EPROTONOSUPPORT; + gb_operation_result_set(operation, -EPROTONOSUPPORT); } #endif @@ -424,11 +434,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation) * any payload so the request message is ready to go. If non-null, * the callback function supplied will be called when the response * message has arrived indicating the operation is complete. In - * that case, the callback function is responsible for extracting - * the result of the operation from operation->errno if desired, - * and dropping the final reference to the operation. A null - * callback function is used for a synchronous request; return from - * this function won't occur until the operation is complete. + * that case, the callback function is responsible for fetching the + * result of the operation using gb_operation_result() if desired, + * and dropping the final reference to (i.e., destroying) the + * operation. A null callback function is used for a synchronous + * request; in that case return from this function won't occur until + * the operation is complete. */ int gb_operation_request_send(struct gb_operation *operation, gb_operation_callback callback) @@ -470,7 +481,7 @@ int gb_operation_request_send(struct gb_operation *operation, if (ret < 0) gb_operation_cancel(operation, -EINTR); - return operation->errno; + return gb_operation_result(operation); } /* @@ -501,7 +512,7 @@ greybus_data_sent(struct greybus_host_device *hd, void *header, int status) /* XXX Right now we assume we're an outgoing request */ message = gb_hd_message_find(hd, header); operation = message->operation; - operation->errno = status; + gb_operation_result_set(operation, status); queue_work(gb_operation_workqueue, &operation->work); } EXPORT_SYMBOL_GPL(greybus_data_sent); @@ -527,7 +538,7 @@ void gb_connection_recv_request(struct gb_connection *connection, memcpy(operation->request->header, data, size); /* XXX Right now this will just complete the operation */ - operation->errno = -ENOSYS; + gb_operation_result_set(operation, -ENOSYS); queue_work(gb_operation_workqueue, &operation->work); } @@ -571,7 +582,7 @@ static void gb_connection_recv_response(struct gb_connection *connection, memcpy(message->header, data, size); /* The rest will be handled in work queue context */ - operation->errno = result; + gb_operation_result_set(operation, result); queue_work(gb_operation_workqueue, &operation->work); } @@ -619,7 +630,7 @@ void gb_connection_recv(struct gb_connection *connection, */ void gb_operation_cancel(struct gb_operation *operation, int errno) { - operation->errno = errno; + gb_operation_result_set(operation, errno); gb_message_cancel(operation->request); gb_message_cancel(operation->response); } diff --git a/drivers/staging/greybus/operation.h b/drivers/staging/greybus/operation.h index bc5c1641e1ac..7f835d2e8f35 100644 --- a/drivers/staging/greybus/operation.h +++ b/drivers/staging/greybus/operation.h @@ -84,6 +84,8 @@ struct gb_operation { void gb_connection_recv(struct gb_connection *connection, void *data, size_t size); +int gb_operation_result(struct gb_operation *operation); + struct gb_operation *gb_operation_create(struct gb_connection *connection, u8 type, size_t request_size, size_t response_size);