From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: linux-sparse@vger.kernel.org
Subject: sparse reports "different lock contexts for basic block" when using guard syntax
Date: Mon, 2 Dec 2024 10:25:53 +0100 [thread overview]
Message-ID: <xc3xx56vvesaen7r2c3q5thmrjva7zcfq5habasejlyn7vnpbj@jxsfprt5gfa4> (raw)
[-- 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 --]
next reply other threads:[~2024-12-02 9:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 9:25 Uwe Kleine-König [this message]
2024-12-02 21:06 ` sparse reports "different lock contexts for basic block" when using guard syntax Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xc3xx56vvesaen7r2c3q5thmrjva7zcfq5habasejlyn7vnpbj@jxsfprt5gfa4 \
--to=u.kleine-koenig@baylibre.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).