From cfb16906860d76b5afe192d32fb79cf9af853b92 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Tue, 15 Sep 2015 10:48:01 +0200 Subject: [PATCH] greybus: greybus_protocols: add missing version-request definition Add the missing version-request definition that was falsely claimed to be empty. Update the generic version-request helper and SVC version-request handler to use the request definition rather than rely on the response happening to have the same layout, something which also improves readability. Remove a misplaced "Control Protocol" header while at it. Signed-off-by: Johan Hovold Reviewed-by: Viresh Kumar Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/greybus_protocols.h | 11 ++++++++--- drivers/staging/greybus/protocol.c | 21 +++++++++++---------- drivers/staging/greybus/svc.c | 21 +++++++++++---------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/staging/greybus/greybus_protocols.h b/drivers/staging/greybus/greybus_protocols.h index d77e03915428..9b2d18916403 100644 --- a/drivers/staging/greybus/greybus_protocols.h +++ b/drivers/staging/greybus/greybus_protocols.h @@ -103,9 +103,11 @@ struct gb_operation_msg_hdr { #define GB_REQUEST_TYPE_INVALID 0x00 #define GB_REQUEST_TYPE_PROTOCOL_VERSION 0x01 -/* Control Protocol */ +struct gb_protocol_version_request { + __u8 major; + __u8 minor; +} __packed; -/* version request has no payload */ struct gb_protocol_version_response { __u8 major; __u8 minor; @@ -748,7 +750,10 @@ struct gb_spi_transfer_response { #define GB_SVC_TYPE_ROUTE_CREATE 0x0b #define GB_SVC_TYPE_ROUTE_DESTROY 0x0c -/* SVC version request/response have same payload as gb_protocol_version_response */ +/* + * SVC version request/response has the same payload as + * gb_protocol_version_request/response. + */ /* SVC protocol hello request */ struct gb_svc_hello_request { diff --git a/drivers/staging/greybus/protocol.c b/drivers/staging/greybus/protocol.c index 1c746597f016..c93f96365667 100644 --- a/drivers/staging/greybus/protocol.c +++ b/drivers/staging/greybus/protocol.c @@ -165,30 +165,31 @@ struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor) int gb_protocol_get_version(struct gb_connection *connection) { - struct gb_protocol_version_response version; + struct gb_protocol_version_request request; + struct gb_protocol_version_response response; int retval; - version.major = connection->protocol->major; - version.minor = connection->protocol->minor; + request.major = connection->protocol->major; + request.minor = connection->protocol->minor; retval = gb_operation_sync(connection, GB_REQUEST_TYPE_PROTOCOL_VERSION, - &version, sizeof(version), &version, - sizeof(version)); + &request, sizeof(request), &response, + sizeof(response)); if (retval) return retval; - if (version.major > connection->protocol->major) { + if (response.major > connection->protocol->major) { dev_err(&connection->dev, "unsupported major version (%hhu > %hhu)\n", - version.major, connection->protocol->major); + response.major, connection->protocol->major); return -ENOTSUPP; } - connection->module_major = version.major; - connection->module_minor = version.minor; + connection->module_major = response.major; + connection->module_minor = response.minor; dev_dbg(&connection->dev, "version_major = %u version_minor = %u\n", - version.major, version.minor); + response.major, response.minor); return 0; } diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c index 075d81d20cb8..28f03dc463f3 100644 --- a/drivers/staging/greybus/svc.c +++ b/drivers/staging/greybus/svc.c @@ -256,30 +256,31 @@ static void gb_svc_route_destroy(struct gb_svc *svc, u8 intf1_id, u8 intf2_id) static int gb_svc_version_request(struct gb_operation *op) { struct gb_connection *connection = op->connection; - struct gb_protocol_version_response *version; + struct gb_protocol_version_request *request; + struct gb_protocol_version_response *response; struct device *dev = &connection->dev; - version = op->request->payload; + request = op->request->payload; - if (version->major > GB_SVC_VERSION_MAJOR) { + if (request->major > GB_SVC_VERSION_MAJOR) { dev_err(&connection->dev, "unsupported major version (%hhu > %hhu)\n", - version->major, GB_SVC_VERSION_MAJOR); + request->major, GB_SVC_VERSION_MAJOR); return -ENOTSUPP; } - connection->module_major = version->major; - connection->module_minor = version->minor; + connection->module_major = request->major; + connection->module_minor = request->minor; - if (!gb_operation_response_alloc(op, sizeof(*version), GFP_KERNEL)) { + if (!gb_operation_response_alloc(op, sizeof(*response), GFP_KERNEL)) { dev_err(dev, "%s: error allocating response\n", __func__); return -ENOMEM; } - version = op->response->payload; - version->major = connection->module_major; - version->minor = connection->module_minor; + response = op->response->payload; + response->major = connection->module_major; + response->minor = connection->module_minor; return 0; } -- 2.20.1