From patchwork Mon Jun 9 20:38:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 895121 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 8622322129F; Mon, 9 Jun 2025 20:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749501543; cv=none; b=SPtmGH521uczbAxpJl3AZ3wck1oTSpfZNJK0/yNCC8FoLQ76TsN9KcmIMgpc50yd29/aToBY3p6vovmAbFKfM4OxTE95IgSZUBvif3EYYvh/r40xbtuWdE6Gcb7in6hUmT9C3e9GIg+sWvLFWaT0o5JKIyIEQKgLjpiN6hnki8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749501543; c=relaxed/simple; bh=/FW1uODFNygTPBiads/Cgva/fZBdnCPVHS77URlMjjc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V5QlHZvYTJmfJjkuKMvmu1d7CmGB+hcKnHaRnCxyWz7nyz5EB6ogeSFt0LYJ7AntktET3j9YKwV5etXRZLM7Eep2GMmTfxY9ktfE4H5cp3++Ft9Q7/glK8SUgVFSYc6qtKZ4+PCS6eXRmzAy9GYLgXNZHQxwnUn5Cc0QMIyxIgM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=RQ/h7KoF; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="RQ/h7KoF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1749501539; bh=/FW1uODFNygTPBiads/Cgva/fZBdnCPVHS77URlMjjc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RQ/h7KoFVxyEaL3gOrcwRIrSgiUi8tpf+8bZ1J3cmHacz1rZSlBzejqnzNA6GJH05 bfa6DvVbFooTRNtO1DccruKYL07wctByi6ad/WxxZxTwEs1/r55W8AD32nJcQP9ng9 k++3zu4wwvtQi17CUEWu2WFdHxXlKbqOsQHqAtV0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 09 Jun 2025 22:38:39 +0200 Subject: [PATCH v6 3/3] locking/mutex: Mark devm_mutex_init() as __must_check Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250609-must_check-devm_mutex_init-v6-3-9540d5df9704@weissschuh.net> References: <20250609-must_check-devm_mutex_init-v6-0-9540d5df9704@weissschuh.net> In-Reply-To: <20250609-must_check-devm_mutex_init-v6-0-9540d5df9704@weissschuh.net> To: Peter Zijlstra , Ingo Molnar , Waiman Long , Boqun Feng , Vicentiu Galanopulo , Will Deacon , Han Xu , Haibo Chen , Yogesh Gaur , Mark Brown , Lee Jones , Pavel Machek , Andrew Davis Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, Bartosz Golaszewski , Bartosz Golaszewski , linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-leds@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1749501538; l=2169; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=/FW1uODFNygTPBiads/Cgva/fZBdnCPVHS77URlMjjc=; b=XMIA2t76cWY8q3SbUJtzN8v1jQ4AwXiPpkwDqG5ui1Cd4AyjqNi3x12hCFUhxnv95kyToir+s tiAJIto8fDLApMRKWxsys9+vfQBWRGMaKFmhqy59sHuLny/dl0fQBvt X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Even if it's not critical, the avoidance of checking the error code from devm_mutex_init() call today diminishes the point of using the devm variant of it. Tomorrow it may even leak something. Enforce all callers checking the return value through the compiler. As devm_mutex_init() itself is a macro, it can not be annotated directly. Annotate __devm_mutex_init() instead. Unfortunately __must_check/warn_unused_result don't propagate through statement expression. So move the statement expression into the argument list of the call to __devm_mutex_init() through a helper macro. Signed-off-by: Thomas Weißschuh Reviewed-by: Andy Shevchenko Reviewed-by: Bartosz Golaszewski --- include/linux/mutex.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/mutex.h b/include/linux/mutex.h index a039fa8c17807c700d3b61193feac0418cad1243..00afd341d293ddfcc0a427b576efdce044955e38 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -126,11 +126,11 @@ do { \ #ifdef CONFIG_DEBUG_MUTEXES -int __devm_mutex_init(struct device *dev, struct mutex *lock); +int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock); #else -static inline int __devm_mutex_init(struct device *dev, struct mutex *lock) +static inline int __must_check __devm_mutex_init(struct device *dev, struct mutex *lock) { /* * When CONFIG_DEBUG_MUTEXES is off mutex_destroy() is just a nop so @@ -141,14 +141,17 @@ static inline int __devm_mutex_init(struct device *dev, struct mutex *lock) #endif -#define devm_mutex_init(dev, mutex) \ +#define __mutex_init_ret(mutex) \ ({ \ typeof(mutex) mutex_ = (mutex); \ \ mutex_init(mutex_); \ - __devm_mutex_init(dev, mutex_); \ + mutex_; \ }) +#define devm_mutex_init(dev, mutex) \ + __devm_mutex_init(dev, __mutex_init_ret(mutex)) + /* * See kernel/locking/mutex.c for detailed documentation of these APIs. * Also see Documentation/locking/mutex-design.rst.