Skip to content

Commit

Permalink
Bluetooth: btmtkuart: fix error handling in mtk_hci_wmt_sync()
Browse files Browse the repository at this point in the history
This code has an uninitialized variable warning:

    drivers/bluetooth/btmtkuart.c:184 mtk_hci_wmt_sync()
    error: uninitialized symbol 'wc'.

But it also has error paths which have memory leaks.

Fixes: 8f550f55b155 ("Bluetooth: btmtkuart: rely on BT_MTK module")
Signed-off-by: Dan Carpenter <[email protected]>
Signed-off-by: Marcel Holtmann <[email protected]>
  • Loading branch information
Dan Carpenter authored and holtmann committed Mar 18, 2022
1 parent 9fa6b4c commit a76d269
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/bluetooth/btmtkuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
}

wc = kzalloc(hlen, GFP_KERNEL);
if (!wc)
return -ENOMEM;
if (!wc) {
err = -ENOMEM;
goto err_free_skb;
}

hdr = &wc->hdr;
hdr->dir = 1;
Expand Down Expand Up @@ -153,7 +155,7 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
bt_dev_err(hdev, "Wrong op received %d expected %d",
wmt_evt->whdr.op, hdr->op);
err = -EIO;
goto err_free_skb;
goto err_free_wc;
}

switch (wmt_evt->whdr.op) {
Expand All @@ -177,11 +179,11 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
if (wmt_params->status)
*wmt_params->status = status;

err_free_wc:
kfree(wc);
err_free_skb:
kfree_skb(bdev->evt_skb);
bdev->evt_skb = NULL;
err_free_wc:
kfree(wc);

return err;
}
Expand Down

0 comments on commit a76d269

Please sign in to comment.