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 ED52652ED31 for ; Wed, 9 Sep 2026 11:04:03 +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=1788951850; cv=none; b=tEPdFCbxirEZLHK5Vd1rc5+t8fZrOujBwNZjt/m67sz7GwRAgfY8LBvahA6JzWlUu5QGDeS41W5FwBVc5WZsk6PwdjAIhbhi+fTH9De1kJ9BI2nxwxIpzPoFZ62060KJIQ1JHcQbmMFzUlFFd0M0awyw+oCsgqdMfeHY25hHmxk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788951850; c=relaxed/simple; bh=hpawfH/qg86UykaXVpKD6lKZ6CrNPHBWB6i2lHxJIqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pjqi01/IQKrwMMww5XYKWOEWQmVSdFToz0IccYnEPMyuR3SPijch5DSPbJRwDHAoRi3uB1se97JQKmrpX+qxvqGYeQnah9ttqx+VP7tIiHOinrvkP4m4S2OSiE26YH0YIUQHPqZrmeiW2koXzbROENRNlQIfYR2o08SetqIxWTM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oNEgVEFD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oNEgVEFD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0F721F00ADE; Wed, 9 Sep 2026 11:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788951840; bh=qWnHJLSeYFnDxNNsd2jl6BW1IVADs/nIcbPPv1hSULg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oNEgVEFDj0+Vuajzn/Ql40N/cu/Om+5JQKPXYcBoJ+ni6z9OdUP2dCQ7hup387VBu xfsLNHGRrfQKOWgyf/ZmdGp8Tz73Zd6tuuP5S9YW1V5Elcb3I2/UKU5uub+6kxNINf cYVPgaw5hzrtfLftGzX+edDip2cZU4/dz/R8afUPJkqEL7WJcqdR/nHNhfEG9vwxPV TfTEd4Rqrw2lM6V9syNX1fKUIY0yTmBNFE0zvoBOyzWL0m8vQtxAINR8Eifh03leSf xyGss1BP/JwatJXFazC0dXC0x7QM74nX15vsc4Ak6kjenU55u2hj8qf1AXbpho21Xd fp++8OZUb5nJA== From: Sasha Levin To: stable@vger.kernel.org Cc: Fan Wu , Sebastian Reichel , Sasha Levin Subject: [PATCH 6.1.y 2/2] power: supply: rt9455: quiesce delayed work before teardown Date: Wed, 9 Sep 2026 07:03:57 -0400 Message-ID: <20260909110357.1706595-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260909110357.1706595-1-sashal@kernel.org> References: <2026090322-duller-precut-e80c@gregkh> <20260909110357.1706595-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Fan Wu [ Upstream commit 3e7a1ebc32fad5a558254a478efd401c17a24381 ] The threaded IRQ handler can queue pwr_rdy_work, max_charging_time_work and batt_presence_work. pwr_rdy_work and batt_presence_work can also queue max_charging_time_work, while batt_presence_work can requeue itself. rt9455_remove() cancels max_charging_time_work before batt_presence_work. The latter can therefore queue max_charging_time_work after it has already been cancelled: rt9455_remove() workqueue cancel pwr_rdy_work cancel max_charging_time_work batt_presence_work queues max_charging_time_work cancel batt_presence_work return devres frees rt9455_info max_charging_time_work dereferences rt9455_info The IRQ also remains registered until devres cleanup and can queue more work after any of the cancellation calls. If rt9455_hw_init() fails after the IRQ has been requested, probe returns without cancelling work that may already have been queued. A pending callback can then access rt9455_info after it has been freed. Register rt9455_cancel_all_delayed_works() through devm_add_action_or_reset() right after devm_power_supply_register(). devres invokes the action in reverse registration order, after the managed IRQ has been freed and before rt9455_info is released, so the delayed works are drained in both rt9455_remove() and the probe error path. Cancel pwr_rdy_work and batt_presence_work before max_charging_time_work because both can queue the latter. This issue was found by an in-house static analysis tool. Fixes: e86d69dd786e ("power_supply: Add support for Richtek RT9455 battery charger") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.6 Signed-off-by: Fan Wu Link: https://patch.msgid.link/20260723225310.12663-1-fanwu01@zju.edu.cn Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/rt9455_charger.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/rt9455_charger.c b/drivers/power/supply/rt9455_charger.c index dd4ff038814f4..62ffc3acc2aec 100644 --- a/drivers/power/supply/rt9455_charger.c +++ b/drivers/power/supply/rt9455_charger.c @@ -1583,6 +1583,19 @@ static const struct regmap_config rt9455_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +static void rt9455_cancel_all_delayed_works(void *data) +{ + struct rt9455_info *info = data; + + /* + * Both pwr_rdy_work and batt_presence_work can queue + * max_charging_time_work, so cancel them first. + */ + cancel_delayed_work_sync(&info->pwr_rdy_work); + cancel_delayed_work_sync(&info->batt_presence_work); + cancel_delayed_work_sync(&info->max_charging_time_work); +} + static int rt9455_probe(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; @@ -1673,6 +1686,10 @@ static int rt9455_probe(struct i2c_client *client) goto put_usb_notifier; } + ret = devm_add_action_or_reset(dev, rt9455_cancel_all_delayed_works, info); + if (ret) + goto put_usb_notifier; + ret = devm_request_threaded_irq(dev, client->irq, NULL, rt9455_irq_handler_thread, IRQF_TRIGGER_LOW | IRQF_ONESHOT, @@ -1713,10 +1730,6 @@ static void rt9455_remove(struct i2c_client *client) if (info->nb.notifier_call) usb_unregister_notifier(info->usb_phy, &info->nb); #endif - - cancel_delayed_work_sync(&info->pwr_rdy_work); - cancel_delayed_work_sync(&info->max_charging_time_work); - cancel_delayed_work_sync(&info->batt_presence_work); } static const struct i2c_device_id rt9455_i2c_id_table[] = { -- 2.53.0