Linux USB
 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 01/12] usb: apple-mfi-fastcharge: Convert to devm resources
Date: Sun, 06 Dec 2026 03:00:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-252098@kernel.org> (raw)
In-Reply-To: <cfe9bf3def4e942b0bb9d1211ce65e8f9a837cb6.1796524906.git.rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] usb: apple-mfi-fastcharge: devm power supply unregister races
  with USB unbind
- [Medium] usb: apple-mfi-fastcharge: commit message describes absent
  module init fix
- [Low] usb: apple-mfi-fastcharge: stale comment still mentions .probe()
  ID check
--

commit 427d84edebb61420afc7208c728895fb30a00bfa
Author: Rosen Penev <rosenp@gmail.com>

usb: apple-mfi-fastcharge: Convert to devm resources

This commit converts apple-mfi-fastcharge to device-managed allocations and
power supply registration, removes mfi_fc_disconnect(), and drops the
mfi_fc_match() call from mfi_fc_probe().

> Also fix the module init/exit: module_usb_driver() is for struct
> usb_driver *, not struct usb_device_driver *. Use the correct
> usb_register_device_driver() / usb_deregister_device_driver() calls
> instead.

[Severity: Medium]
Should this paragraph be dropped from the commit message?

mfi_fc_driver_init() and mfi_fc_driver_exit() already call
usb_register_device_driver() and usb_deregister_device_driver(), and this
patch does not touch them.

Separately, the patch moves mfi->udev = udev before power supply
registration and drops the dev_err() on registration failure without
mentioning either change in the changelog.

> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
> index 02adec28d9e69..133dde848dd12 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c

[ ... ]

> @@ -177,67 +166,42 @@ static int mfi_fc_probe(struct usb_device *udev)
>  {
>  	struct power_supply_config battery_cfg = {};
> -	struct mfi_device *mfi = NULL;
> -	char *battery_name;
> -	int err;
> -
> -	if (!mfi_fc_match(udev))
> -		return -ENODEV;

[Severity: Low]
With mfi_fc_match() removed from mfi_fc_probe(), the comment above
mfi_fc_id_table[] still says "Those checks will be done in .match() and
.probe()."  Should that comment be updated?

[ ... ]

> +	battery = devm_power_supply_register(&udev->dev, battery_desc, &battery_cfg);
> +	if (IS_ERR(battery))
> +		return PTR_ERR(battery);
>  
> -static void mfi_fc_disconnect(struct usb_device *udev)
> -{
> -	struct mfi_device *mfi;
> -
> -	mfi = dev_get_drvdata(&udev->dev);
> -	if (mfi->battery)
> -		power_supply_unregister(mfi->battery);
> -	kfree(mfi->battery_desc.name);
> -	dev_set_drvdata(&udev->dev, NULL);
> -	kfree(mfi);
> +	return 0;
>  }
>  
>  static struct usb_device_driver mfi_fc_driver = {
>  	.name =		"apple-mfi-fastcharge",
>  	.probe =	mfi_fc_probe,
> -	.disconnect =	mfi_fc_disconnect,

[Severity: Medium]
Can switching to devm_power_supply_register() and removing
mfi_fc_disconnect() race with a concurrent sysfs write to charge_type
during USB unbind?

__device_release_driver() runs device_remove() before
device_unbind_cleanup().  Because mfi_fc_driver has no .disconnect callback
now, usb_unbind_device() runs usb_generic_driver_disconnect() and
usb_autosuspend_device() while the power supply is still registered:

CPU0                              CPU1
__device_release_driver()
  device_lock(&udev->dev)
  usb_unbind_device()
    usb_generic_driver_disconnect()
      usb_set_configuration(..., -1)
    usb_autosuspend_device()
                                  apple_mfi_fc_set_property()
                                    pm_runtime_get_sync(&udev->dev)
                                      usb_runtime_resume() <-- no device_lock
                                    usb_control_msg(...)   <-- unconfigured
  device_unbind_cleanup()
    power_supply_unregister()

A concurrent write to charge_type during rmmod or sysfs unbind can submit
vendor control request 0x40 to an unconfigured device or trigger
usb_runtime_resume() -> usb_resume_both() -> finish_port_resume() without
holding device_lock(&udev->dev) while unbind holds it.  Keeping
mfi_fc_disconnect() to call power_supply_unregister() synchronously before
usb_generic_driver_disconnect() runs avoids this window.

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

  reply	other threads:[~2026-12-06  3:00 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 [this message]
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
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-252098@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