Bluetooth: Fix broken usage of get_unaligned_le16
Subsystems (2)
Marcel Holtmann
maintainerPATCH 1/1 Bluetooth: Fix broken usage of get_unaligned_le16
In case the struct is already __packed, there is no need to use unaligned access to the data. So just use __le16_to_cpu in these cases.
--- net/bluetooth/mgmt.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
net/bluetooth/mgmt.c +6 -6
@@ -862,7 +862,7 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,BT_DBG ("request for %s" , hdev->name); - timeout =get_unaligned_le16 (&cp->timeout); + timeout =__le16_to_cpu (cp->timeout);if (!cp->val && timeout >0 )return cmd_status (sk, hdev->id,MGMT_OP_SET_DISCOVERABLE ,MGMT_STATUS_INVALID_PARAMS );
@@ -1461,7 +1461,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,u16 key_count, expected_len;int i; - key_count =get_unaligned_le16 (&cp->key_count); + key_count =__le16_to_cpu (cp->key_count); expected_len =sizeof (*cp) + key_count *sizeof (struct mgmt_link_key_info );
@@ -2606,7 +2606,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,u16 key_count, expected_len;int i; - key_count =get_unaligned_le16 (&cp->key_count); + key_count =__le16_to_cpu (cp->key_count); expected_len =sizeof (*cp) + key_count *sizeof (struct mgmt_ltk_info );
@@ -2717,9 +2717,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) } hdr = buf; - opcode =get_unaligned_le16 (&hdr->opcode); - index =get_unaligned_le16 (&hdr->index); - len =get_unaligned_le16 (&hdr->len); + opcode =__le16_to_cpu (hdr->opcode); + index =__le16_to_cpu (hdr->index); + len =__le16_to_cpu (hdr->len);if (len != msglen -sizeof (*hdr)) { err = -EINVAL ;
Signature · 1 line
1.7.7.6
Hi Marcel,
Quoted 2 lines · Marcel Holtmann
In case the struct is already
__packed, there is no need to use unaligned access to the data. So just use__le16_to_cpuin these cases.
One minor comment related to use of __xxx versions. What is the general rule when to use __le16_to_cpu and when le16_to_cpu? In mgmt.c looks that mostly in use version without underscore.
Best regards
Andrei Emeltchenko
Quoted 57 lines
Signed-off-by Marcel Holtmann <[email protected]>--- net/bluetooth/mgmt.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)net/bluetooth/mgmt.c +6
-6@@ -862,7 +862,7 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,BT_DBG ("request for %s" , hdev->name); - timeout =get_unaligned_le16 (&cp->timeout); + timeout =__le16_to_cpu (cp->timeout);if (!cp->val && timeout >0 )return cmd_status (sk, hdev->id,MGMT_OP_SET_DISCOVERABLE ,MGMT_STATUS_INVALID_PARAMS );@@ -1461,7 +1461,7 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,u16 key_count, expected_len;int i; - key_count =get_unaligned_le16 (&cp->key_count); + key_count =__le16_to_cpu (cp->key_count); expected_len =sizeof (*cp) + key_count *sizeof (struct mgmt_link_key_info );@@ -2606,7 +2606,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,u16 key_count, expected_len;int i; - key_count =get_unaligned_le16 (&cp->key_count); + key_count =__le16_to_cpu (cp->key_count); expected_len =sizeof (*cp) + key_count *sizeof (struct mgmt_ltk_info );@@ -2717,9 +2717,9 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) } hdr = buf; - opcode =get_unaligned_le16 (&hdr->opcode); - index =get_unaligned_le16 (&hdr->index); - len =get_unaligned_le16 (&hdr->len); + opcode =__le16_to_cpu (hdr->opcode); + index =__le16_to_cpu (hdr->index); + len =__le16_to_cpu (hdr->len);if (len != msglen -sizeof (*hdr)) { err = -EINVAL ;Signature · 6 lines
1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Marcel Holtmann
maintainerHi Andrei,
Quoted 6 lines
Quoted 2 lines
In case the struct is already
__packed, there is no need to use unaligned access to the data. So just use__le16_to_cpuin these cases.One minor comment related to use of
__xxxversions. What is the general rule when to use__le16_to_cpuand whenle16_to_cpu? Inmgmt.clooks that mostly in use version without underscore.
honestly I do not know. We have been using __le16_to_cpu and cpu_to_le16 as long as I can remember.
Regards
Marcel
Johan Hedberg
AppliedHi Marcel,
Quoted 7 lines · Marcel Holtmann
In case the struct is already
__packed, there is no need to use unaligned access to the data. So just use__le16_to_cpuin these cases.Signed-off-by Marcel Holtmann <[email protected]>--- net/bluetooth/mgmt.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
Applied. Thanks.
Johan