Re: [PATCH 3/4] Bluetooth: Fix Remove Device to wait for HCI before sending cmd_complete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Johan,

> This patch updates the Remove Device mgmt command handler to use a
> hci_request to wait for HCI command completion before notifying user
> space of the mgmt command completion. This way we ensure that once the
> mgmt command returns all HCI commands triggered by it have also
> completed.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@xxxxxxxxx>
> ---
> net/bluetooth/mgmt.c | 49 +++++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 43 insertions(+), 6 deletions(-)
> 
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index 7efdeb3cf224..ab3dae3076d7 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -5522,16 +5522,47 @@ static void device_removed(struct sock *sk, struct hci_dev *hdev,
> 	mgmt_event(MGMT_EV_DEVICE_REMOVED, hdev, &ev, sizeof(ev), sk);
> }
> 
> +static void remove_device_complete(struct hci_dev *hdev, u8 status)
> +{
> +	struct pending_cmd *cmd;
> +
> +	BT_DBG("status 0x%02x", status);
> +
> +	hci_dev_lock(hdev);
> +
> +	cmd = mgmt_pending_find(MGMT_OP_REMOVE_DEVICE, hdev);
> +	if (!cmd)
> +		goto unlock;
> +
> +	cmd->cmd_complete(cmd, mgmt_status(status));
> +	mgmt_pending_remove(cmd);
> +
> +unlock:
> +	hci_dev_unlock(hdev);
> +}
> +
> static int remove_device(struct sock *sk, struct hci_dev *hdev,
> 			 void *data, u16 len)
> {
> 	struct mgmt_cp_remove_device *cp = data;
> +	struct pending_cmd *cmd;
> +	struct hci_request req;
> 	int err;
> 
> 	BT_DBG("%s", hdev->name);
> 
> +	hci_req_init(&req, hdev);
> +
> 	hci_dev_lock(hdev);
> 
> +	cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_DEVICE, hdev, data, len);
> +	if (!cmd) {
> +		err = -ENOMEM;
> +		goto unlock;
> +	}
> +
> +	cmd->cmd_complete = addr_cmd_complete;
> +
> 	if (bacmp(&cp->addr.bdaddr, BDADDR_ANY)) {
> 		struct hci_conn_params *params;
> 		u8 addr_type;
> @@ -5555,7 +5586,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
> 				goto unlock;
> 			}
> 
> -			hci_update_page_scan(hdev, NULL);
> +			hci_update_page_scan(hdev, &req);

so it seems we have done this at least once before. This does not mean that I start to like it now. Especially since now we are adding hci_request pointers to almost all of them now.

I have the feeling we need to fix hci_update_page_scan first to only take the hci_request pointer. We really could just do these two:

	hci_update_page_scan(struct hci_dev *);
	__hci_update_page_scan(struct hci_request *);

And then of course similar things with the other ones.

Regards

Marcel

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux