From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-25.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D475AC433F5 for ; Wed, 22 Sep 2021 14:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9EDC611C9 for ; Wed, 22 Sep 2021 14:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236375AbhIVPBC (ORCPT ); Wed, 22 Sep 2021 11:01:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:39792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236303AbhIVPBA (ORCPT ); Wed, 22 Sep 2021 11:01:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E357361153; Wed, 22 Sep 2021 14:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632322770; bh=EQ2C98TlWZE0g0z7OwmAB1xVVZKpvfN8eAHsxQ9nREM=; h=From:To:Cc:Subject:Date:From; b=shnmOzmwe+3AOy8qFTNgKnx7ggtL0b6NXMWIp29AuJDQhUZHXkCdV6I2uTYdniQSu 6hdeFIQUmEf7hnKAYzY1yLAkQYcPP1eG7zA1sP+U8lnNya0J7TP6qCRCzvmi7aVHkZ 4TED4NMmUrQs1ZKybwalh1M7Hjo3tmjSCQerRXl86ozoZ/1QGx4s4C09jfVP7EKs+j kXJw9SaR85Mfw3s/j3KtPQU9XDhFvmRyjnkkBfpP0H0BbeqG108AjA0g31aoR4gDdm pY6uqGsoynszFhFIQ1SMTDd45pXAqPR9F81ip5J71012wtUgYFrnsB7iEowFqSBjv2 YEAIXj84M0iyw== From: Nathan Chancellor To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Waiman Long , Boqun Feng , Nick Desaulniers , Maarten Lankhorst , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Nathan Chancellor , "kernelci.org bot" , Stephen Rothwell Subject: [PATCH] locking/ww-mutex: Fix uninitialized use of ret in test_aa() Date: Wed, 22 Sep 2021 07:58:22 -0700 Message-Id: <20210922145822.3935141-1-nathan@kernel.org> X-Mailer: git-send-email 2.33.0.514.g99c99ed825 MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clang warns: kernel/locking/test-ww_mutex.c:138:7: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!ww_mutex_trylock(&mutex, &ctx)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/locking/test-ww_mutex.c:172:9: note: uninitialized use occurs here return ret; ^~~ kernel/locking/test-ww_mutex.c:138:3: note: remove the 'if' if its condition is always false if (!ww_mutex_trylock(&mutex, &ctx)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/locking/test-ww_mutex.c:125:9: note: initialize the variable 'ret' to silence this warning int ret; ^ = 0 1 error generated. Assign !ww_mutex_trylock(...) to ret so that it is always initialized. Fixes: 12235da8c80a ("kernel/locking: Add context to ww_mutex_trylock()") Link: https://github.com/ClangBuiltLinux/linux/issues/1463 Reported-by: "kernelci.org bot" Reported-by: Stephen Rothwell Signed-off-by: Nathan Chancellor --- kernel/locking/test-ww_mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index d63ac411f367..353004155d65 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -135,7 +135,8 @@ static int test_aa(bool trylock) goto out; } } else { - if (!ww_mutex_trylock(&mutex, &ctx)) { + ret = !ww_mutex_trylock(&mutex, &ctx); + if (ret) { pr_err("%s: initial trylock failed!\n", __func__); goto out; } base-commit: 12235da8c80a1f9909008e4ca6036d5772b81192 -- 2.33.0.514.g99c99ed825