Skip to content

Commit cac43d3

Browse files
gregkhVudentz
authored andcommitted
Bluetooth: btusb: Fix short read errors in btusb_qca_send_vendor_req()
If btusb_qca_send_vendor_req() gets a "short" read from a device, it will accidentally treat that as a "real" read and populate the returned value with some unknown and probably totally invalid data. Fix this logic error up by calling usb_control_msg_recv() which guarantees a "full" read happens, and then simplify the error checking for when btusb_qca_send_vendor_req() is called. Cc: stable <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 0cc4b56 commit cac43d3

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

drivers/bluetooth/btusb.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,28 +3424,16 @@ static const char *qca_get_fw_subdirectory(const struct qca_version *ver)
34243424
static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request,
34253425
void *data, u16 size)
34263426
{
3427-
int pipe, err;
3428-
u8 *buf;
3429-
3430-
buf = kmalloc(size, GFP_KERNEL);
3431-
if (!buf)
3432-
return -ENOMEM;
3427+
int err;
34333428

34343429
/* Found some of USB hosts have IOT issues with ours so that we should
34353430
* not wait until HCI layer is ready.
34363431
*/
3437-
pipe = usb_rcvctrlpipe(udev, 0);
3438-
err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN,
3439-
0, 0, buf, size, USB_CTRL_GET_TIMEOUT);
3440-
if (err < 0) {
3432+
err = usb_control_msg_recv(udev, 0, request, USB_TYPE_VENDOR | USB_DIR_IN,
3433+
0, 0, data, size, USB_CTRL_GET_TIMEOUT,
3434+
GFP_KERNEL);
3435+
if (err)
34413436
dev_err(&udev->dev, "Failed to access otp area (%d)", err);
3442-
goto done;
3443-
}
3444-
3445-
memcpy(data, buf, size);
3446-
3447-
done:
3448-
kfree(buf);
34493437

34503438
return err;
34513439
}
@@ -3652,7 +3640,7 @@ static bool btusb_qca_need_patch(struct usb_device *udev)
36523640
struct qca_version ver;
36533641

36543642
if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
3655-
sizeof(ver)) < 0)
3643+
sizeof(ver)))
36563644
return false;
36573645
/* only low ROM versions need patches */
36583646
return !(le32_to_cpu(ver.rom_version) & ~0xffffU);
@@ -3670,7 +3658,7 @@ static int btusb_setup_qca(struct hci_dev *hdev)
36703658

36713659
err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
36723660
sizeof(ver));
3673-
if (err < 0)
3661+
if (err)
36743662
return err;
36753663

36763664
ver_rom = le32_to_cpu(ver.rom_version);
@@ -3693,7 +3681,7 @@ static int btusb_setup_qca(struct hci_dev *hdev)
36933681

36943682
err = btusb_qca_send_vendor_req(udev, QCA_CHECK_STATUS, &status,
36953683
sizeof(status));
3696-
if (err < 0)
3684+
if (err)
36973685
return err;
36983686

36993687
if (!(status & QCA_PATCH_UPDATED)) {
@@ -3704,7 +3692,7 @@ static int btusb_setup_qca(struct hci_dev *hdev)
37043692

37053693
err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver,
37063694
sizeof(ver));
3707-
if (err < 0)
3695+
if (err)
37083696
return err;
37093697

37103698
btdata->qca_dump.fw_version = le32_to_cpu(ver.patch_version);

0 commit comments

Comments
 (0)