Skip to content

Commit

Permalink
usb: dwc3: fix memory leak of dwc->regset
Browse files Browse the repository at this point in the history
dwc->regset is allocated on dwc3_debugfs_init, and should
be released on init failure or dwc3_debugfs_exit. Btw,
The line "dwc->root = NULL" is unnecessary, so remove it.

Signed-off-by: Du, Changbin <changbin.du@intel.com>

[ felipe.balbi@linux.intel.com : add another err label for the new
	error condition ]

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
  • Loading branch information
Du, Changbin authored and Felipe Balbi committed Apr 18, 2016
1 parent 5c4ad31 commit e6bdf81
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/usb/dwc3/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,15 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
if (!file) {
ret = -ENOMEM;
goto err1;
goto err2;
}

if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_mode_fops);
if (!file) {
ret = -ENOMEM;
goto err1;
goto err2;
}
}

Expand All @@ -663,19 +663,22 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
dwc, &dwc3_testmode_fops);
if (!file) {
ret = -ENOMEM;
goto err1;
goto err2;
}

file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
dwc, &dwc3_link_state_fops);
if (!file) {
ret = -ENOMEM;
goto err1;
goto err2;
}
}

return 0;

err2:
kfree(dwc->regset);

err1:
debugfs_remove_recursive(root);

Expand All @@ -686,5 +689,5 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
void dwc3_debugfs_exit(struct dwc3 *dwc)
{
debugfs_remove_recursive(dwc->root);
dwc->root = NULL;
kfree(dwc->regset);
}

0 comments on commit e6bdf81

Please sign in to comment.