Skip to contentSkip to conversation

nfc: nfcmrvl: fix memory leak in nfcmrvl_usb_nci_send()

PATCH RESEND New [email protected] 1 participant 1 message Sep 24 NFC

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 nfc: nfcmrvl: fix memory leak in nfcmrvl_usb_nci_send()

From: Yalagada Pavan Kumar <[email protected]>

nfcmrvl_usb_nci_send() gets an skb from the NCI core and sends it over USB. If the URB allocation or submission fails, the skb is left allocated and leaks.

Free the skb when URB allocation or submission fails.

Fixes f26e30cc6b50 ("NFC: nfcmrvl: Initial commit for Marvell NFC driver")
Reported-by [email protected]
---
 drivers/nfc/nfcmrvl/usb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/nfc/nfcmrvl/usb.c +7 -2
index c7f2afe00b93..7a4094797ba4 100644
@@ -224,12 +224,16 @@ static int nfcmrvl_usb_nci_send(struct nfcmrvl_private *priv,
 	unsigned int pipe;
 	int err;
 
-	if (!drv_data->bulk_tx_ep)
+	if (!drv_data->bulk_tx_ep) {
+		kfree_skb(skb);
 		return -ENODEV;
+	}
 
 	urb = usb_alloc_urb(0, GFP_ATOMIC);
-	if (!urb)
+	if (!urb) {
+		kfree_skb(skb);
 		return -ENOMEM;
+	}
 
 	pipe = usb_sndbulkpipe(drv_data->udev,
 				drv_data->bulk_tx_ep->bEndpointAddress);
@@ -254,6 +258,7 @@ static int nfcmrvl_usb_nci_send(struct nfcmrvl_private *priv,
 				"urb %p submission failed (%d)\n", urb, -err);
 		kfree(urb->setup_packet);
 		usb_unanchor_urb(urb);
+		kfree_skb(skb);
 	} else {
 		usb_mark_last_busy(drv_data->udev);
 	}
Signature · 1 line
2.43.0