OSDN Git Service

greybus: introduce gb_operation_errno_map()
authorAlex Elder <elder@linaro.org>
Tue, 2 Dec 2014 14:30:38 +0000 (08:30 -0600)
committerGreg Kroah-Hartman <greg@kroah.com>
Tue, 2 Dec 2014 22:44:11 +0000 (14:44 -0800)
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 <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/operation.c
drivers/staging/greybus/operation.h

index 8ffc54b..f324681 100644 (file)
@@ -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;
index ed344f8..adaec7c 100644 (file)
@@ -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);