Commit 7cc2ade2 authored by Marcel Holtmann's avatar Marcel Holtmann Committed by Johan Hedberg
Browse files

Bluetooth: Simplify HCI socket bind handling



The HCI socket bind handling checks a few too many times the channel
we are binding. So centralize this and make the function easier to read.

Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 3a208627
Loading
Loading
Loading
Loading
+31 −16
Original line number Original line Diff line number Diff line
@@ -367,18 +367,16 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
	if (haddr.hci_family != AF_BLUETOOTH)
	if (haddr.hci_family != AF_BLUETOOTH)
		return -EINVAL;
		return -EINVAL;


	if (haddr.hci_channel > HCI_CHANNEL_CONTROL)
	lock_sock(sk);
		return -EINVAL;


	if (haddr.hci_channel == HCI_CHANNEL_CONTROL) {
	if (sk->sk_state == BT_BOUND) {
		if (!enable_mgmt)
		err = -EALREADY;
			return -EINVAL;
		goto done;
		set_bit(HCI_PI_MGMT_INIT, &hci_pi(sk)->flags);
	}
	}


	lock_sock(sk);
	switch (haddr.hci_channel) {

	case HCI_CHANNEL_RAW:
	if (sk->sk_state == BT_BOUND || hci_pi(sk)->hdev) {
		if (hci_pi(sk)->hdev) {
			err = -EALREADY;
			err = -EALREADY;
			goto done;
			goto done;
		}
		}
@@ -393,8 +391,25 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_le
			atomic_inc(&hdev->promisc);
			atomic_inc(&hdev->promisc);
		}
		}


	hci_pi(sk)->channel = haddr.hci_channel;
		hci_pi(sk)->hdev = hdev;
		hci_pi(sk)->hdev = hdev;
		break;

	case HCI_CHANNEL_CONTROL:
		if (haddr.hci_dev != HCI_DEV_NONE || !enable_mgmt) {
			err = -EINVAL;
			goto done;
		}

		set_bit(HCI_PI_MGMT_INIT, &hci_pi(sk)->flags);
		break;

	default:
		err = -EINVAL;
		goto done;
	}


	hci_pi(sk)->channel = haddr.hci_channel;
	sk->sk_state = BT_BOUND;
	sk->sk_state = BT_BOUND;


done:
done: