]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
greybus: define gb_operation_status_map()
authorAlex Elder <elder@linaro.org>
Wed, 19 Nov 2014 23:55:04 +0000 (17:55 -0600)
committerGreg Kroah-Hartman <greg@kroah.com>
Thu, 20 Nov 2014 00:49:57 +0000 (16:49 -0800)
Define a common function that maps an operation status value to a
Linux negative errno.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/operation.c
drivers/staging/greybus/operation.h

index 30110208156766fee19cc75a32e9a9837d8f9532..cfc341e6e341067dc3edae547a61f18a0398e46d 100644 (file)
@@ -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
index 80ee158d74f7d0792ae46cadd78f5bae33f30d84..6547291d8d85135e8e3156e3270cbb5f9125bfce 100644 (file)
@@ -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);