Bluetooth: check for already existent channel before create new one
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Mon, 28 May 2012 01:27:58 +0000 (22:27 -0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 5 Jun 2012 03:34:11 +0000 (06:34 +0300)
Move this check to before the channel time creation simplifies the code
and avoid memory allocation if the channel already exist.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Acked-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/l2cap_core.c

index d64c836f2bcf3e691c72935e5e6b314451ddd125..6f30d1da89a0b4baee22e81a49192af4f81819a9 100644 (file)
@@ -3343,21 +3343,16 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
 
        result = L2CAP_CR_NO_MEM;
 
+       /* Check if we already have channel with that dcid */
+       if (__l2cap_get_chan_by_dcid(conn, scid))
+               goto response;
+
        chan = pchan->ops->new_connection(pchan);
        if (!chan)
                goto response;
 
        sk = chan->sk;
 
-       /* Check if we already have channel with that dcid */
-       if (__l2cap_get_chan_by_dcid(conn, scid)) {
-               if (chan->ops->teardown)
-                       chan->ops->teardown(chan, 0);
-
-               chan->ops->close(chan);
-               goto response;
-       }
-
        hci_conn_hold(conn->hcon);
 
        bacpy(&bt_sk(sk)->src, conn->src);