From: Alex Elder Date: Tue, 2 Dec 2014 14:30:38 +0000 (-0600) Subject: greybus: introduce gb_operation_errno_map() X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1792 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=0c90fff4e35c1322a52709f17d630431c7deb931;p=karo-tx-linux.git 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 --- diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 8ffc54bacba1..f3246818d777 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: @@ -438,6 +438,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 @@ -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 ed344f8de2a7..adaec7c43ea9 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);