Skip to content

Commit

Permalink
Bluetooth: check for already existent channel before create new one
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Gustavo Padovan authored and Johan Hedberg committed Jun 5, 2012
1 parent 5382669 commit 2dfa100
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions net/bluetooth/l2cap_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2dfa100

Please sign in to comment.