greybus: greybus_protocols: add missing version-request definition
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 15 Sep 2015 08:48:01 +0000 (10:48 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 15 Sep 2015 13:15:37 +0000 (06:15 -0700)
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 <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/greybus_protocols.h
drivers/staging/greybus/protocol.c
drivers/staging/greybus/svc.c

index d77e03915428f802d7a5b1aade0dd265b56d8f9f..9b2d1891640343ee7b24575edc368cc8650b550e 100644 (file)
@@ -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 {
index 1c746597f01680cda4b2853f5cd9fc74d9b58ff7..c93f963656674b5a82ee8697b6efc5250f10ee7e 100644 (file)
@@ -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;
 }
index 075d81d20cb838ebd200e59f808f1f9c3b6f959a..28f03dc463f35a5a21ef44e948d1df20a4ab516a 100644 (file)
@@ -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;
 }