From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 07/12] usb: apple-mfi-fastcharge: Restore charge current on resume
Date: Sun, 06 Dec 2026 03:05:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-252103@kernel.org> (raw)
In-Reply-To: <b1b0b35337eac3affa7860ae9f74dd5fe5af93cb.1796524906.git.rosenp@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: apple-mfi-fastcharge: NULL deref in mfi_fc_resume() on
probe autoresume
- [Medium] usb: apple-mfi-fastcharge: mfi_fc_resume() races with unbind
teardown
--
commit 86e6119152426dd019ad71e148c2e276d8b2358f
Author: Rosen Penev <rosenp@gmail.com>
usb: apple-mfi-fastcharge: Restore charge current on resume
This commit adds a resume callback to reprogram the fast charge current
after suspend/resume and refactors the USB control transfer into
apple_mfi_fc_send_current().
> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
> index 49644922c5b51..85cf970e5f5eb 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c
[ ... ]
> @@ -194,12 +203,31 @@ static int mfi_fc_probe(struct usb_device *udev)
> if (IS_ERR(battery))
> return PTR_ERR(battery);
>
> + dev_set_drvdata(&udev->dev, mfi);
> +
> + return 0;
> +}
> +
> +static int mfi_fc_resume(struct usb_device *udev, pm_message_t message)
> +{
> + struct mfi_device *mfi = dev_get_drvdata(&udev->dev);
> +
> + /*
> + * A failure here must not fail the resume: the USB core would then
> + * skip resuming the device's interfaces. Fall back to trickle so a
> + * later write of "Fast" is sent to the device again.
> + */
> + if (mfi->charge_type == POWER_SUPPLY_CHARGE_TYPE_FAST &&
> + apple_mfi_fc_send_current(mfi, FAST_CURRENT_MA) < 0)
> + mfi->charge_type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
> +
> return 0;
> }
[Severity: High]
Can mfi be NULL here if the device is runtime-suspended when the driver
binds?
really_probe() sets udev->dev.driver before usb_probe_device() runs,
which calls usb_autoresume_device() (directly and via
usb_generic_driver_probe() -> usb_set_configuration()) before
mfi_fc_probe() sets drvdata.
When udev is runtime-suspended, usb_resume_device() invokes
mfi_fc_resume() with NULL drvdata, causing a NULL pointer dereference on
mfi->charge_type. Returning 0 when !mfi avoids the crash.
[Severity: Medium]
Can mfi_fc_resume() race with driver unbind and dereference a freed mfi?
During unbind, __device_release_driver() drops its runtime PM reference
before device_remove() and device_unbind_cleanup(), and
usb_unbind_device() autosuspends udev without disabling runtime PM.
A concurrent port runtime resume can then queue
pm_request_resume(&udev->dev) without device_lock(&udev->dev), letting
usb_resume_device() call mfi_fc_resume() during teardown:
CPU0 (unbind) CPU1
__device_release_driver()
pm_runtime_put_sync(dev)
usb_unbind_device()
usb_autosuspend_device(udev)
usb_port_runtime_resume()
pm_request_resume(&udev->dev)
usb_resume_device()
udriver = udev->dev.driver
usb_generic_driver_resume()
device_unbind_cleanup()
devres_release_all(dev)
mfi_fc_resume()
mfi = dev_get_drvdata(...)
mfi->charge_type <-- use-after-free
device_set_driver(dev, NULL)
dev_set_drvdata(dev, NULL)
devres_release_all() frees mfi before dev->driver and dev->driver_data
are cleared, and pm_runtime_reinit() returns early while runtime PM is
enabled. Depending on timing, mfi_fc_resume() hits a use-after-free, a
NULL pointer dereference, or unloaded module text during rmmod.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796524906.git.rosenp@gmail.com?part=7
next prev parent reply other threads:[~2026-12-06 3:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 2:44 [PATCH 00/12] usb: apple-mfi-fastcharge: Fixes and cleanups Rosen Penev
2026-12-06 2:44 ` [PATCH 01/12] usb: apple-mfi-fastcharge: Convert to devm resources Rosen Penev
2026-12-06 3:00 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 02/12] usb: apple-mfi-fastcharge: Use pm_runtime_resume_and_get() Rosen Penev
2026-12-06 2:44 ` [PATCH 03/12] usb: apple-mfi-fastcharge: Fix usb_control_msg() return check and timeout Rosen Penev
2026-12-06 2:44 ` [PATCH 04/12] usb: apple-mfi-fastcharge: Use POWER_SUPPLY_TYPE_USB instead of BATTERY Rosen Penev
2026-12-06 3:04 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 05/12] usb: apple-mfi-fastcharge: Constify power_supply_property array Rosen Penev
2026-12-06 2:44 ` [PATCH 06/12] usb: apple-mfi-fastcharge: Use topology-based device name Rosen Penev
2026-12-06 2:44 ` [PATCH 07/12] usb: apple-mfi-fastcharge: Restore charge current on resume Rosen Penev
2026-12-06 3:05 ` sashiko-bot [this message]
2026-12-06 2:44 ` [PATCH 08/12] usb: apple-mfi-fastcharge: Serialize charge_type access with a mutex Rosen Penev
2026-12-06 3:07 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 09/12] usb: apple-mfi-fastcharge: Configure runtime PM autosuspend Rosen Penev
2026-12-06 3:05 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 10/12] usb: apple-mfi-fastcharge: Name the vendor power request Rosen Penev
2026-12-06 2:44 ` [PATCH 11/12] usb: apple-mfi-fastcharge: Rename battery variables to psy Rosen Penev
2026-12-06 2:58 ` sashiko-bot
2026-12-06 2:44 ` [PATCH 12/12] usb: apple-mfi-fastcharge: Simplify match and property_is_writeable Rosen Penev
2026-12-06 3:06 ` sashiko-bot
2026-12-06 3:07 ` [PATCH 00/12] usb: apple-mfi-fastcharge: Fixes and cleanups sashiko-bot
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=sashiko-outbox-252103@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rosenp@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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