Commit ba986b5a authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

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: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 9f240f20
...@@ -66,6 +66,16 @@ struct gb_operation_msg_hdr { ...@@ -66,6 +66,16 @@ struct gb_operation_msg_hdr {
/* XXX Could be per-host device, per-module, or even per-connection */ /* XXX Could be per-host device, per-module, or even per-connection */
static DEFINE_SPINLOCK(gb_operations_lock); 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) static void gb_pending_operation_insert(struct gb_operation *operation)
{ {
struct gb_connection *connection = operation->connection; struct gb_connection *connection = operation->connection;
...@@ -164,7 +174,7 @@ static void gb_operation_request_handle(struct gb_operation *operation) ...@@ -164,7 +174,7 @@ static void gb_operation_request_handle(struct gb_operation *operation)
gb_connection_err(operation->connection, gb_connection_err(operation->connection,
"unexpected incoming request type 0x%02hhx\n", header->type); "unexpected incoming request type 0x%02hhx\n", header->type);
operation->errno = -EPROTONOSUPPORT; gb_operation_result_set(operation, -EPROTONOSUPPORT);
} }
#endif #endif
...@@ -424,11 +434,12 @@ static void gb_operation_sync_callback(struct gb_operation *operation) ...@@ -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, * any payload so the request message is ready to go. If non-null,
* the callback function supplied will be called when the response * the callback function supplied will be called when the response
* message has arrived indicating the operation is complete. In * message has arrived indicating the operation is complete. In
* that case, the callback function is responsible for extracting * that case, the callback function is responsible for fetching the
* the result of the operation from operation->errno if desired, * result of the operation using gb_operation_result() if desired,
* and dropping the final reference to the operation. A null * and dropping the final reference to (i.e., destroying) the
* callback function is used for a synchronous request; return from * operation. A null callback function is used for a synchronous
* this function won't occur until the operation is complete. * 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, int gb_operation_request_send(struct gb_operation *operation,
gb_operation_callback callback) gb_operation_callback callback)
...@@ -470,7 +481,7 @@ int gb_operation_request_send(struct gb_operation *operation, ...@@ -470,7 +481,7 @@ int gb_operation_request_send(struct gb_operation *operation,
if (ret < 0) if (ret < 0)
gb_operation_cancel(operation, -EINTR); 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) ...@@ -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 */ /* XXX Right now we assume we're an outgoing request */
message = gb_hd_message_find(hd, header); message = gb_hd_message_find(hd, header);
operation = message->operation; operation = message->operation;
operation->errno = status; gb_operation_result_set(operation, status);
queue_work(gb_operation_workqueue, &operation->work); queue_work(gb_operation_workqueue, &operation->work);
} }
EXPORT_SYMBOL_GPL(greybus_data_sent); EXPORT_SYMBOL_GPL(greybus_data_sent);
...@@ -527,7 +538,7 @@ void gb_connection_recv_request(struct gb_connection *connection, ...@@ -527,7 +538,7 @@ void gb_connection_recv_request(struct gb_connection *connection,
memcpy(operation->request->header, data, size); memcpy(operation->request->header, data, size);
/* XXX Right now this will just complete the operation */ /* 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); queue_work(gb_operation_workqueue, &operation->work);
} }
...@@ -571,7 +582,7 @@ static void gb_connection_recv_response(struct gb_connection *connection, ...@@ -571,7 +582,7 @@ static void gb_connection_recv_response(struct gb_connection *connection,
memcpy(message->header, data, size); memcpy(message->header, data, size);
/* The rest will be handled in work queue context */ /* 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); queue_work(gb_operation_workqueue, &operation->work);
} }
...@@ -619,7 +630,7 @@ void gb_connection_recv(struct gb_connection *connection, ...@@ -619,7 +630,7 @@ void gb_connection_recv(struct gb_connection *connection,
*/ */
void gb_operation_cancel(struct gb_operation *operation, int errno) 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->request);
gb_message_cancel(operation->response); gb_message_cancel(operation->response);
} }
......
...@@ -84,6 +84,8 @@ struct gb_operation { ...@@ -84,6 +84,8 @@ struct gb_operation {
void gb_connection_recv(struct gb_connection *connection, void gb_connection_recv(struct gb_connection *connection,
void *data, size_t size); void *data, size_t size);
int gb_operation_result(struct gb_operation *operation);
struct gb_operation *gb_operation_create(struct gb_connection *connection, struct gb_operation *gb_operation_create(struct gb_connection *connection,
u8 type, size_t request_size, u8 type, size_t request_size,
size_t response_size); size_t response_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment