Skip to content

Commit

Permalink
Bluetooth: Fix handling of getsockname() for HCI sockets
Browse files Browse the repository at this point in the history
The hci_dev check is not protected and so move it into the socket lock. In
addition return the HCI channel identifier instead of always 0 channel.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
  • Loading branch information
Marcel Holtmann authored and Gustavo Padovan committed Sep 16, 2013
1 parent 06f43cb commit 9d4b68b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,25 +695,30 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr,
{
struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr;
struct sock *sk = sock->sk;
struct hci_dev *hdev = hci_pi(sk)->hdev;
struct hci_dev *hdev;
int err = 0;

BT_DBG("sock %p sk %p", sock, sk);

if (peer)
return -EOPNOTSUPP;

if (!hdev)
return -EBADFD;

lock_sock(sk);

hdev = hci_pi(sk)->hdev;
if (!hdev) {
err = -EBADFD;
goto done;
}

*addr_len = sizeof(*haddr);
haddr->hci_family = AF_BLUETOOTH;
haddr->hci_dev = hdev->id;
haddr->hci_channel= 0;
haddr->hci_channel= hci_pi(sk)->channel;

done:
release_sock(sk);
return 0;
return err;
}

static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg,
Expand Down

0 comments on commit 9d4b68b

Please sign in to comment.