greybus: connection: intf_cport_id is local to an interface
authorViresh Kumar <viresh.kumar@linaro.org>
Wed, 1 Jul 2015 06:43:56 +0000 (12:13 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 1 Jul 2015 23:38:42 +0000 (16:38 -0700)
intf_cport_id is local to an interface and same intf_cport_id can be
used for two separate interface blocks. For finding a connection for an
interface, we are matching intf_cport_id of the connection with
cport_id, passed as argument. This is wrong, as it can match for a
connection on a different interface block.

Fix it by also comparing interface block for which connection is
requested.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/connection.c

index 6cd9fe2df034fee45bb53c2e7f5293cc8438fc2c..85b2a337074485fed986c74227edf6fd031afb01 100644 (file)
@@ -13,12 +13,14 @@ static DEFINE_SPINLOCK(gb_connections_lock);
 
 /* This is only used at initialization time; no locking is required. */
 static struct gb_connection *
-gb_connection_intf_find(struct greybus_host_device *hd, u16 cport_id)
+gb_connection_intf_find(struct gb_interface *intf, u16 cport_id)
 {
+       struct greybus_host_device *hd = intf->hd;
        struct gb_connection *connection;
 
        list_for_each_entry(connection, &hd->connections, hd_links)
-               if (connection->intf_cport_id == cport_id)
+               if (connection->bundle->intf == intf &&
+                               connection->intf_cport_id == cport_id)
                        return connection;
        return NULL;
 }
@@ -149,7 +151,7 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
         * initialize connections serially so we don't need to worry
         * about holding the connection lock.
         */
-       if (gb_connection_intf_find(hd, cport_id)) {
+       if (gb_connection_intf_find(bundle->intf, cport_id)) {
                pr_err("duplicate interface cport id 0x%04hx\n", cport_id);
                return NULL;
        }