From bc717fcbf673b0852a474b869efb9bfd0989b012 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Wed, 19 Nov 2014 17:55:04 -0600 Subject: [PATCH] greybus: define gb_operation_status_map() Define a common function that maps an operation status value to a Linux negative errno. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/operation.c | 29 +++++++++++++++++++++++++++++ drivers/staging/greybus/operation.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index 301102081567..cfc341e6e341 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -287,6 +287,35 @@ static void gb_operation_message_exit(struct gb_message *message) message->buffer_size = 0; } +/* + * Map an enum gb_operation_status value (which is represted in a + * message as a single back a single byte) to an appropriate Linux + * negative errno. + */ +int gb_operation_status_map(u8 status) +{ + switch (status) { + case GB_OP_SUCCESS: + return 0; + case GB_OP_INVALID: + return -EINVAL; + case GB_OP_NO_MEMORY: + return -ENOMEM; + case GB_OP_INTERRUPTED: + return -EINTR; + case GB_OP_RETRY: + return -EAGAIN; + case GB_OP_PROTOCOL_BAD: + return -EPROTONOSUPPORT; + case GB_OP_OVERFLOW: + return -E2BIG; + case GB_OP_TIMEOUT: + return -ETIMEDOUT; + default: + return -EIO; + } +} + /* * Create a Greybus operation to be sent over the given connection. * The request buffer will big enough for a payload of the given diff --git a/drivers/staging/greybus/operation.h b/drivers/staging/greybus/operation.h index 80ee158d74f7..6547291d8d85 100644 --- a/drivers/staging/greybus/operation.h +++ b/drivers/staging/greybus/operation.h @@ -101,6 +101,8 @@ int gb_operation_response_send(struct gb_operation *operation); void gb_operation_cancel(struct gb_operation *operation); int gb_operation_wait(struct gb_operation *operation); +int gb_operation_status_map(u8 status); + int gb_operation_init(void); void gb_operation_exit(void); -- 2.20.1