Skip to contentSkip to conversation

gpio: adnp: fix flow control regression caused by scoped_guard()

PATCH Applied Bartosz Golaszewski 2 participants 3 messages May 22 – May 26 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: adnp: fix flow control regression caused by scoped_guard()

scoped_guard() is implemented as a for loop. Using it to protect code using the continue statement changes the flow as we now only break out of the hidden loop inside scoped_guard(), not the original for loop. Use a regular code block instead.

Fixes c7fe19ed3973 ("gpio: adnp: use lock guards for the I2C lock")
---
 drivers/gpio/gpio-adnp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-adnp.c +3 -1
index 27a80d1143a1..350feea2afa3 100644
@@ -237,7 +237,9 @@ static irqreturn_t adnp_irq(int irq, void *data)
 		unsigned long pending;
 		int err;
 
-		scoped_guard(mutex, &adnp->i2c_lock) {
+		{
+			guard(mutex)(&adnp->i2c_lock);
+
 			err = adnp_read(adnp, GPIO_PLR(adnp) + i, &level);
 			if (err < 0)
 				continue;
Signature · 1 line
2.47.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Bartosz Golaszewski

scoped_guard() is implemented as a for loop. Using it to protect code using the continue statement changes the flow as we now only break out of the hidden loop inside scoped_guard(), not the original for loop. Use a regular code block instead.

Fixes c7fe19ed3973 ("gpio: adnp: use lock guards for the I2C lock")

This class of bugs would be nice to identify with tools, both AI and Cocinelle.

Julia, do you know if we can make a coccicheck script that warn about scoped_guard() { continue; }?

Yours,
Linus Walleij

author Applied
#2 lore raw
In reply to Bartosz Golaszewski
Quoted 6 lines · Bartosz Golaszewski

scoped_guard() is implemented as a for loop. Using it to protect code using the continue statement changes the flow as we now only break out of the hidden loop inside scoped_guard(), not the original for loop. Use a regular code block instead.

Applied, thanks!

[1/1] gpio: adnp: fix flow control regression caused by scoped_guard()

      https://git.kernel.org/brgl/c/7df1b49aadadb0be1baec2a101b3ab3986e40e7f

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>