From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9C1D7080D; Fri, 4 Sep 2026 05:55:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788501348; cv=none; b=cdK8kdpU9mckhKKAggxcGxwSvrCwQ1MVtepnYCKPSKmnfblbnAzUsbylkHEiWwV/ispnw8pxZheAD2A/NV1wUetTtwtAOzr3d/IYM+TmvMKK1U9EevvrxAKYEId5c/pi73+jqx5gxtjFvp+Z2rX2De5Ft6rc7bWFs1G+TjrOLVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788501348; c=relaxed/simple; bh=jSaWL+j+cy7yofCKjsRIo7ntskQyMA4Tevf0j7gNNws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=daYOkCnDJwf9hFq6vWEiuh1X+NAA3dQWuzLgFG7Vx9ZqIOVP4lZoiEVRg0cbk7euFmu4yktvBC3KonsI5WGK6Qm7RD5dEtyvOzwlMNuqfF8K7x10kCLch+ROxYzchGucLQNqAZlNqCaeTxzP5AO0dwsyVBWZDCEIZ+vqegVotWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QI0UBVT3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QI0UBVT3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EBE41F00A3D; Fri, 4 Sep 2026 05:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788501347; bh=n4ItgynLdUV5mBt/+YcL5jYoDSU9OoJQLUOz3PiK2h8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QI0UBVT3KsVBaMD9eBbshi435uo16eMafrUWG/Zn0lu+3sQUJqwKKOAPOXjGO9L2+ yVy/HaU08lVUj9++bWFJT2FLQ1pk3b3BG8pJXgFypyfZm4PxJDY49YeZv4WcAJlbAl I34hkyQ0GJWMqLEPQQyjI31iYj/bNBMgrkv8hDDY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sebastian Reichel , Maoyi Xie , Sebastian Reichel Subject: [PATCH 6.18 377/552] power: supply: twl4030_charger: cancel workers via devm Date: Fri, 4 Sep 2026 06:58:54 +0200 Message-ID: <20260904045758.767263775@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maoyi Xie commit 6eba34732524067da2aad5ddfdfbc641ded10e9e upstream. bci is devm-allocated. Two workers (bci->work and bci->current_worker) dereference it. twl4030_bci_remove() disables charging and masks interrupts. It cancels neither worker. A worker pending at remove() can run after devm frees bci. The USB transceiver comes from devm_usb_get_phy_by_node(). devm unregisters its notifier only after remove() returns. A cancel_work_sync() in remove() can then race a notifier reschedule. devm_work_autocancel() and devm_delayed_work_autocancel() avoid that. They cancel the workers during devm release, before bci is freed. The current_worker is registered first, since devm will cancel in reverse order and bci->work can reschedule current_worker. Suggested-by: Sebastian Reichel Fixes: d6ccc442b1210 ("twl4030_charger: Make the driver atomic notifier safe") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20260702172128.2001753-1-maoyixie.tju@gmail.com Signed-off-by: Maoyi Xie Link: https://patch.msgid.link/20260725072540.3092504-1-maoyixie.tju@gmail.com [Move comment about order into the commit message] Signed-off-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/power/supply/twl4030_charger.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/power/supply/twl4030_charger.c +++ b/drivers/power/supply/twl4030_charger.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1002,8 +1003,15 @@ static int twl4030_bci_probe(struct plat platform_set_drvdata(pdev, bci); - INIT_WORK(&bci->work, twl4030_bci_usb_work); - INIT_DELAYED_WORK(&bci->current_worker, twl4030_current_worker); + ret = devm_delayed_work_autocancel(&pdev->dev, &bci->current_worker, + twl4030_current_worker); + if (ret) + return ret; + + ret = devm_work_autocancel(&pdev->dev, &bci->work, + twl4030_bci_usb_work); + if (ret) + return ret; bci->channel_vac = devm_iio_channel_get(&pdev->dev, "vac"); if (IS_ERR(bci->channel_vac)) {