greybus: connection: fail to bind if connection init fails
authorFabien Parent <fparent@baylibre.com>
Mon, 31 Aug 2015 11:51:14 +0000 (17:21 +0530)
committerJohan Hovold <johan@hovoldconsulting.com>
Thu, 3 Sep 2015 12:46:52 +0000 (14:46 +0200)
gb_connection_init() can fail and will return proper error code in that
case, but the caller is ignoring it currently.

Fix that by properly handling errors returned from gb_connection_init()
and propagating them to callers of gb_connection_bind_protocol().

Signed-off-by: Fabien Parent <fparent@baylibre.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h

index 29870536aa2fbdd2387799d799625787831457ed..d0642bcd760032e276a224baf30211a05e14cd90 100644 (file)
@@ -451,19 +451,20 @@ void gb_hd_connections_exit(struct greybus_host_device *hd)
                gb_connection_destroy(connection);
 }
 
-void gb_connection_bind_protocol(struct gb_connection *connection)
+int gb_connection_bind_protocol(struct gb_connection *connection)
 {
        struct gb_protocol *protocol;
+       int ret;
 
        /* If we already have a protocol bound here, just return */
        if (connection->protocol)
-               return;
+               return 0;
 
        protocol = gb_protocol_get(connection->protocol_id,
                                   connection->major,
                                   connection->minor);
        if (!protocol)
-               return;
+               return 0;
        connection->protocol = protocol;
 
        /*
@@ -472,6 +473,14 @@ void gb_connection_bind_protocol(struct gb_connection *connection)
         */
        if ((!connection->bundle &&
             connection->hd_cport_id == GB_SVC_CPORT_ID) ||
-           connection->bundle->intf->device_id != GB_DEVICE_ID_BAD)
-               gb_connection_init(connection);
+           connection->bundle->intf->device_id != GB_DEVICE_ID_BAD) {
+               ret = gb_connection_init(connection);
+               if (ret) {
+                       gb_protocol_put(protocol);
+                       connection->protocol = NULL;
+                       return ret;
+               }
+       }
+
+       return 0;
 }
index 0b442fe61b87116a2db5aea0cbda25c23a65203e..e3ae01dcfd821b667c2f7015f3b818c046a72ff1 100644 (file)
@@ -68,6 +68,6 @@ void gb_connection_push_timestamp(struct gb_connection *connection);
 int gb_connection_pop_timestamp(struct gb_connection *connection,
                                struct timeval *tv);
 
-void gb_connection_bind_protocol(struct gb_connection *connection);
+int gb_connection_bind_protocol(struct gb_connection *connection);
 
 #endif /* __CONNECTION_H */