Bluetooth: hci_event: Use struct_size() helper
Subsystems (4)
PATCH 1/1 Bluetooth: hci_event: Use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.
So, change the following form:
sizeof(*ev) + ev->num_hndl * sizeof(struct hci_comp_pkts_info)
to :
struct_size(ev, handles, ev->num_hndl)
This code was detected with the help of Coccinelle.
--- net/bluetooth/hci_event.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/bluetooth/hci_event.c +4 -4
@@ -3556,8 +3556,8 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)return ; } -if (skb->len <sizeof (*ev) || skb->len <sizeof (*ev) + - ev->num_hndl *sizeof (struct hci_comp_pkts_info )) { +if (skb->len <sizeof (*ev) || + skb->len <struct_size (ev, handles, ev->num_hndl)) {BT_DBG ("%s bad parameters" , hdev->name);return ; }
@@ -3644,8 +3644,8 @@ static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)return ; } -if (skb->len <sizeof (*ev) || skb->len <sizeof (*ev) + - ev->num_hndl *sizeof (struct hci_comp_blocks_info )) { +if (skb->len <sizeof (*ev) || + skb->len <struct_size (ev, handles, ev->num_hndl)) {BT_DBG ("%s bad parameters" , hdev->name);return ; }
Signature · 1 line
2.20.1
Quoted 6 lines · Gustavo A. R. Silva
Make use of the
struct_size()helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.So, change the following form:
Quoted 7 lines
sizeof(*ev)+ev->num_hndl*sizeof(struct hci_comp_pkts_info)to :
struct_size(ev, handles, ev->num_hndl)This code was detected with the help of Coccinelle.
[]
net/bluetooth/hci_event.c
Quoted 1 line
net/bluetooth/hci_event.c +0
-0
[]
Quoted 12 lines
net/bluetooth/hci_event.c +2
-2@@ -3556,8 +3556,8 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)return ; } -if (skb->len <sizeof (*ev) || skb->len <sizeof (*ev) + - ev->num_hndl *sizeof (struct hci_comp_pkts_info )) { +if (skb->len <sizeof (*ev) || + skb->len <struct_size (ev, handles, ev->num_hndl)) {BT_DBG ("%s bad parameters" , hdev->name);return ; }
net/bluetooth/hci_event.c static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb) · line 3648
Quoted 7 lines
net/bluetooth/hci_event.c +2
-2@@ -3644,8 +3644,8 @@ static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)return ; } -if (skb->len <sizeof (*ev) || skb->len <sizeof (*ev) + - ev->num_hndl *sizeof (struct hci_comp_blocks_info )) { +if (skb->len <sizeof (*ev) || + skb->len <struct_size (ev, handles, ev->num_hndl)) {
Unless these are in a real fast path where skb->len < sizeof(*ev) is pretty likely, it seems a bit redundant as the multiplication is pretty cheap and num_hndl is unsigned (actually __u8)
This could/should be simply
if (skb->len < struct_size(...))
Marcel Holtmann
maintainerHi Gustavo,
Quoted 10 lines
Make use of the
struct_size()helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.So, change the following form:
sizeof(*ev)+ev->num_hndl*sizeof(struct hci_comp_pkts_info)to :
Quoted 8 lines
struct_size(ev, handles, ev->num_hndl)This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>---
net/bluetooth/hci_event.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel