diff mbox series

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

Message ID xc3xx56vvesaen7r2c3q5thmrjva7zcfq5habasejlyn7vnpbj@jxsfprt5gfa4 (mailing list archive)
State New
Headers show
Series sparse reports "different lock contexts for basic block" when using guard syntax | expand

Commit Message

Uwe Kleine-König Dec. 2, 2024, 9:25 a.m. UTC
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:


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

Comments

Linus Torvalds Dec. 2, 2024, 9:06 p.m. UTC | #1
On Mon, 2 Dec 2024 at 01:26, Uwe Kleine-König
<u.kleine-koenig@baylibre.com> wrote:
>
> Trying to understand what sparse wants to tell me, I tried the following
> change and the 2nd warning goes away:

Sparse really doesn't understand the new guard infrastructure. It gets
_parsed_, but that's just about it.

So it parses the cleanup function, but never actually generates the
logic to _call_ the cleanup function when the variable goes out of
scope.

Which obviously then means that none of the context updates of the
cleanup get done, and so the lock context never gets undone.

Sadly, I think sparse is unmaintained these days,

               Linus
diff mbox series

Patch

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;
 }