Skip to contentSkip to conversation

regulator: core: avoid unused variable warning

PATCH In review Arnd Bergmann 2 participants 3 messages Oct 9, 2015 – Oct 13, 2015 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: core: avoid unused variable warning

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 patch moves the postincrement outside of the call mutex_lock_nested(), which is enough to shut up gcc about it.

Fixes 9f01cd4a915 ("regulator: core: introduce function to lock regulators and its supplies")
drivers/regulator/core.c +3 -1
index 96dd7e1f1f28..bac8eefbfeff 100644
@@ -142,7 +142,9 @@ static void __maybe_unused regulator_lock_supply(struct regulator_dev *rdev)
 	int i = 0;
 
 	while (1) {
-		mutex_lock_nested(&rdev->mutex, i++);
+		mutex_lock_nested(&rdev->mutex, i);
+		i++;
+
 		supply = rdev->supply;
 
 		if (!rdev->supply)
maintainer
#1 lore raw
Quoted 4 lines · Arnd Bergmann

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:

Shouldn't we have an annotation or something for this in
mutex_lock_nested()? It seems like something that might come up
elsewhere and it's a bit of a surprise to have one of the arguments
there not be evaluated.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151012/7f04d4b2/attachment.sig>

#2 lore raw
Quoted 7 lines · On Monday 12 October 2015 16:42:31 Mark Brown wrote:
Quoted 4 lines · Arnd Bergmann

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:

Quoted 5 lines

Shouldn't we have an annotation or something for this in mutex_lock_nested()? It seems like something that might come up elsewhere and it's a bit of a surprise to have one of the arguments there not be evaluated.

I've found a better solution by making mutex_lock_nested an inline function. Will send a new patch.

Arnd