Skip to content

Commit c7bd5c9

Browse files
kirankrishnappa-intelgregkh
authored andcommitted
Bluetooth: btintel_pcie: Avoid redundant buffer allocation
[ Upstream commit d1af1f0 ] Reuse the skb buffer provided by the PCIe driver to pass it onto the stack, instead of copying it to a new skb. Fixes: c2b636b ("Bluetooth: btintel_pcie: Add support for PCIe transport") Signed-off-by: Kiran K <kiran.k@intel.com> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 620810a commit c7bd5c9

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

drivers/bluetooth/btintel_pcie.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,10 @@ static int btintel_pcie_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
581581
/* This is a debug event that comes from IML and OP image when it
582582
* starts execution. There is no need pass this event to stack.
583583
*/
584-
if (skb->data[2] == 0x97)
584+
if (skb->data[2] == 0x97) {
585+
hci_recv_diag(hdev, skb);
585586
return 0;
587+
}
586588
}
587589

588590
return hci_recv_frame(hdev, skb);
@@ -598,7 +600,6 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
598600
u8 pkt_type;
599601
u16 plen;
600602
u32 pcie_pkt_type;
601-
struct sk_buff *new_skb;
602603
void *pdata;
603604
struct hci_dev *hdev = data->hdev;
604605

@@ -675,24 +676,20 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
675676

676677
bt_dev_dbg(hdev, "pkt_type: 0x%2.2x len: %u", pkt_type, plen);
677678

678-
new_skb = bt_skb_alloc(plen, GFP_ATOMIC);
679-
if (!new_skb) {
680-
bt_dev_err(hdev, "Failed to allocate memory for skb of len: %u",
681-
skb->len);
682-
ret = -ENOMEM;
683-
goto exit_error;
684-
}
685-
686-
hci_skb_pkt_type(new_skb) = pkt_type;
687-
skb_put_data(new_skb, skb->data, plen);
679+
hci_skb_pkt_type(skb) = pkt_type;
688680
hdev->stat.byte_rx += plen;
681+
skb_trim(skb, plen);
689682

690683
if (pcie_pkt_type == BTINTEL_PCIE_HCI_EVT_PKT)
691-
ret = btintel_pcie_recv_event(hdev, new_skb);
684+
ret = btintel_pcie_recv_event(hdev, skb);
692685
else
693-
ret = hci_recv_frame(hdev, new_skb);
686+
ret = hci_recv_frame(hdev, skb);
687+
skb = NULL; /* skb is freed in the callee */
694688

695689
exit_error:
690+
if (skb)
691+
kfree_skb(skb);
692+
696693
if (ret)
697694
hdev->stat.err_rx++;
698695

@@ -706,16 +703,10 @@ static void btintel_pcie_rx_work(struct work_struct *work)
706703
struct btintel_pcie_data *data = container_of(work,
707704
struct btintel_pcie_data, rx_work);
708705
struct sk_buff *skb;
709-
int err;
710-
struct hci_dev *hdev = data->hdev;
711706

712707
/* Process the sk_buf in queue and send to the HCI layer */
713708
while ((skb = skb_dequeue(&data->rx_skb_q))) {
714-
err = btintel_pcie_recv_frame(data, skb);
715-
if (err)
716-
bt_dev_err(hdev, "Failed to send received frame: %d",
717-
err);
718-
kfree_skb(skb);
709+
btintel_pcie_recv_frame(data, skb);
719710
}
720711
}
721712

0 commit comments

Comments
 (0)