Commit 25cdd7aa authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: operation: handle static connections

Use the host-device device and connection name for error messages, as
the operation code can not assume that a connection has a bundle.

Note that the "initial" svc connection has never had a bundle.
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 4c4b5021
...@@ -217,7 +217,8 @@ static void gb_message_cancel(struct gb_message *message) ...@@ -217,7 +217,8 @@ static void gb_message_cancel(struct gb_message *message)
static void gb_operation_request_handle(struct gb_operation *operation) static void gb_operation_request_handle(struct gb_operation *operation)
{ {
struct gb_protocol *protocol = operation->connection->protocol; struct gb_connection *connection = operation->connection;
struct gb_protocol *protocol = connection->protocol;
int status; int status;
int ret; int ret;
...@@ -227,18 +228,18 @@ static void gb_operation_request_handle(struct gb_operation *operation) ...@@ -227,18 +228,18 @@ static void gb_operation_request_handle(struct gb_operation *operation)
if (protocol->request_recv) { if (protocol->request_recv) {
status = protocol->request_recv(operation->type, operation); status = protocol->request_recv(operation->type, operation);
} else { } else {
dev_err(&operation->connection->bundle->dev, dev_err(&connection->hd->dev,
"unexpected incoming request type 0x%02hhx\n", "%s: unexpected incoming request of type 0x%02hhx\n",
operation->type); connection->name, operation->type);
status = -EPROTONOSUPPORT; status = -EPROTONOSUPPORT;
} }
ret = gb_operation_response_send(operation, status); ret = gb_operation_response_send(operation, status);
if (ret) { if (ret) {
dev_err(&operation->connection->bundle->dev, dev_err(&connection->hd->dev,
"failed to send response %d for type 0x%02hhx: %d\n", "%s: failed to send response %d for type 0x%02hhx: %d\n",
status, operation->type, ret); connection->name, status, operation->type, ret);
return; return;
} }
} }
...@@ -743,7 +744,7 @@ static int gb_operation_response_send(struct gb_operation *operation, ...@@ -743,7 +744,7 @@ static int gb_operation_response_send(struct gb_operation *operation,
/* Record the result */ /* Record the result */
if (!gb_operation_result_set(operation, errno)) { if (!gb_operation_result_set(operation, errno)) {
dev_err(&connection->bundle->dev, "request result already set\n"); dev_err(&connection->hd->dev, "request result already set\n");
return -EIO; /* Shouldn't happen */ return -EIO; /* Shouldn't happen */
} }
...@@ -795,9 +796,9 @@ void greybus_message_sent(struct gb_host_device *hd, ...@@ -795,9 +796,9 @@ void greybus_message_sent(struct gb_host_device *hd,
*/ */
if (message == operation->response) { if (message == operation->response) {
if (status) { if (status) {
dev_err(&connection->bundle->dev, dev_err(&connection->hd->dev,
"error sending response type 0x%02hhx: %d\n", "%s: error sending response 0x%02hhx: %d\n",
operation->type, status); connection->name, operation->type, status);
} }
gb_operation_put_active(operation); gb_operation_put_active(operation);
gb_operation_put(operation); gb_operation_put(operation);
...@@ -827,8 +828,9 @@ static void gb_connection_recv_request(struct gb_connection *connection, ...@@ -827,8 +828,9 @@ static void gb_connection_recv_request(struct gb_connection *connection,
operation = gb_operation_create_incoming(connection, operation_id, operation = gb_operation_create_incoming(connection, operation_id,
type, data, size); type, data, size);
if (!operation) { if (!operation) {
dev_err(&connection->bundle->dev, dev_err(&connection->hd->dev,
"can't create incoming operation\n"); "%s: can't create incoming operation\n",
connection->name);
return; return;
} }
...@@ -865,17 +867,19 @@ static void gb_connection_recv_response(struct gb_connection *connection, ...@@ -865,17 +867,19 @@ static void gb_connection_recv_response(struct gb_connection *connection,
operation = gb_operation_find_outgoing(connection, operation_id); operation = gb_operation_find_outgoing(connection, operation_id);
if (!operation) { if (!operation) {
dev_err(&connection->bundle->dev, dev_err(&connection->hd->dev,
"unexpected response 0x%04hx received\n", operation_id); "%s: unexpected response id 0x%04hx received\n",
connection->name, operation_id);
return; return;
} }
message = operation->response; message = operation->response;
message_size = sizeof(*message->header) + message->payload_size; message_size = sizeof(*message->header) + message->payload_size;
if (!errno && size != message_size) { if (!errno && size != message_size) {
dev_err(&connection->bundle->dev, dev_err(&connection->hd->dev,
"malformed response of type 0x%02hhx received (%zu != %zu)\n", "%s: malformed response 0x%02hhx received (%zu != %zu)\n",
message->header->type, size, message_size); connection->name, message->header->type, size,
message_size);
errno = -EMSGSIZE; errno = -EMSGSIZE;
} }
trace_gb_message_recv_response(operation->response); trace_gb_message_recv_response(operation->response);
...@@ -902,17 +906,18 @@ void gb_connection_recv(struct gb_connection *connection, ...@@ -902,17 +906,18 @@ void gb_connection_recv(struct gb_connection *connection,
void *data, size_t size) void *data, size_t size)
{ {
struct gb_operation_msg_hdr header; struct gb_operation_msg_hdr header;
struct device *dev = &connection->bundle->dev; struct device *dev = &connection->hd->dev;
size_t msg_size; size_t msg_size;
u16 operation_id; u16 operation_id;
if (connection->state != GB_CONNECTION_STATE_ENABLED) { if (connection->state != GB_CONNECTION_STATE_ENABLED) {
dev_warn(dev, "dropping %zu received bytes\n", size); dev_warn(dev, "%s: dropping %zu received bytes\n",
connection->name, size);
return; return;
} }
if (size < sizeof(header)) { if (size < sizeof(header)) {
dev_err(dev, "short message received\n"); dev_err(dev, "%s: short message received\n", connection->name);
return; return;
} }
...@@ -921,9 +926,9 @@ void gb_connection_recv(struct gb_connection *connection, ...@@ -921,9 +926,9 @@ void gb_connection_recv(struct gb_connection *connection,
msg_size = le16_to_cpu(header.size); msg_size = le16_to_cpu(header.size);
if (size < msg_size) { if (size < msg_size) {
dev_err(dev, dev_err(dev,
"incomplete message 0x%04hx of type 0x%02hhx received (%zu < %zu)\n", "%s: incomplete message 0x%04hx of type 0x%02hhx received (%zu < %zu)\n",
le16_to_cpu(header.operation_id), header.type, size, connection->name, le16_to_cpu(header.operation_id),
msg_size); header.type, size, msg_size);
return; /* XXX Should still complete operation */ return; /* XXX Should still complete operation */
} }
...@@ -1030,9 +1035,9 @@ int gb_operation_sync_timeout(struct gb_connection *connection, int type, ...@@ -1030,9 +1035,9 @@ int gb_operation_sync_timeout(struct gb_connection *connection, int type,
ret = gb_operation_request_send_sync_timeout(operation, timeout); ret = gb_operation_request_send_sync_timeout(operation, timeout);
if (ret) { if (ret) {
dev_err(&connection->bundle->dev, dev_err(&connection->hd->dev,
"synchronous operation of type 0x%02hhx failed: %d\n", "%s: synchronous operation of type 0x%02hhx failed: %d\n",
type, ret); connection->name, type, ret);
} else { } else {
if (response_size) { if (response_size) {
memcpy(response, operation->response->payload, memcpy(response, operation->response->payload,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment