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=1793216626; b=MMZC+jJCsgOutTc3rK/ByES0tZR6j8p7J2xbUg0JXU0vzQNmj7uXeGfisE4Ltk/GuGui DNn4+bCgp3ioAZgX3Nnl/KXhehqOiVPt2jPRHmc/vbw4wCWeh95RzFwBx8jVy72KPogIh 6rKze3pJD78CjUAhhhEaACvQKRKP231CoBHcHCXOiIzZKxiYLVpYd2Mqgx7GxdYAcPH13 40/pVkPkFhloBoLBz6r0CpyQO/wKdBeasmkNRJ1vlnbbmif/IYbSBH6vM71C3kHW+//JF JqUQ1y7g0inOyR9CL7WBnGaG3eFJp5PInaSk+1cWQa7vevtc4jNxfIlwIxmM1y9uN3g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793216626; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=kW2/hHFg44wD1nI5Zb6xWJJt8kQCvIUGausAFf0Bjtw=; b=eJIauY3U7msqt3ZoMS4vEzApbfCgaghL1RTt3eA7+342WMv+/oPJ7mNtVt3hmGMaX04W VYgatSRfxGdlTvSp0b2A4sYfJXQnEg9zqtygSlViMnqGEcly9JcV1U6nM84TO09Nouz/H dXI88N91mr90xZFjXFyhjHudZL5GA10F/eaRw4TFU905ILQIcrktpl5gOWZ9biuGl738/ in4pJiiXjODTZDkn6EFTfAa7y7ZOfJZ4LcSAadmeyJd3awe74UoAnlk5wYTQig3xGZiRB 5zAArJrIhPogd8WKJwn8o0Dbb14boG4uuQTliPa5MaUbuSvUIeFnIonc1x6bxVlTxvA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TKmpziN9; 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 30F6D606A31C; Wed, 28 Oct 2026 19:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=TKmpziN9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 467031F01825; Wed, 28 Oct 2026 19:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793216625; bh=kW2/hHFg44wD1nI5Zb6xWJJt8kQCvIUGausAFf0Bjtw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TKmpziN97qymLoLLCTzM5VHohYpgImdK4Vm+nklCuQjxeFztSInlVK3eN1Qgr3xoR LnACm+XcKhpZ04B3eU+JhzddNQzWks32rokZky0o/PsVXMJuQ3G4LWSCkpmWw3X0nv sGknJBXbxkjl2kOCNIbXDqBtOqgllQ2swJFCGUj8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Sudeep Holla , Sasha Levin Subject: [PATCH 6.1 1622/1887] firmware: arm_scmi: Fix SCMI device destroy lifetimes Date: Wed, 28 Oct 2026 18:01:58 +0100 Message-ID: <20261028170536.379691857@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sudeep Holla [ Upstream commit 6abe8fe36b29ff51d1a42c2f338972883f4751a5 ] scmi_child_dev_find() drops the reference returned by device_find_child() before returning the scmi_device pointer. A concurrent unregister can then release the device while the destroy path is still using the returned pointer. Make the lookup helper return the device_find_child() reference and keep it until scmi_device_destroy() has finished unregistering the child. Also split device_unregister() in __scmi_device_destroy() so the SCMI bus ID is not made reusable until after device_del() has removed the old scmi_dev.N name from sysfs. This avoids a new SCMI device reusing the same ID while the old device is still registered. The final device release callback is also a possible cleanup path when SCMI children are deleted by driver core recursion rather than __scmi_device_destroy(). Release the SCMI bus ID from a common helper used by destroy, register-failure and final-release paths, and clear scmi_dev->id after freeing it so the final release cannot free the same ID again. Fixes: 9ca67840c0dd ("firmware: arm_scmi: Balance device refcount when destroying devices") Reported-by: Sashiko Link: https://patch.msgid.link/20260714-scmi_core_fixes-v6-15-3afe499d46e3@kernel.org Signed-off-by: Sudeep Holla Signed-off-by: Sasha Levin --- drivers/firmware/arm_scmi/bus.c | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index 323e1e48cabde..3fcc46423d42c 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -220,8 +220,9 @@ static int scmi_match_by_id_table(struct device *dev, void *data) (id_table->name && !strcmp(sdev->name, id_table->name)); } -static struct scmi_device *scmi_child_dev_find(struct device *parent, - int prot_id, const char *name) +/* Returns a device_find_child() reference which must be dropped by caller. */ +static struct scmi_device * +scmi_child_dev_find_get(struct device *parent, int prot_id, const char *name) { struct scmi_device_id id_table; struct device *dev; @@ -233,9 +234,6 @@ static struct scmi_device *scmi_child_dev_find(struct device *parent, if (!dev) return NULL; - /* Drop the refcnt bumped implicitly by device_find_child */ - put_device(dev); - return to_scmi_dev(dev); } @@ -299,10 +297,19 @@ void scmi_driver_unregister(struct scmi_driver *driver) } EXPORT_SYMBOL_GPL(scmi_driver_unregister); +static void scmi_device_release_resources(struct scmi_device *scmi_dev) +{ + if (scmi_dev->id) { + ida_free(&scmi_bus_id, scmi_dev->id); + scmi_dev->id = 0; + } +} + static void scmi_device_release(struct device *dev) { struct scmi_device *scmi_dev = to_scmi_dev(dev); + scmi_device_release_resources(scmi_dev); kfree_const(scmi_dev->name); kfree(scmi_dev); } @@ -317,8 +324,9 @@ static void __scmi_device_destroy(struct scmi_device *scmi_dev) if (scmi_dev->protocol_id == SCMI_PROTOCOL_SYSTEM) atomic_set(&scmi_syspower_registered, 0); - ida_free(&scmi_bus_id, scmi_dev->id); - device_unregister(&scmi_dev->dev); + device_del(&scmi_dev->dev); + scmi_device_release_resources(scmi_dev); + put_device(&scmi_dev->dev); } static struct scmi_device * @@ -335,9 +343,11 @@ __scmi_device_create(struct device_node *np, struct device *parent, * each DT defined protocol at probe time, and the concurrent * registration of SCMI drivers. */ - scmi_dev = scmi_child_dev_find(parent, protocol, name); - if (scmi_dev) + scmi_dev = scmi_child_dev_find_get(parent, protocol, name); + if (scmi_dev) { + put_device(&scmi_dev->dev); return scmi_dev; + } /* * Ignore any possible subsequent failures while creating the device @@ -388,8 +398,8 @@ __scmi_device_create(struct device_node *np, struct device *parent, return scmi_dev; put_dev: + scmi_device_release_resources(scmi_dev); put_device(&scmi_dev->dev); - ida_free(&scmi_bus_id, id); return NULL; } @@ -461,9 +471,11 @@ void scmi_device_destroy(struct device *parent, int protocol, const char *name) { struct scmi_device *scmi_dev; - scmi_dev = scmi_child_dev_find(parent, protocol, name); - if (scmi_dev) + scmi_dev = scmi_child_dev_find_get(parent, protocol, name); + if (scmi_dev) { __scmi_device_destroy(scmi_dev); + put_device(&scmi_dev->dev); + } } EXPORT_SYMBOL_GPL(scmi_device_destroy); -- 2.53.0