Skip to contentSkip to conversation

usb: musb: davinci: change the variable type

PATCH In review Saurav Girepunje 2 participants 3 messages Apr 18, 2021 – Apr 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: musb: davinci: change the variable type

vbus_state is define as bool but on davinci.c assigning a value '-1' to the bool variable.

Fix the following coccicheck error:

drivers/usb/musb//davinci.c:532:2-18:
ERROR: Assignment of non-0/1 constant to bool variable

By changing the variable type to int.
As vbus_state need more three values/states more required by vbus_state variable.

/* 0/1 vs "-1 == unknown/init" */

---
 drivers/usb/musb/davinci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/musb/davinci.c +1 -1
index 704435526394..e3435621a9d9 100644
@@ -36,7 +36,7 @@ struct davinci_glue {
 	struct device		*dev;
 	struct platform_device	*musb;
 	struct clk		*clk;
-	bool			vbus_state;
+	int			vbus_state;
 	struct gpio_desc	*vbus;
 	struct work_struct	vbus_work;
 };
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 2 lines · Saurav Girepunje

vbus_state is define as bool but on davinci.c assigning a value '-1' to the bool variable.

Does it also test that value?

If so, shouldn't that logic error be fixed instead of working around it by changing the variable type?

This feels wrong...

thanks,

greg k-h

#2 lore raw
Quoted 6 lines · Greg KH
Quoted 2 lines · Saurav Girepunje

vbus_state is define as bool but on davinci.c assigning a value '-1' to the bool variable.

Does it also test that value?

Quoted 8 lines

If so, shouldn't that logic error be fixed instead of working around it by changing the variable type?

This feels wrong...

thanks,

greg k-h

vbus_state is assign with the value of "-1" in davinci.c file. However it check value whether it is zero or a non-zero.

This value pass On gpio lib function.Which need this value to bool only.

On below "glue->vbus_state" should be 1.

	glue->vbus = devm_gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW);
	if (IS_ERR(glue->vbus)) {
                ret = PTR_ERR(glue->vbus);
                goto err0;
        } else {
                glue->vbus_state = -1;
                INIT_WORK(&glue->vbus_work, evm_deferred_drvvbus);
        }