Skip to content

Commit de71a6c

Browse files
Jupeng Zhongholtmann
authored andcommitted
Bluetooth: btusb: Fix memory leak in btusb_mtk_wmt_recv
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 <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent e8bd76e commit de71a6c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/bluetooth/btusb.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ static void btusb_mtk_wmt_recv(struct urb *urb)
32413241
skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC);
32423242
if (!skb) {
32433243
hdev->stat.err_rx++;
3244-
goto err_out;
3244+
return;
32453245
}
32463246

32473247
hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
@@ -3259,13 +3259,18 @@ static void btusb_mtk_wmt_recv(struct urb *urb)
32593259
*/
32603260
if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) {
32613261
data->evt_skb = skb_clone(skb, GFP_ATOMIC);
3262-
if (!data->evt_skb)
3263-
goto err_out;
3262+
if (!data->evt_skb) {
3263+
kfree_skb(skb);
3264+
return;
3265+
}
32643266
}
32653267

32663268
err = hci_recv_frame(hdev, skb);
3267-
if (err < 0)
3268-
goto err_free_skb;
3269+
if (err < 0) {
3270+
kfree_skb(data->evt_skb);
3271+
data->evt_skb = NULL;
3272+
return;
3273+
}
32693274

32703275
if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT,
32713276
&data->flags)) {
@@ -3274,11 +3279,6 @@ static void btusb_mtk_wmt_recv(struct urb *urb)
32743279
wake_up_bit(&data->flags,
32753280
BTUSB_TX_WAIT_VND_EVT);
32763281
}
3277-
err_out:
3278-
return;
3279-
err_free_skb:
3280-
kfree_skb(data->evt_skb);
3281-
data->evt_skb = NULL;
32823282
return;
32833283
} else if (urb->status == -ENOENT) {
32843284
/* Avoid suspend failed when usb_kill_urb */

0 commit comments

Comments
 (0)