Linux-Sparse Archive mirror
 help / color / mirror / Atom feed
* sparse reports "different lock contexts for basic block" when using guard syntax
@ 2024-12-02  9:25 Uwe Kleine-König
  2024-12-02 21:06 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2024-12-02  9:25 UTC (permalink / raw)
  To: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 1826 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: sparse reports "different lock contexts for basic block" when using guard syntax
  2024-12-02  9:25 sparse reports "different lock contexts for basic block" when using guard syntax Uwe Kleine-König
@ 2024-12-02 21:06 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2024-12-02 21:06 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: linux-sparse

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-02 21:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-02  9:25 sparse reports "different lock contexts for basic block" when using guard syntax Uwe Kleine-König
2024-12-02 21:06 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).