Skip to contentSkip to conversation

regulator: max8973: get rid of extra variable for gpio validity

PATCH In review Laxman Dewangan 2 participants 4 messages Apr 8, 2015 – Apr 10, 2015 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: max8973: get rid of extra variable for gpio validity

To find that dvs-gpio is valid or not, gpio API gpio_is_valid() can be directly used instead of intermediate variable.

Removing the extra variable and using the gpio_is_valid().

---
 drivers/regulator/max8973-regulator.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/regulator/max8973-regulator.c +2 -6
index c3d55c2..1890808 100644
@@ -100,7 +100,6 @@ struct max8973_chip {
 	int curr_vout_val[MAX8973_MAX_VOUT_REG];
 	int curr_vout_reg;
 	int curr_gpio_val;
-	bool valid_dvs_gpio;
 	struct regulator_ops ops;
 };
 
@@ -174,7 +173,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
 	 * If gpios are available to select the VOUT register then least
 	 * recently used register for new configuration.
 	 */
-	if (max->valid_dvs_gpio)
+	if (gpio_is_valid(max->dvs_gpio))
 		found = find_voltage_set_register(max, vsel,
 					&vout_reg, &gpio_val);
 
@@ -191,7 +190,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
 	}
 
 	/* Select proper VOUT register vio gpios */
-	if (max->valid_dvs_gpio) {
+	if (gpio_is_valid(max->dvs_gpio)) {
 		gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
 		max->curr_gpio_val = gpio_val;
 	}
@@ -434,7 +433,6 @@ static int max8973_probe(struct i2c_client *client,
 				max->dvs_gpio, ret);
 			return ret;
 		}
-		max->valid_dvs_gpio = true;
 
 		/*
 		 * Initialize the lru index with vout_reg id
@@ -444,8 +442,6 @@ static int max8973_probe(struct i2c_client *client,
 			max->lru_index[i] = i;
 		max->lru_index[0] = max->curr_vout_reg;
 		max->lru_index[max->curr_vout_reg] = 0;
-	} else {
-		max->valid_dvs_gpio = false;
 	}
 
 	if (pdata) {
Signature · 1 line
1.8.1.5
maintainer
#1 lore raw
Quoted 4 lines · Laxman Dewangan

To find that dvs-gpio is valid or not, gpio API gpio_is_valid() can be directly used instead of intermediate variable.

Removing the extra variable and using the gpio_is_valid().

Are you sure that platform data using 0 as default/unset is still handled correctly after this?

#2 lore raw
Quoted 10 lines · Mark Brown

* PGP Signed by an unknown key

Quoted 4 lines · Laxman Dewangan

To find that dvs-gpio is valid or not, gpio API gpio_is_valid() can be directly used instead of intermediate variable.

Removing the extra variable and using the gpio_is_valid().

Are you sure that platform data using 0 as default/unset is still handled correctly after this?

This issue already exist and this patch will not handle this case because gpio_is_valid() return true for gpio 0 also.

I search the registration of this driver on linux-next and found that it is used from DT only. No one is registering this device from non-DT.

However, I can push another patch to fix the issue as if platform data is provided from non-DT and dvs_gpio is 0 then mark this as -EINVAL so that it will treat this as invalid gpio. Still there will be issue if some platform have real GPIO number as 0 and register from board files.

Does it make sense?

maintainer
#3 lore raw
Quoted 7 lines · Laxman Dewangan

However, I can push another patch to fix the issue as if platform data is provided from non-DT and dvs_gpio is 0 then mark this as -EINVAL so that it will treat this as invalid gpio.
Still there will be issue if some platform have real GPIO number as 0 and register from board files.

Does it make sense?

Yes, that makes sense.