From patchwork Fri Nov 20 14:24:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 105223 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp512921lbb; Fri, 20 Nov 2015 06:26:03 -0800 (PST) X-Received: by 10.68.170.98 with SMTP id al2mr19680546pbc.121.1448029562999; Fri, 20 Nov 2015 06:26:02 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc7si19933658pbd.145.2015.11.20.06.26.01; Fri, 20 Nov 2015 06:26:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760218AbbKTO0A (ORCPT + 28 others); Fri, 20 Nov 2015 09:26:00 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:56473 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752989AbbKTOZ6 (ORCPT ); Fri, 20 Nov 2015 09:25:58 -0500 Received: from wuerfel.localnet ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue005) with ESMTPSA (Nemesis) id 0M3wF4-1aH2cN2QQU-00rVkZ; Fri, 20 Nov 2015 15:24:41 +0100 From: Arnd Bergmann To: Mark Brown Cc: Sascha Hauer , Liam Girdwood , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peter Zijlstra , Ingo Molnar Subject: [PATCH v3b] regulator: core: avoid unused variable warning Date: Fri, 20 Nov 2015 15:24:39 +0100 Message-ID: <4083086.03MkICpY7S@wuerfel> User-Agent: KMail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jSEZ9V/ZqkjjbCX+D956mj/Ps rq7MlKGv4IQ/OEgu Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The second argument of the mutex_lock_nested() helper is only evaluated if CONFIG_DEBUG_LOCK_ALLOC is set. Otherwise we get this build warning for the new regulator_lock_supply function: drivers/regulator/core.c: In function 'regulator_lock_supply': drivers/regulator/core.c:142:6: warning: unused variable 'i' [-Wunused-variable] To avoid the warning, this restructures the code to make it both simpler and to move the 'i++' outside of the mutex_lock_nested call, where it is now always used and the variable is not flagged as unused. We had some discussion about changing mutex_lock_nested to an inline function, which would make the code do the right thing here, but in the end decided against it, in order to guarantee that mutex_lock_nested() does not introduced overhead without CONFIG_DEBUG_LOCK_ALLOC. Signed-off-by: Arnd Bergmann Fixes: 9f01cd4a915 ("regulator: core: introduce function to lock regulators and its supplies") Link: http://permalink.gmane.org/gmane.linux.kernel/2068900 --- This is a different approach I came up with now, feel free to pick either v3a or v3b of the patch, whichever seems more appropriate to you. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 4cf1390784e5..c9bdca5f3b9b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -138,18 +138,10 @@ static bool have_full_constraints(void) */ static void regulator_lock_supply(struct regulator_dev *rdev) { - struct regulator *supply; - int i = 0; - - while (1) { - mutex_lock_nested(&rdev->mutex, i++); - supply = rdev->supply; - - if (!rdev->supply) - return; + int i; - rdev = supply->rdev; - } + for (i = 0; rdev->supply; rdev = rdev->supply->rdev, i++) + mutex_lock_nested(&rdev->mutex, i); } /**