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=1796383204; b=hnt6BlKnFMUF2nXIOFOf89i2X285pWYhddDo6f9J6nY3+JfCGmsvxyh0jpEyRRjXnZPI rQw2/F4tw5nWZaHRwuF2GKUgqVO2JVEVyJTJOa6hN0Nj4nY5+AXDdOcsA+/0Dly24w2D6 11KQInwbj8CGaSSmPW8foJOwOyD6rqX4rJYqpM9fwrqWJTkHTdYzS1XIn30r/FA45bzN6 zrVlCymU00wiUzqg9dyFmfzdA9ja1lvFKsu889aOinrh7FPSV51TTRtDlhQlx5FVZAmlp PdcTFY/0wlUc4TZtESSuBPS+W5R+JImmuD/+d4etE0ipNaEtxo2ewh6KrfpzsJUBFSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383204; 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=Fz/DHUWCui/+SNpNPgyAwcAfcWCz+Jcq1EV5/i4TKk4=; b=3dkWrO6+/aEZlcmLQGuajDsA0IKI/Xf5bGyblPBrJoPP8JCwEcqrN2J4V8EIeomZzRcf lkFFVg71II+FGUfUaSGD2GjuxCqGsmHAFpwD/LJFyF285mGfKcD2SVbcBu8YlTreXjhrk 37FjpJjWr4lYIIsBo4+iCaDqYy7s3oBgsBuL1bCt/cQMQs6uFa33oh7W8JUiePxSrHsHZ 1mPmP57I3SLWCmXh22BxIkOjaozQVeO8z/Qd5POpaXPXMQ2z5NvJXStMNBL9Yy+0dGkrk xJ+REQ30ryrAWrwslpWali+lWt9zD/mrmLH+zZC/NpUtfJsrbGUpGWgWcn9zF1rIfBQ== 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=DtGp0YGw; 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 58FDC606A322; Fri, 4 Dec 2026 11:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=DtGp0YGw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91EE81F000C2; Fri, 4 Dec 2026 11:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383204; bh=Fz/DHUWCui/+SNpNPgyAwcAfcWCz+Jcq1EV5/i4TKk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DtGp0YGwq8P/MCiHRZ7uwtaSkR3ZR802AlzX4RSDIwSCNvosLcOJoXK+znTGrAM9K ZYULezwZuYedvKuOLRVaUeBP2C1fFN5fj0ZcELT71APxL6eglmoBVDQAGAGNl/Orcx W1aYDQc1ubZGCIpY7yi9b5m1SWQXQX0hNw4+nyEI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Danilo Krummrich , Sasha Levin Subject: [PATCH 6.12 125/555] devres: add devm_remove_action_nowarn() Date: Fri, 4 Dec 2026 19:02:48 +0900 Message-ID: <20261204100612.587840560@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Danilo Krummrich [ Upstream commit f1725160fd28a2e65e47166637aa44856a1a7f89 ] devm_remove_action() warns if the action to remove does not exist (anymore). The Rust devres abstraction, however, has a use-case to call devm_remove_action() at a point where it can't be guaranteed that the corresponding action hasn't been released yet. In particular, an instance of `Devres` may be dropped after the action has been released. So far, `Devres` worked around this by keeping the inner type alive. Hence, add devm_remove_action_nowarn(), which returns an error code if the action has been removed already. A subsequent patch uses devm_remove_action_nowarn() to remove the action when `Devres` is dropped. Signed-off-by: Danilo Krummrich Link: https://lore.kernel.org/r/20250107122609.8135-1-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman Stable-dep-of: 6c6508e742b4 ("usb: dwc3: xilinx: unwind ZynqMP platform init on probe failure and remove") Signed-off-by: Sasha Levin --- drivers/base/devres.c | 23 ++++++++++++++++++----- include/linux/device.h | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index f229c5b3e7850..03da20f0431dc 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -757,25 +757,38 @@ int __devm_add_action(struct device *dev, void (*action)(void *), void *data, co EXPORT_SYMBOL_GPL(__devm_add_action); /** - * devm_remove_action() - removes previously added custom action + * devm_remove_action_nowarn() - removes previously added custom action * @dev: Device that owns the action * @action: Function implementing the action * @data: Pointer to data passed to @action implementation * * Removes instance of @action previously added by devm_add_action(). * Both action and data should match one of the existing entries. + * + * In contrast to devm_remove_action(), this function does not WARN() if no + * entry could have been found. + * + * This should only be used if the action is contained in an object with + * independent lifetime management, e.g. the Devres rust abstraction. + * + * Causing the warning from regular driver code most likely indicates an abuse + * of the devres API. + * + * Returns: 0 on success, -ENOENT if no entry could have been found. */ -void devm_remove_action(struct device *dev, void (*action)(void *), void *data) +int devm_remove_action_nowarn(struct device *dev, + void (*action)(void *), + void *data) { struct action_devres devres = { .data = data, .action = action, }; - WARN_ON(devres_destroy(dev, devm_action_release, devm_action_match, - &devres)); + return devres_destroy(dev, devm_action_release, devm_action_match, + &devres); } -EXPORT_SYMBOL_GPL(devm_remove_action); +EXPORT_SYMBOL_GPL(devm_remove_action_nowarn); /** * devm_release_action() - release previously added custom action diff --git a/include/linux/device.h b/include/linux/device.h index 95bfb360915b9..601e60c68504c 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -287,7 +287,23 @@ void device_remove_bin_file(struct device *dev, const struct bin_attribute *attr); /* allows to add/remove a custom action to devres stack */ -void devm_remove_action(struct device *dev, void (*action)(void *), void *data); +int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data); + +/** + * devm_remove_action() - removes previously added custom action + * @dev: Device that owns the action + * @action: Function implementing the action + * @data: Pointer to data passed to @action implementation + * + * Removes instance of @action previously added by devm_add_action(). + * Both action and data should match one of the existing entries. + */ +static inline +void devm_remove_action(struct device *dev, void (*action)(void *), void *data) +{ + WARN_ON(devm_remove_action_nowarn(dev, action, data)); +} + void devm_release_action(struct device *dev, void (*action)(void *), void *data); int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name); -- 2.53.0