mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
Bluetooth: btmtk: Fix short read errors in btmtk_usb_reg_read()
If btmtk_usb_reg_read() 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 btmtk_usb_reg_read() is called (it's really just btmtk_usb_id_get() that calls btmtk_usb_reg_read(), so fix up those return sites. 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>
This commit is contained in:
committed by
Luiz Augusto von Dentz
parent
b186c18c48
commit
0cc4b5649a
+15
-21
@@ -827,27 +827,21 @@ static int btmtk_usb_uhw_reg_read(struct hci_dev *hdev, u32 reg, u32 *val)
|
||||
static int btmtk_usb_reg_read(struct hci_dev *hdev, u32 reg, u32 *val)
|
||||
{
|
||||
struct btmtk_data *data = hci_get_priv(hdev);
|
||||
int pipe, err, size = sizeof(u32);
|
||||
void *buf;
|
||||
u8 buf[sizeof(u32)];
|
||||
int err;
|
||||
|
||||
buf = kzalloc(size, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
pipe = usb_rcvctrlpipe(data->udev, 0);
|
||||
err = usb_control_msg(data->udev, pipe, 0x63,
|
||||
USB_TYPE_VENDOR | USB_DIR_IN,
|
||||
reg >> 16, reg & 0xffff,
|
||||
buf, size, USB_CTRL_GET_TIMEOUT);
|
||||
*val = 0;
|
||||
err = usb_control_msg_recv(data->udev, 0, 0x63,
|
||||
USB_TYPE_VENDOR | USB_DIR_IN,
|
||||
reg >> 16, reg & 0xffff,
|
||||
buf, sizeof(buf), USB_CTRL_GET_TIMEOUT,
|
||||
GFP_KERNEL);
|
||||
if (err < 0)
|
||||
goto err_free_buf;
|
||||
return err;
|
||||
|
||||
*val = get_unaligned_le32(buf);
|
||||
|
||||
err_free_buf:
|
||||
kfree(buf);
|
||||
|
||||
return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btmtk_usb_id_get(struct hci_dev *hdev, u32 reg, u32 *id)
|
||||
@@ -974,7 +968,7 @@ int btmtk_usb_subsys_reset(struct hci_dev *hdev, u32 dev_id)
|
||||
}
|
||||
|
||||
err = btmtk_usb_id_get(hdev, 0x70010200, &val);
|
||||
if (err < 0 || (!val && dev_id != 0x6639))
|
||||
if (err || (!val && dev_id != 0x6639))
|
||||
bt_dev_err(hdev, "Can't get device id, subsys reset fail.");
|
||||
|
||||
return err;
|
||||
@@ -1318,24 +1312,24 @@ int btmtk_usb_setup(struct hci_dev *hdev)
|
||||
calltime = ktime_get();
|
||||
|
||||
err = btmtk_usb_id_get(hdev, 0x80000008, &dev_id);
|
||||
if (err < 0) {
|
||||
if (err) {
|
||||
bt_dev_err(hdev, "Failed to get device id (%d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!dev_id || dev_id != 0x7663) {
|
||||
err = btmtk_usb_id_get(hdev, 0x70010200, &dev_id);
|
||||
if (err < 0) {
|
||||
if (err) {
|
||||
bt_dev_err(hdev, "Failed to get device id (%d)", err);
|
||||
return err;
|
||||
}
|
||||
err = btmtk_usb_id_get(hdev, 0x80021004, &fw_version);
|
||||
if (err < 0) {
|
||||
if (err) {
|
||||
bt_dev_err(hdev, "Failed to get fw version (%d)", err);
|
||||
return err;
|
||||
}
|
||||
err = btmtk_usb_id_get(hdev, 0x70010020, &fw_flavor);
|
||||
if (err < 0) {
|
||||
if (err) {
|
||||
bt_dev_err(hdev, "Failed to get fw flavor (%d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user