All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 11/12] usb: apple-mfi-fastcharge: Rename battery variables to psy
Date: Sun, 06 Dec 2026 02:58:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-252095@kernel.org> (raw)
In-Reply-To: <2ccb008252a1b2f6916edc9bf3cbb1876139511d.1796524906.git.rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: apple-mfi-fastcharge: NULL deref in mfi_fc_resume() during
  probe
--

commit 4d0b06a77285f110f6866355c9ab47b9f51b4b31
Author: Rosen Penev <rosenp@gmail.com>

usb: apple-mfi-fastcharge: Rename battery variables to psy

This commit renames battery, battery_desc, and battery_cfg to psy,
psy_desc, and psy_cfg in apple-mfi-fastcharge to match its
POWER_SUPPLY_TYPE_USB registration.

> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
> index 71dcf5f0bdc45..f6355db6ec99d 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c

[ ... ]

> @@ -192,27 +192,27 @@ static int mfi_fc_probe(struct usb_device *udev)

[ ... ]

> -	battery = devm_power_supply_register(&udev->dev, battery_desc, &battery_cfg);
> -	if (IS_ERR(battery))
> -		return PTR_ERR(battery);
> +	psy = devm_power_supply_register(&udev->dev, psy_desc, &psy_cfg);
> +	if (IS_ERR(psy))
> +		return PTR_ERR(psy);
>  
>  	dev_set_drvdata(&udev->dev, mfi);
>  	usb_enable_autosuspend(udev);

[Severity: High]
Can mfi_fc_resume() dereference a NULL mfi pointer during probe?

mfi_fc_probe() enables autosuspend without disabling it on disconnect.
After unbinding the driver (e.g. rmmod or sysfs unbind), dev->driver_data
is cleared to NULL while runtime PM stays enabled, so the unbound device
can autosuspend.

On rebind, really_probe() sets dev->driver before usb_probe_device().
With generic_subclass = 1, usb_probe_device() calls
usb_generic_driver_probe() -> usb_set_configuration() ->
usb_autoresume_device() -> mfi_fc_resume() before mfi_fc_probe() runs:

drivers/usb/misc/apple-mfi-fastcharge.c:mfi_fc_resume() {
	struct mfi_device *mfi = dev_get_drvdata(&udev->dev);

	guard(mutex)(&mfi->lock);
	...
}

At that point dev_get_drvdata(&udev->dev) returns NULL, causing a NULL
pointer dereference when locking &mfi->lock.

Separately, mfi_fc_probe() registers the power supply before calling
dev_set_drvdata(&udev->dev, mfi), so a concurrent write to charge_type on
a suspended device in that window triggers the same NULL pointer
dereference via apple_mfi_fc_set_property() -> pm_runtime_resume_and_get().

Checking if (!mfi) return 0 in mfi_fc_resume() and moving
dev_set_drvdata(&udev->dev, mfi) before devm_power_supply_register()
avoids both paths.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796524906.git.rosenp@gmail.com?part=11

  reply	other threads:[~2026-12-06  2:58 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
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 [this message]
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-252095@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.