sparse reports "different lock contexts for basic block" when using guard syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

on Linux v6.13-rc1 I get:

	$ armmake C=1 drivers/pwm/pwm-gpio.o
	...
	  CC [M]  drivers/pwm/pwm-gpio.o
	  CHECK   /home/uwe/gsrc/linux/drivers/pwm/pwm-gpio.c
	drivers/pwm/pwm-gpio.c:98:9: warning: context imbalance in 'pwm_gpio_timer' - wrong count at exit
	drivers/pwm/pwm-gpio.c:101:12: warning: context imbalance in 'pwm_gpio_apply' - different lock contexts for basic block
	drivers/pwm/pwm-gpio.c:166:9: warning: context imbalance in 'pwm_gpio_get_state' - wrong count at exit

with

	$ sparse --version
	0.6.4 (Debian: 0.6.4-4+b1)

but also on sparse/main.

Trying to understand what sparse wants to tell me, I tried the following
change and the 2nd warning goes away:

diff --git a/drivers/pwm/pwm-gpio.c b/drivers/pwm/pwm-gpio.c
index 9f8884ac7504..d811b1f71c92 100644
--- a/drivers/pwm/pwm-gpio.c
+++ b/drivers/pwm/pwm-gpio.c
@@ -103,6 +103,7 @@ static int pwm_gpio_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 {
 	struct pwm_gpio *gpwm = pwmchip_get_drvdata(chip);
 	bool invert = state->polarity == PWM_POLARITY_INVERSED;
+	unsigned long flags;
 
 	if (state->duty_cycle && state->duty_cycle < hrtimer_resolution)
 		return -EINVAL;
@@ -125,7 +126,7 @@ static int pwm_gpio_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			return ret;
 	}
 
-	guard(spinlock_irqsave)(&gpwm->lock);
+	spin_lock_irqsave(&gpwm->lock, flags);
 
 	if (!state->enabled) {
 		pwm_gpio_round(&gpwm->state, state);
@@ -148,6 +149,7 @@ static int pwm_gpio_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 				      HRTIMER_MODE_REL);
 	}
 
+	spin_unlock_irqrestore(&gpwm->lock, flags);
 	return 0;
 }
 

But unless I'm mistaken the new code in pwm-gpio.c is equivalent, so
maybe sparse doesn't understand the guard syntax?

Any hints?

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux