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=1796526333; b=P7I1X2YSCzT8mpBFb+yHcOyKFpea1ds0wmnubeAS5720735HLCQ1ctRN6nMZvU1lTRVE HEFumFmgYBywfEu7zIBvzxjvn7ukOPIAI9AzFUaQXEAIzurQjFaToUtS2PtFSHT9esQL5 +Cf+m6IWaN+u99Gvj1sCqa1ptnRm8e5PieppZmWzI9x3W+Bo/drJiiEQ39JFLl7FTEAYa ckUfsqh3o1i2CIsQ9dyAE9sa9G8uzmC1nRc4Np+UhHAmRcu+QocDmLLb3ZvIZTsOSuRBK pMz7SXKn7AmosgGSxqBHKlqfWA+1tjsIxWk4S87dRUZ07eSFnGkuUgW7OvulL9dMF7A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796526333; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=4raFEJktkDCjyHcRHCz0eyqAoonfbnNk2Qk31piRYKg=; b=UIre4vuMsVdhqa9Jj9nkPoX6N5VWPwWzSin9gGdsfIChAfxKFj56EGzesSlCzR8swv6L J7/bqW4kr1Sld9y+JkYnDI22qgach4owoPh4eLZTOVFTT2M31xEUoACZW37cz279tjAyb hLygXKShGhnG1ln+JWiBBw+tG0HZ4PtQ7Mvpgbt/NEqhurUBifMT0/W3qQrIuzY//7GyI 7MFrkEud6TV9pnwuZdlJUDWV4MTnoZYbuW76H6vw8RjmnYpBR1QBZe5OfLcFsQHnRmwAL UPzgl6nkNd/bB1svMfWG4x7OVvAOY1CvLFhMgzfRv6ZatVKoXPG5EedRMbCbMCF5xtg== 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=c7yz8l7a; 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 E6F1A606A31F for ; Sun, 6 Dec 2026 03:05:32 +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=c7yz8l7a Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9058F1F0092B; Sun, 6 Dec 2026 03:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796526332; bh=4raFEJktkDCjyHcRHCz0eyqAoonfbnNk2Qk31piRYKg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=c7yz8l7acwlXCo8Cdcf9JOF9RM328ghbdfa4fxRnPZ3HRmswSJWUQSWvqTcZfkaWs wZlpJtyjscXN2GEPcydyN8AZGZTb4gsZCzEUb0dYMAA4SYbrwakJtkScVZB+smD8Ti aXdLrvay6KXvKnUFAuM0ucWvI4T5M+SGhoo5ZqE4RAe02yObeAVu6L6nXopYVgCMB4 JkIoSuaVwTF6tUhKPj4mzu39+66/MnonVWOXhVHuWVX9u4/XS3/pOeYeHwQxaLxqv9 2VFsDr/EfJ2o2iRGmysCTxT1a43EKzI4WyrNN+rmaJCgm6QvrKE3qnKEXQrcpoORNS FSQ7++ZD1uRCA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 07/12] usb: apple-mfi-fastcharge: Restore charge current on resume Reply-To: sashiko-reviews@lists.linux.dev To: "Rosen Penev" Cc: linux-usb@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 03:05:32 +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 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 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/a= pple-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); > =20 > + 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 =3D 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 =3D=3D POWER_SUPPLY_CHARGE_TYPE_FAST && > + apple_mfi_fc_send_current(mfi, FAST_CURRENT_MA) < 0) > + mfi->charge_type =3D 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 =3D udev->dev.driver usb_generic_driver_resume() device_unbind_cleanup() devres_release_all(dev) mfi_fc_resume() mfi =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796524906.gi= t.rosenp@gmail.com?part=3D7