From 0c90fff4e35c1322a52709f17d630431c7deb931 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Tue, 2 Dec 2014 08:30:38 -0600 Subject: [PATCH] greybus: introduce gb_operation_errno_map() Define gb_operation_errno_map(), which maps an operation->errno into the u8 value that represents it in the status field of an operation response header. It'll be used in an upcoming patch. Make gb_operation_status_map() a private function. It's not used outside "operation.c" and I don't believe it ever should be. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/operation.c | 36 +++++++++++++++++++++++++++++++++++- drivers/staging/greybus/operation.h | 2 -- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 8ffc54b..f324681 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -411,7 +411,7 @@ static void gb_operation_message_free(struct gb_message *message) * Map an enum gb_operation_status value (which is represented in a * message as a single byte) to an appropriate Linux negative errno. */ -int gb_operation_status_map(u8 status) +static int gb_operation_status_map(u8 status) { switch (status) { case GB_OP_SUCCESS: @@ -439,6 +439,39 @@ int gb_operation_status_map(u8 status) } /* + * Map a Linux errno value (from operation->errno) into the value + * that should represent it in a response message status sent + * over the wire. Returns an enum gb_operation_status value (which + * is represented in a message as a single byte). + */ +static u8 gb_operation_errno_map(int errno) +{ + switch (errno) { + case 0: + return GB_OP_SUCCESS; + case -EINTR: + return GB_OP_INTERRUPTED; + case -ETIMEDOUT: + return GB_OP_TIMEOUT; + case -ENOMEM: + return GB_OP_NO_MEMORY; + case -EPROTONOSUPPORT: + return GB_OP_PROTOCOL_BAD; + case -EMSGSIZE: + return GB_OP_OVERFLOW; /* Could be underflow too */ + case -EINVAL: + return GB_OP_INVALID; + case -EAGAIN: + return GB_OP_RETRY; + case -EILSEQ: + return GB_OP_MALFUNCTION; + case -EIO: + default: + return GB_OP_UNKNOWN_ERROR; + } +} + +/* * Create a Greybus operation to be sent over the given connection. * The request buffer will be big enough for a payload of the given * size. @@ -656,6 +689,7 @@ int gb_operation_response_send(struct gb_operation *operation, int errno) pr_err("request result already set\n"); return -EIO; /* Shouldn't happen */ } + (void)gb_operation_errno_map; /* avoid a build warning */ gb_operation_destroy(operation); return 0; diff --git a/drivers/staging/greybus/operation.h b/drivers/staging/greybus/operation.h index ed344f8..adaec7c 100644 --- a/drivers/staging/greybus/operation.h +++ b/drivers/staging/greybus/operation.h @@ -104,8 +104,6 @@ int gb_operation_response_send(struct gb_operation *operation, int errno); void gb_operation_cancel(struct gb_operation *operation, int errno); -int gb_operation_status_map(u8 status); - void greybus_data_sent(struct greybus_host_device *hd, void *header, int status); -- 2.7.4