Created
December 3, 2021 22:16
-
-
Save Vudentz/ffce584912eb7dc4add9c3bb25466fa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 6d6868e4c03153eda1bb137e920ef0477bf9187d (HEAD -> bluetooth-next) | |
Author: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | |
Date: Fri Dec 3 11:50:50 2021 -0800 | |
Bluetooth: mgmt: Make use of mgmt_send_event_skb in MGMT_EV_DEVICE_FOUND | |
This makes use of mgmt_alloc_skb to build MGMT_EV_DEVICE_FOUND so the | |
data is copied directly to skb that is then sent using | |
mgmt_send_event_skb eliminating the necessity of intermediary buffers. | |
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | |
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c | |
index 7d3c69c3cf62..bc2a24e7de90 100644 | |
--- a/net/bluetooth/mgmt.c | |
+++ b/net/bluetooth/mgmt.c | |
@@ -335,6 +335,13 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data, u16 len, | |
HCI_SOCK_TRUSTED, skip_sk); | |
} | |
+static int mgmt_event_skb(u16 event, struct hci_dev *hdev, struct sk_buff *skb, | |
+ struct sock *skip_sk) | |
+{ | |
+ return mgmt_send_event_skb(event, hdev, HCI_CHANNEL_CONTROL, skb, | |
+ HCI_SOCK_TRUSTED, skip_sk); | |
+} | |
+ | |
static u8 le_addr_type(u8 mgmt_addr_type) | |
{ | |
if (mgmt_addr_type == BDADDR_LE_PUBLIC) | |
@@ -9538,9 +9545,8 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, | |
u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, | |
u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len) | |
{ | |
- char buf[512]; | |
- struct mgmt_ev_device_found *ev = (void *)buf; | |
- size_t ev_size; | |
+ struct sk_buff *skb; | |
+ struct mgmt_ev_device_found *ev; | |
/* Don't send events for a non-kernel initiated discovery. With | |
* LE one exception is if we have pend_le_reports > 0 in which | |
@@ -9575,13 +9581,12 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, | |
} | |
} | |
- /* Make sure that the buffer is big enough. The 5 extra bytes | |
- * are for the potential CoD field. | |
- */ | |
- if (sizeof(*ev) + eir_len + scan_rsp_len + 5 > sizeof(buf)) | |
+ /* Allocate skb. The 5 extra bytes are for the potential CoD field */ | |
+ skb = mgmt_alloc_skb(sizeof(ev) + eir_len + scan_rsp_len + 5); | |
+ if (!skb) | |
return; | |
- memset(buf, 0, sizeof(buf)); | |
+ ev = skb_put(skb, sizeof(*ev)); | |
/* In case of device discovery with BR/EDR devices (pre 1.2), the | |
* RSSI value was reported as 0 when not available. This behavior | |
@@ -9602,21 +9607,23 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, | |
if (eir_len > 0) | |
/* Copy EIR or advertising data into event */ | |
- memcpy(ev->eir, eir, eir_len); | |
+ skb_put_data(skb, eir, eir_len); | |
- if (dev_class && !eir_get_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, | |
- NULL)) | |
- eir_len = eir_append_data(ev->eir, eir_len, EIR_CLASS_OF_DEV, | |
- dev_class, 3); | |
+ if (dev_class && !eir_get_data(eir, eir_len, EIR_CLASS_OF_DEV, NULL)) { | |
+ u8 eir_cod[5]; | |
+ | |
+ eir_len += eir_append_data(eir_cod, 0, EIR_CLASS_OF_DEV, | |
+ dev_class, 3); | |
+ skb_put_data(skb, eir_cod, eir_len); | |
+ } | |
if (scan_rsp_len > 0) | |
/* Append scan response data to event */ | |
- memcpy(ev->eir + eir_len, scan_rsp, scan_rsp_len); | |
+ skb_put_data(skb, scan_rsp, scan_rsp_len); | |
ev->eir_len = cpu_to_le16(eir_len + scan_rsp_len); | |
- ev_size = sizeof(*ev) + eir_len + scan_rsp_len; | |
- mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL); | |
+ mgmt_event_skb(MGMT_EV_DEVICE_FOUND, hdev, skb, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment