linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: apple-mfi-fastcharge: Fix kfree after failed kzalloc
@ 2020-11-15 10:28 Lucas Tanure
  0 siblings, 0 replies; only message in thread
From: Lucas Tanure @ 2020-11-15 10:28 UTC (permalink / raw)
  To: Bastien Nocera, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Lucas Tanure

kfree don't need to be called after a failed kzalloc

Signed-off-by: Lucas Tanure <tanure@linux.com>
---
Follow up patch from "USB: apple-mfi-fastcharge: Use devm_kzalloc and
simplify the code"

 drivers/usb/misc/apple-mfi-fastcharge.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index 9de0171b5177..6dedd5498e8a 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -178,16 +178,13 @@ static int mfi_fc_probe(struct usb_device *udev)
 {
 	struct power_supply_config battery_cfg = {};
 	struct mfi_device *mfi = NULL;
-	int err;
 
 	if (!mfi_fc_match(udev))
 		return -ENODEV;
 
 	mfi = kzalloc(sizeof(struct mfi_device), GFP_KERNEL);
-	if (!mfi) {
-		err = -ENOMEM;
-		goto error;
-	}
+	if (!mfi)
+		return -ENOMEM;
 
 	battery_cfg.drv_data = mfi;
 
@@ -197,18 +194,14 @@ static int mfi_fc_probe(struct usb_device *udev)
 						&battery_cfg);
 	if (IS_ERR(mfi->battery)) {
 		dev_err(&udev->dev, "Can't register battery\n");
-		err = PTR_ERR(mfi->battery);
-		goto error;
+		kfree(mfi);
+		return PTR_ERR(mfi->battery);
 	}
 
 	mfi->udev = usb_get_dev(udev);
 	dev_set_drvdata(&udev->dev, mfi);
 
 	return 0;
-
-error:
-	kfree(mfi);
-	return err;
 }
 
 static void mfi_fc_disconnect(struct usb_device *udev)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-15 10:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15 10:28 [PATCH] USB: apple-mfi-fastcharge: Fix kfree after failed kzalloc Lucas Tanure

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).