diff options
author | Alex Elder | 2014-11-22 02:29:12 +0100 |
---|---|---|
committer | Greg Kroah-Hartman | 2014-11-22 04:31:13 +0100 |
commit | 23383defa8395eb34d02dd4d4fc1d95e95c5603d (patch) | |
tree | 6455d7911736f59729ae75e5f541a8a39413bb84 /drivers/staging/greybus/i2c-gb.c | |
parent | greybus: Random spell fixes (diff) | |
download | kernel-qcow2-linux-23383defa8395eb34d02dd4d4fc1d95e95c5603d.tar.gz kernel-qcow2-linux-23383defa8395eb34d02dd4d4fc1d95e95c5603d.tar.xz kernel-qcow2-linux-23383defa8395eb34d02dd4d4fc1d95e95c5603d.zip |
greybus: use errno for operation result
An in-core operation structure tracks the progress of an operation.
Currently it holds a result field that was intended to take the
status value that arrives in an operation response message header.
But operations can fail for reasons other than that, and it's
inconvenient to try to represent those using the operation status
codes.
So change the operation->result field to be an int, and switch to
storing negative errno values in it. Rename it "errno" to make
it obvious how to interpret the value.
This patch makes another change, which simplifies the protocol drivers
a lot. It's being done as part of this patch because it affects all
the same code as the above change does. If desired I can split this
into two separate patches.
If a caller makes a synchronous gb_operation_request_send() request
(i.e., no callback function is supplied), and the operation request
and response messages were transferred successfully, have
gb_operation_request_send() return the result of the request (i.e.,
operation->errno). This allows the caller (or more generally, any
caller of gb_request_wait() to avoid having to look at this field
for every successful send.
Any caller that does an asynchronous request will of course need
to look at request->errno in the callback function to see the
result of the operation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'drivers/staging/greybus/i2c-gb.c')
-rw-r--r-- | drivers/staging/greybus/i2c-gb.c | 75 |
1 files changed, 17 insertions, 58 deletions
diff --git a/drivers/staging/greybus/i2c-gb.c b/drivers/staging/greybus/i2c-gb.c index 2a5fb822535e..6b2fd7e934e3 100644 --- a/drivers/staging/greybus/i2c-gb.c +++ b/drivers/staging/greybus/i2c-gb.c @@ -111,23 +111,16 @@ static int gb_i2c_proto_version_operation(struct gb_i2c_device *gb_i2c_dev) goto out; } - if (operation->result) { - ret = gb_operation_status_map(operation->result); - gb_connection_err(connection, "version result %hhu", - operation->result); - } else { - response = operation->response->payload; - if (response->major > GB_I2C_VERSION_MAJOR) { - pr_err("unsupported major version (%hhu > %hhu)\n", - response->major, GB_I2C_VERSION_MAJOR); - ret = -ENOTSUPP; - goto out; - } - gb_i2c_dev->version_major = response->major; - gb_i2c_dev->version_minor = response->minor; + response = operation->response->payload; + if (response->major > GB_I2C_VERSION_MAJOR) { + pr_err("unsupported major version (%hhu > %hhu)\n", + response->major, GB_I2C_VERSION_MAJOR); + ret = -ENOTSUPP; + goto out; } + gb_i2c_dev->version_major = response->major; + gb_i2c_dev->version_minor = response->minor; out: - gb_operation_destroy(operation); return ret; @@ -163,16 +156,9 @@ static int gb_i2c_functionality_operation(struct gb_i2c_device *gb_i2c_dev) goto out; } - if (operation->result) { - ret = gb_operation_status_map(operation->result); - gb_connection_err(connection, "functionality result %hhu", - operation->result); - } else { - response = operation->response->payload; - functionality = le32_to_cpu(response->functionality); - gb_i2c_dev->functionality = - gb_i2c_functionality_map(functionality); - } + response = operation->response->payload; + functionality = le32_to_cpu(response->functionality); + gb_i2c_dev->functionality = gb_i2c_functionality_map(functionality); out: gb_operation_destroy(operation); @@ -195,19 +181,10 @@ static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec) /* Synchronous operation--no callback */ ret = gb_operation_request_send(operation, NULL); - if (ret) { + if (ret) pr_err("timeout operation failed (%d)\n", ret); - goto out; - } - - if (operation->result) { - ret = gb_operation_status_map(operation->result); - gb_connection_err(connection, "timeout result %hhu", - operation->result); - } else { + else gb_i2c_dev->timeout_msec = msec; - } -out: gb_operation_destroy(operation); return ret; @@ -230,19 +207,10 @@ static int gb_i2c_retries_operation(struct gb_i2c_device *gb_i2c_dev, /* Synchronous operation--no callback */ ret = gb_operation_request_send(operation, NULL); - if (ret) { + if (ret) pr_err("retries operation failed (%d)\n", ret); - goto out; - } - - if (operation->result) { - ret = gb_operation_status_map(operation->result); - gb_connection_err(connection, "retries result %hhu", - operation->result); - } else { + else gb_i2c_dev->retries = retries; - } -out: gb_operation_destroy(operation); return ret; @@ -365,22 +333,13 @@ static int gb_i2c_transfer_operation(struct gb_i2c_device *gb_i2c_dev, /* Synchronous operation--no callback */ ret = gb_operation_request_send(operation, NULL); if (ret) { - pr_err("transfer operation failed (%d)\n", ret); - goto out; - } - - if (operation->result) { - ret = gb_operation_status_map(operation->result); - if (ret != -EAGAIN) { - gb_connection_err(connection, "transfer result %hhu", - operation->result); - } + if (ret != -EAGAIN) + pr_err("transfer operation failed (%d)\n", ret); } else { response = operation->response->payload; gb_i2c_transfer_response(msgs, msg_count, response->data); ret = msg_count; } -out: gb_operation_destroy(operation); return ret; |