From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760215AbbKTO0A (ORCPT ); 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 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/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:jTTC2opABtMlosC54a+1kd/2JKRK8ylwjiUtp+p/FDST3IS4k9B wVhoTnAnmehnrO67YFpLnZg2IEmrntiZ66tMCxhAw75W1h4wFQbdVOsnwXqjfAmmN6YOAO/ 2Z4rjj7X4ZDtGKnV4tH/Z499q2KsKvCvDJ8e/X1QNZmPanVwvJD7r6Mxz34Ubp1WNHOPrT5 HTjB8P0eXRJqlElkzMztg== X-UI-Out-Filterresults: notjunk:1;V01:K0:DFDENyAz1PU=:EH9dmF9QHizKZkY7TI3bqV 4AYEbe8gHnuwwMYWqHVGTGLgRVKZ2XuHUlJXYYyhS0W02evlx7GtaD1tRisZIlZSPfANhPdMv CIxZpOe/nPQvXJFchZ790Y8IehfeLK5bC+AbRCyCeLk/gkzGBnoXr9J+JMnJI5PlByz3Bq0qb t4hvHl1/8mL9cJvc1076B8/QVfoxBGIcMCmFsLnSNTm2VRvIk7bfSH0GpiHWWArqVOkD4b1Hu PeaczhNiHHeGik3nFkjk0+sbsq59gaYaQtgQO2dKFieSC9RHmZFhJcV6e4777xLsvktNE+Fsp OiG1k1iG0NEXu0NbsYZ1Po5QaXs26R3YB95aI5jtLAkTT7PHRm7mS6n0Y+3QZeTHqc6blfQBi 2XYqAUmm5mfDgpHk8JhVqfZRT+P7iXRxBB01WbJ2BdYE9f5E0+J06JsNMaKnxlxOFMl8fZQb4 y7tFEMbgKnWyGKrnymS/0RW8X1RPuq5qRJMIbjDeVavQjHpYbqlqOPAHlOiFmw9ZpohRGOyE8 saN0HPxtcIIW0G6XVmM47B36oaBbAbf8KWlwPoiEqwLWLgaFC/14QAZ4Odt7EkfvjnaloJ0PN J4WzHGAjfEv6743Gs94yZfBYCv/yf9GC8cI08v2Lr3u4f2j+2DNqczlstdE4vSYxIpPT/gMbT 7bnOAXlW8LRSdZ3cBbcLzeghxiMsYq6hKG8kQ+NWsT/Wng18jSEZ9V/ZqkjjbCX+D956mj/Ps rq7MlKGv4IQ/OEgu Sender: linux-kernel-owner@vger.kernel.org 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. 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); } /**