From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796526308; b=MoT8CjrkN+y26zFbwTuS7gQIWxKU00aDjydffX/jf7ziZOZuotDiVR/h47r32Byu6XHu 2zwBGmZzkQqL1LJvJz0KVThlsfYrOnphZLK7cLBjh88Eh4uO3mXyra7e4SH05L8NLI+8E rm/cnTu7hstf+xTdpzU6BvDRB/exCCzHK7uqlh7ZNcQPtulqJ/kI5bt4+QFhMoSGVhkd2 mateNA38lVd2QlUUYkWUPTthTRgO8CmPtPyeZ/hirhbW43cLjaVyVaJry1WenCv9uGJYm KzyktHlfubrffPOaJSUwZuam4cXaVXiM9t3ZqwKXSuwJjF/rPv0VzwJsC+hop0jsUjQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796526308; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bjsyeyZDDQubGF4nQOn0vIvaPue0gFCyXFMliJZxhlg=; b=HEQmnH7Usa6F0NZXKQTpAVcw73NhfnNRC/RQ9lLnUYPRvx2iggRje1GS/OuZwG3Bpw9U 2XJ60yRwJpdm7KqLAZyLNUlzTUpj638shIZa+twu/JU9PsJLNzB+Lmh41XRjvJTPjER0y eNTPt/fgkDZ82z9BSWIirXW++Dt17k++B0/d7MPtTHiYk/ij+L0hhXNuSr6iWEAiFvpct DOSILKdiRft4gwdfzegPM5ZCAtBiPmYZBTwP3vjdQjLPgOSlmo9hmyK8v2ws7eXPYKQdy a8RWyXejqOlXTNHjvSeQseqtPuML9aFA3XFd+wQhVGrWEnLF4H5+MEsXZrwqZO4XAZg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=btaey41k; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F953606A31F for ; Sun, 6 Dec 2026 03:05:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=btaey41k Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D3881F0092B; Sun, 6 Dec 2026 03:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796526308; bh=bjsyeyZDDQubGF4nQOn0vIvaPue0gFCyXFMliJZxhlg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=btaey41kn+d4WJ7yAQJjLzz+zKvXxzGzFSesqeZPcZ52/dCVOckHgFb0M2Kb2XBjc foQB5HLAlfIcgNTc4j4s2oIszUjPnDmF1qHk4eTMSrumfZkqFF5GkGhq+841D6c3On H59d2cwDVUGKWKS/L4i2QY6FRmNtwZyCjkOwm0hHYmwBqHPhSFVPMzFK96yjc+Z0Ny 0sGudVS5p+tJK+lqYmhPjmLFCCR03xRG7+zgBKedUD3fgVJF/++4+ab80BVvUXjvmU EtYzz1H79zDfIm5UMHTsJQ8VNiZH/3U2yRhVoW1R4vnkF3S84rffBMop7PSKUteSkE MyhLhB3ufLNTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 09/12] usb: apple-mfi-fastcharge: Configure runtime PM autosuspend Reply-To: sashiko-reviews@lists.linux.dev To: "Rosen Penev" Cc: linux-usb@vger.kernel.org In-Reply-To: <92dbc6290a8c587e9078da7da146f66044d7d14d.1796524906.git.rosenp@gmail.com> References: <92dbc6290a8c587e9078da7da146f66044d7d14d.1796524906.git.rosenp@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 03:05:08 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] usb: apple-mfi-fastcharge: NULL deref in mfi_fc_resume() before drvdata is set - [High] usb: apple-mfi-fastcharge: usb_enable_autosuspend() breaks fast charging - [Medium] usb: apple-mfi-fastcharge: missing usb_disable_autosuspend() on unbind - [Medium] usb: apple-mfi-fastcharge: unpaired usb_enable_autosuspend() races resume -- commit 52cde79222ebee5d1af8ec77b3372e905516d988 Author: Rosen Penev usb: apple-mfi-fastcharge: Configure runtime PM autosuspend This commit sets supports_autosuspend on mfi_fc_driver and calls usb_enable_autosuspend() at the end of mfi_fc_probe() so the USB device can runtime-autosuspend when idle. > diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/a= pple-mfi-fastcharge.c > index fb4b975a62e94..83009b601da14 100644 > --- a/drivers/usb/misc/apple-mfi-fastcharge.c > +++ b/drivers/usb/misc/apple-mfi-fastcharge.c > @@ -212,6 +212,7 @@ static int mfi_fc_probe(struct usb_device *udev) > return PTR_ERR(battery); > =20 > dev_set_drvdata(&udev->dev, mfi); > + usb_enable_autosuspend(udev); > =20 > return 0; > } [Severity: High] Does calling usb_enable_autosuspend() here break fast charging after the default 2-second autosuspend delay? After setting charge_type to Fast, apple_mfi_fc_set_property() immediately calls pm_runtime_put_autosuspend(). With no runtime PM reference held and no suspend callback to veto PMSG_AUTO_SUSPEND, an idle device enters USB Suspend and loses its fast-charge state while charge_type stays Fast. Unconditionally enabling autosuspend also overrides USB core's default policy across all 0x05ac:0x1200..0x12ff devices (unlike other generic_subclass drivers that only set supports_autosuspend) and adds a 40 ms usb_port_resume() stall on intermittent wakeups. Dropping usb_enable_autosuspend() and preventing autosuspend while POWER_SUPPLY_CHARGE_TYPE_FAST is active would avoid this regression. [Severity: Medium] Does mfi_fc_probe() leave autosuspend permanently enabled on udev after the driver unbinds? mfi_fc_driver defines no disconnect callback or devm action to call usb_disable_autosuspend(udev). Since pm_runtime_reinit() in device_unbind_cleanup() returns early while pm_runtime_enabled() is true, runtime_auto stays enabled after module unload or sysfs unbind. > @@ -241,6 +242,7 @@ static struct usb_device_driver mfi_fc_driver =3D { > .id_table =3D mfi_fc_id_table, > .match =3D mfi_fc_match, > .generic_subclass =3D 1, > + .supports_autosuspend =3D 1, > }; [Severity: High] Can setting supports_autosuspend trigger a NULL pointer dereference in mfi_fc_resume() before mfi_fc_probe() sets drvdata? When binding to a runtime-suspended device (such as on rebind after unbind leaves autosuspend enabled), really_probe() sets dev->driver before calling usb_probe_device(). With supports_autosuspend and generic_subclass set, usb_probe_device() no longer resumes udev before usb_generic_driver_probe(). Instead, usb_generic_driver_probe() -> usb_set_configuration() -> usb_autoresume_device() -> usb_resume_device() invokes mfi_fc_resume() before mfi_fc_probe() runs. dev_get_drvdata(&udev->dev) is still NULL, so guard(mutex)(&mfi->lock) dereferences NULL. A concurrent charge_type write during probe can hit the same crash because mfi_fc_probe() registers the power supply before calling dev_set_drvdata(). Checking for NULL in mfi_fc_resume() and setting drvdata before devm_power_supply_register() would prevent both crashes. [Severity: Medium] Can an asynchronous runtime resume race with driver unbind and cause a use-after-free of mfi in mfi_fc_resume()? During unbind or rmmod while the device remains attached, usb_generic_driver_disconnect() calls usb_autosuspend_device(). Without a disconnect callback disabling autosuspend, udev can autosuspend before device_unbind_cleanup() frees mfi and clears dev->driver: CPU0 (unbind) CPU1 (pm_wq) __device_release_driver() usb_unbind_device() usb_set_configuration(..., -1) usb_autosuspend_device() ... -> usb_port_suspend() device_unbind_cleanup() devres_release_all() mutex_destroy(&mfi->lock) kfree(mfi) usb_port_runtime_resume() pm_request_resume(&udev->dev) usb_runtime_resume() ... -> mfi_fc_resume() guard(mutex)(&mfi->lock) <-- use-after-free device_set_driver(dev, NULL) dev_set_drvdata(dev, NULL) Because usb_runtime_resume() does not acquire device_lock(&udev->dev), mfi_fc_resume() can touch freed mfi or sleep in usb_control_msg() across devres_release_all() and module unload. Calling usb_disable_autosuspend(udev) in a disconnect callback or devm action before mfi is freed would synchronize runtime PM during unbind. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796524906.gi= t.rosenp@gmail.com?part=3D9