diff mbox series

[2/2] usb: gadget: Fix memleak in gadgetfs_fill_super

Message ID 20201116121710.1546690-3-zhangqilong3@huawei.com
State New
Headers show
Series usb: gadget: Fix two memleaks in error handling | expand

Commit Message

Zhang Qilong Nov. 16, 2020, 12:17 p.m. UTC
usb_get_gadget_udc_name will alloc memory for CHIP
in "Enomem" branch. we should free it before error
returns to prevent memleak.

Fixes: 175f712119c57 ("usb: gadget: provide interface for legacy gadgets to get UDC name")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/usb/gadget/legacy/inode.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 1b430b36d0a6..3cefc27be098 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -2039,6 +2039,9 @@  gadgetfs_fill_super (struct super_block *sb, struct fs_context *fc)
 	return 0;
 
 Enomem:
+	free(CHIP);
+	CHIP = NULL;
+
 	return -ENOMEM;
 }