diff mbox

[Vivid,4/6] Bluetooth: btusb: Fix incorrect type in qca_device_info

Message ID 1433411157-26049-4-git-send-email-jesse.sung@canonical.com
State New
Headers show

Commit Message

Wen-chien Jesse Sung June 4, 2015, 9:45 a.m. UTC
From: "Kim, Ben Young Tae" <ytkim@qca.qualcomm.com>

BugLink: https://launchpad.net/bugs/1459937

While qca_device_info is not coming from outside communication,
no reason to use specific endian type inside and fix the wrong
version comparison on big-endian platform.

Signed-off-by: Ben Young Tae Kim <ytkim@qca.qualcomm.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
(cherry picked from commit bf906b3db3c2b4f5d4db1db5f35796629c531ac4)
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>
---
 drivers/bluetooth/btusb.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
diff mbox

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 8146ee3..f891f01 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2018,10 +2018,10 @@  struct qca_rampatch_version {
 } __packed;
 
 struct qca_device_info {
-	__le32	rom_version;
-	__u8	rampatch_hdr;	/* length of header in rampatch */
-	__u8	nvm_hdr;	/* length of header in NVM */
-	__u8	ver_offset;	/* offset of version structure in rampatch */
+	u32	rom_version;
+	u8	rampatch_hdr;	/* length of header in rampatch */
+	u8	nvm_hdr;	/* length of header in NVM */
+	u8	ver_offset;	/* offset of version structure in rampatch */
 };
 
 static const struct qca_device_info qca_devices_table[] = {
@@ -2133,11 +2133,15 @@  static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev,
 {
 	struct qca_rampatch_version *rver;
 	const struct firmware *fw;
+	u32 ver_rom, ver_patch;
+	u16 rver_rom, rver_patch;
 	char fwname[64];
 	int err;
 
-	snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin",
-		 le32_to_cpu(ver->rom_version));
+	ver_rom = le32_to_cpu(ver->rom_version);
+	ver_patch = le32_to_cpu(ver->patch_version);
+
+	snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin", ver_rom);
 
 	err = request_firmware(&fw, fwname, &hdev->dev);
 	if (err) {
@@ -2147,14 +2151,16 @@  static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev,
 	}
 
 	BT_INFO("%s: using rampatch file: %s", hdev->name, fwname);
+
 	rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset);
+	rver_rom = le16_to_cpu(rver->rom_version);
+	rver_patch = le16_to_cpu(rver->patch_version);
+
 	BT_INFO("%s: QCA: patch rome 0x%x build 0x%x, firmware rome 0x%x "
-		"build 0x%x", hdev->name, le16_to_cpu(rver->rom_version),
-		le16_to_cpu(rver->patch_version), le32_to_cpu(ver->rom_version),
-		le32_to_cpu(ver->patch_version));
+		"build 0x%x", hdev->name, rver_rom, rver_patch, ver_rom,
+		ver_patch);
 
-	if (rver->rom_version != ver->rom_version ||
-	    rver->patch_version <= ver->patch_version) {
+	if (rver_rom != ver_rom || rver_patch <= ver_patch) {
 		BT_ERR("%s: rampatch file version did not match with firmware",
 		       hdev->name);
 		err = -EINVAL;
@@ -2200,6 +2206,7 @@  static int btusb_setup_qca(struct hci_dev *hdev)
 {
 	const struct qca_device_info *info = NULL;
 	struct qca_version ver;
+	u32 ver_rom;
 	u8 status;
 	int i, err;
 
@@ -2208,13 +2215,14 @@  static int btusb_setup_qca(struct hci_dev *hdev)
 	if (err < 0)
 		return err;
 
+	ver_rom = le32_to_cpu(ver.rom_version);
 	for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
-		if (ver.rom_version == qca_devices_table[i].rom_version)
+		if (ver_rom == qca_devices_table[i].rom_version)
 			info = &qca_devices_table[i];
 	}
 	if (!info) {
 		BT_ERR("%s: don't support firmware rome 0x%x", hdev->name,
-		       le32_to_cpu(ver.rom_version));
+		       ver_rom);
 		return -ENODEV;
 	}