RFC: Bluetooth: missed cpu_to_le16 conversion in hci_init4_req
Subsystems (4)
PATCH 1/1 RFC: Bluetooth: missed cpu_to_le16 conversion in hci_init4_req
It looks like in hci_init4_req() the request is being initialised from cpu-endian data but the packet is specified to be little-endian. This causes an warning from sparse due to __le16 to u16 conversion.
Fix this by using cpu_to_le16() on the two fields in the packet.
net/bluetooth/hci_core.c:845:27: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:845:27: expected restricted __le16 [usertype] tx_lennet/bluetooth/hci_core.c:845:27: got unsigned short [usertype] le_max_tx_lennet/bluetooth/hci_core.c:846:28: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:846:28: expected restricted __le16 [usertype] tx_timenet/bluetooth/hci_core.c:846:28: got unsigned short [usertype] le_max_tx_time
---
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
--- net/bluetooth/hci_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/hci_core.c +2 -2
@@ -842,8 +842,8 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt)if (hdev->le_features[0 ] &HCI_LE_DATA_LEN_EXT ) {struct hci_cp_le_write_def_data_len cp; - cp.tx_len = hdev->le_max_tx_len; - cp.tx_time = hdev->le_max_tx_time; + cp.tx_len =cpu_to_le16 (hdev->le_max_tx_len); + cp.tx_time =cpu_to_le16 (hdev->le_max_tx_time);hci_req_add (req,HCI_OP_LE_WRITE_DEF_DATA_LEN ,sizeof (cp), &cp); }
Signature · 1 line
2.23.0
Quoted 31 lines · Ben Dooks (Codethink)
It looks like in
hci_init4_req()the request is being initialised from cpu-endian data but the packet is specified to be little-endian. This causes an warning from sparse due to__le16to u16 conversion.Fix this by using
cpu_to_le16()on the two fields in the packet.
net/bluetooth/hci_core.c:845:27: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:845:27: expected restricted__le16[usertype]tx_lennet/bluetooth/hci_core.c:845:27: got unsigned short [usertype]le_max_tx_lennet/bluetooth/hci_core.c:846:28: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:846:28: expected restricted__le16[usertype]tx_timenet/bluetooth/hci_core.c:846:28: got unsigned short [usertype]le_max_tx_timeSigned-off-by Ben Dooks <[email protected]>---
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- net/bluetooth/hci_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/bluetooth/hci_core.c +0
-0
net/bluetooth/hci_core.c static int hci_init4_req(struct hci_request *req, unsigned long opt) · line 846
Quoted 7 lines
net/bluetooth/hci_core.c +2
-2@@ -842,8 +842,8 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt)if (hdev->le_features[0 ] &HCI_LE_DATA_LEN_EXT ) {struct hci_cp_le_write_def_data_len cp; - cp.tx_len = hdev->le_max_tx_len; - cp.tx_time = hdev->le_max_tx_time; + cp.tx_len =cpu_to_le16 (hdev->le_max_tx_len); + cp.tx_time =cpu_to_le16 (hdev->le_max_tx_time);
I would suggest that the naming of the le_ fields of struct hci_dev implies that the values stored in those fields should be little endian (but those that are more than bone byte wide are not).
In any case, the question arises as to if this has ever worked on big endian machines.
Quoted 6 lines
net/bluetooth/hci_core.c +0
-0hci_req_add (req,HCI_OP_LE_WRITE_DEF_DATA_LEN ,sizeof (cp), &cp); }Signature · 1 line
2.23.0
Marcel Holtmann
maintainerHi Simon,
Quoted 34 lines
Quoted 34 lines
It looks like in
hci_init4_req()the request is being initialised from cpu-endian data but the packet is specified to be little-endian. This causes an warning from sparse due to__le16to u16 conversion.Fix this by using
cpu_to_le16()on the two fields in the packet.
net/bluetooth/hci_core.c:845:27: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:845:27: expected restricted__le16[usertype]tx_lennet/bluetooth/hci_core.c:845:27: got unsigned short [usertype]le_max_tx_lennet/bluetooth/hci_core.c:846:28: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:846:28: expected restricted__le16[usertype]tx_timenet/bluetooth/hci_core.c:846:28: got unsigned short [usertype]le_max_tx_timeSigned-off-by Ben Dooks <[email protected]>---
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---net/bluetooth/hci_core.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)net/bluetooth/hci_core.c +0
-0@@ -842,8 +842,8 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt)if (hdev->le_features[0 ] &HCI_LE_DATA_LEN_EXT ) {struct hci_cp_le_write_def_data_len cp;
Quoted 8 lines
net/bluetooth/hci_core.c static int hci_init4_req(struct hci_request *req, unsigned long opt) · line 846
Quoted 4 lines
net/bluetooth/hci_core.c +2
-2- cp.tx_len = hdev->le_max_tx_len; - cp.tx_time = hdev->le_max_tx_time; + cp.tx_len =cpu_to_le16 (hdev->le_max_tx_len); + cp.tx_time =cpu_to_le16 (hdev->le_max_tx_time);I would suggest that the naming of the
le_fields of structhci_devimplies that the values stored in those fields should be little endian (but those that are more than bone byte wide are not).
the le_ stands for Low Energy and not for Little Endian.
Regards
Marcel
Quoted 45 lines · Marcel Holtmann
Hi Simon,
Quoted 34 lines
Quoted 34 lines
It looks like in
hci_init4_req()the request is being initialised from cpu-endian data but the packet is specified to be little-endian. This causes an warning from sparse due to__le16to u16 conversion.Fix this by using
cpu_to_le16()on the two fields in the packet.
net/bluetooth/hci_core.c:845:27: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:845:27: expected restricted__le16[usertype]tx_lennet/bluetooth/hci_core.c:845:27: got unsigned short [usertype]le_max_tx_lennet/bluetooth/hci_core.c:846:28: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:846:28: expected restricted__le16[usertype]tx_timenet/bluetooth/hci_core.c:846:28: got unsigned short [usertype]le_max_tx_timeSigned-off-by Ben Dooks <[email protected]>---
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---net/bluetooth/hci_core.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)net/bluetooth/hci_core.c +0
-0@@ -842,8 +842,8 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt)if (hdev->le_features[0 ] &HCI_LE_DATA_LEN_EXT ) {struct hci_cp_le_write_def_data_len cp;Quoted 8 lines
net/bluetooth/hci_core.c static int hci_init4_req(struct hci_request *req, unsigned long opt) · line 846
Quoted 4 lines
net/bluetooth/hci_core.c +2
-2- cp.tx_len = hdev->le_max_tx_len; - cp.tx_time = hdev->le_max_tx_time; + cp.tx_len =cpu_to_le16 (hdev->le_max_tx_len); + cp.tx_time =cpu_to_le16 (hdev->le_max_tx_time);I would suggest that the naming of the
le_fields of structhci_devimplies that the values stored in those fields should be little endian (but those that are more than bone byte wide are not).
Quoted 1 line
the
le_stands for Low Energy and not for Little Endian.
Thanks, in that case I have no objections.
Marcel Holtmann
maintainerHi Ben,
Quoted 24 lines
It looks like in
hci_init4_req()the request is being initialised from cpu-endian data but the packet is specified to be little-endian. This causes an warning from sparse due to__le16to u16 conversion.Fix this by using
cpu_to_le16()on the two fields in the packet.
net/bluetooth/hci_core.c:845:27: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:845:27: expected restricted__le16[usertype]tx_lennet/bluetooth/hci_core.c:845:27: got unsigned short [usertype]le_max_tx_lennet/bluetooth/hci_core.c:846:28: warning: incorrect type in assignment (different base types)net/bluetooth/hci_core.c:846:28: expected restricted__le16[usertype]tx_timenet/bluetooth/hci_core.c:846:28: got unsigned short [usertype]le_max_tx_timeSigned-off-by Ben Dooks <[email protected]>---
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---net/bluetooth/hci_core.c| 4 ++--
Quoted 1 line
1 file changed, 2 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel