Linux USB
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Bastien Nocera <hadess@hadess.net>, Lucas Tanure <tanure@linux.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] USB: apple-mfi-fastcharge: Fix use after free in probe
Date: Thu, 3 Dec 2020 11:42:10 +0300	[thread overview]
Message-ID: <X8ik4j8yJitVUyfU@mwanda> (raw)

This code frees "mfi" and then derefences it on the next line to get
the error code.

Fixes: b0eec52fbe63 ("USB: apple-mfi-fastcharge: Fix kfree after failed kzalloc")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/usb/misc/apple-mfi-fastcharge.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index 6dedd5498e8a..32a17b42d57b 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -178,6 +178,7 @@ 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;
@@ -194,8 +195,9 @@ 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);
 		kfree(mfi);
-		return PTR_ERR(mfi->battery);
+		return err;
 	}
 
 	mfi->udev = usb_get_dev(udev);
-- 
2.29.2


             reply	other threads:[~2020-12-03  8:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03  8:42 Dan Carpenter [this message]
2020-12-04  9:46 ` [PATCH] USB: apple-mfi-fastcharge: Fix use after free in probe Bastien Nocera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X8ik4j8yJitVUyfU@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hadess@hadess.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=tanure@linux.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox