]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
greybus: connection: drop unneeded gb_protocol_put() calls
authorAlex Elder <elder@linaro.org>
Fri, 12 Jun 2015 15:21:07 +0000 (10:21 -0500)
committerGreg Kroah-Hartman <gregkh@google.com>
Fri, 12 Jun 2015 19:13:01 +0000 (12:13 -0700)
Although a connection records its protocol id when it gets
created, its protocol handler doesn't actually get assigned
until gb_connection_bind_protocol() is called.

In gb_connection_create() there are some error paths in
which a reference to the connection's protocol is released
before the protocol handler has been associated with the
connection.

Get rid of those calls.

As a result, we will never pass a null protocol pointer to
gb_protocol_put().  Add a precautionary warning in that
function in the event that ever occurs.

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

index bf5fa101e541eb540999d3296cafb52bc580774d..abd74116cf62598abd102e732a8761112ac1d2e2 100644 (file)
@@ -195,7 +195,6 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
        connection->major = major;
        connection->minor = minor;
        if (!gb_connection_hd_cport_id_alloc(connection)) {
-               gb_protocol_put(connection->protocol);
                kfree(connection);
                return NULL;
        }
@@ -217,7 +216,6 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
                pr_err("failed to add connection device for cport 0x%04hx\n",
                        cport_id);
                gb_connection_hd_cport_id_free(connection);
-               gb_protocol_put(connection->protocol);
                put_device(&connection->dev);
 
                return NULL;
@@ -264,6 +262,7 @@ void gb_connection_destroy(struct gb_connection *connection)
 
        gb_connection_hd_cport_id_free(connection);
        gb_protocol_put(connection->protocol);
+       connection->protocol = NULL;
 
        device_unregister(&connection->dev);
 }
index eed77c3f3a7fd4f9af811a8267f19beaa5520412..6aebbbd585e1681d33280dbd5a179e9cf0d78868 100644 (file)
@@ -196,7 +196,7 @@ void gb_protocol_put(struct gb_protocol *protocol)
        u8 minor;
        u8 protocol_count;
 
-       if (!protocol)
+       if (WARN_ON(!protocol))
                return;
 
        id = protocol->id;