diff mbox series

Bluetooth: btmtkuart: fix error handling in mtk_hci_wmt_sync()

Message ID 20220317075740.GE25237@kili (mailing list archive)
State New, archived
Headers show
Series Bluetooth: btmtkuart: fix error handling in mtk_hci_wmt_sync() | expand

Commit Message

Dan Carpenter March 17, 2022, 7:57 a.m. UTC
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 <dan.carpenter@oracle.com>
---
 drivers/bluetooth/btmtkuart.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Marcel Holtmann March 17, 2022, 11:12 a.m. UTC | #1
Hi Dan,

> 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 <dan.carpenter@oracle.com>
> ---
> drivers/bluetooth/btmtkuart.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel
patchwork-bot+bluetooth@kernel.org March 17, 2022, 11:20 a.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Marcel Holtmann <marcel@holtmann.org>:

On Thu, 17 Mar 2022 10:57:40 +0300 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - Bluetooth: btmtkuart: fix error handling in mtk_hci_wmt_sync()
    https://git.kernel.org/bluetooth/bluetooth-next/c/65d6602f6334

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/bluetooth/btmtkuart.c b/drivers/bluetooth/btmtkuart.c
index 695e1225b08c..c98691cdbbd5 100644
--- a/drivers/bluetooth/btmtkuart.c
+++ b/drivers/bluetooth/btmtkuart.c
@@ -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;
@@ -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) {
@@ -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;
 }