Skip to content

Commit

Permalink
Bluetooth: btusb: Fix memory leak in btusb_mtk_wmt_recv
Browse files Browse the repository at this point in the history
[ Upstream commit de71a6c ]

In btusb_mtk_wmt_recv if skb_clone fails, the alocated skb should be
released.

Omit the labels “err_out” and “err_free_skb” in this function
implementation so that the desired exception handling code
would be directly specified in the affected if branches.

Fixes: a1c49c4 ("btusb: Add protocol support for MediaTek MT7668U USB devices")
Signed-off-by: Jupeng Zhong <zhongjupeng@yulong.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Jupeng Zhong authored and gregkh committed Mar 4, 2021
1 parent 80ace34 commit 65f9fdb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions drivers/bluetooth/btusb.c
Expand Up @@ -2568,7 +2568,7 @@ static void btusb_mtk_wmt_recv(struct urb *urb)
skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC);
if (!skb) {
hdev->stat.err_rx++;
goto err_out;
return;
}

hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
Expand All @@ -2586,13 +2586,18 @@ static void btusb_mtk_wmt_recv(struct urb *urb)
*/
if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) {
data->evt_skb = skb_clone(skb, GFP_ATOMIC);
if (!data->evt_skb)
goto err_out;
if (!data->evt_skb) {
kfree_skb(skb);
return;
}
}

err = hci_recv_frame(hdev, skb);
if (err < 0)
goto err_free_skb;
if (err < 0) {
kfree_skb(data->evt_skb);
data->evt_skb = NULL;
return;
}

if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT,
&data->flags)) {
Expand All @@ -2601,11 +2606,6 @@ static void btusb_mtk_wmt_recv(struct urb *urb)
wake_up_bit(&data->flags,
BTUSB_TX_WAIT_VND_EVT);
}
err_out:
return;
err_free_skb:
kfree_skb(data->evt_skb);
data->evt_skb = NULL;
return;
} else if (urb->status == -ENOENT) {
/* Avoid suspend failed when usb_kill_urb */
Expand Down

0 comments on commit 65f9fdb

Please sign in to comment.