Skip to contentSkip to conversation

gpiolib: Use proper type for bias enumerator in gpio_set_bias()

PATCH In review Andy Shevchenko 2 participants 2 messages Oct 9, 2020 – Oct 19, 2020 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: Use proper type for bias enumerator in gpio_set_bias()

First of all, bias has a special type as being a part of enum pin_config_param. Second, 0 is also defined bias which is equivalent to BUS_HOLD.

Taking into account above, change type of bias variable and refactor gpio_set_bias() in a way that it doesn't use BUS_HOLD as a place holder.

---
 drivers/gpio/gpiolib.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib.c +8 -7
index 33871ad6fed8..4df1f1a23a8b 100644
@@ -2256,8 +2256,8 @@ static int gpio_set_config(struct gpio_desc *desc, enum pin_config_param mode)
 
 static int gpio_set_bias(struct gpio_desc *desc)
 {
-	int bias = 0;
-	int ret = 0;
+	enum pin_config_param bias;
+	int ret;
 
 	if (test_bit(FLAG_BIAS_DISABLE, &desc->flags))
 		bias = PIN_CONFIG_BIAS_DISABLE;
@@ -2265,12 +2265,13 @@ static int gpio_set_bias(struct gpio_desc *desc)
 		bias = PIN_CONFIG_BIAS_PULL_UP;
 	else if (test_bit(FLAG_PULL_DOWN, &desc->flags))
 		bias = PIN_CONFIG_BIAS_PULL_DOWN;
+	else
+		return 0;
+
+	ret = gpio_set_config(desc, bias);
+	if (ret != -ENOTSUPP)
+		return ret;
 
-	if (bias) {
-		ret = gpio_set_config(desc, bias);
-		if (ret != -ENOTSUPP)
-			return ret;
-	}
 	return 0;
 }
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 7 lines · Andy Shevchenko

First of all, bias has a special type as being a part of enum pin_config_param. Second, 0 is also defined bias which is equivalent to BUS_HOLD.

Taking into account above, change type of bias variable and refactor gpio_set_bias() in a way that it doesn't use BUS_HOLD as a place holder.

Patch applied.

Yours,
Linus Walleij