value overwrite in rtq2208-regulator.c: Overwriting previous write to desc->fixed_uV with value from init_data->constraints.min_uV

Brahmajit <[email protected]> Sun, 29 Sep 2024 19:24:12 +0530
Newsgroups gmane.linux.newbie
Message-ID <dkg6c2stonolj2ffcvybyu3lztg74hpqdu3twfx2oyjutxyaes@jbwefoqlxrog>
Hi Alina,

In rtq2208-regulator.c I came across this code segment

if (!ret) {
	if (fixed_uV != init_data->constraints.min_uV ||
		fixed_uV != init_data->constraints.max_uV)
		return -EINVAL;
	desc->n_voltages = 1;
	desc->fixed_uV = fixed_uV;
	desc->fixed_uV = init_data->constraints.min_uV;
	desc->ops = &rtq2208_regulator_ldo_fix_ops;
} else {
	desc->n_voltages = ARRAY_SIZE(rtq2208_ldo_volt_table);
	desc->volt_table = rtq2208_ldo_volt_table;
	desc->ops = &rtq2208_regulator_ldo_adj_ops;
}

As you can see we are setting the value of desc->fixed_uV twice. Is this
intentional? Because it looks from commit af1296d15d890 (regulator:
rtq2208: Add fixed LDO VOUT property and check that matches the
constraints) we only need desc->fixed_uV = fixed_uV. Isn't the second
assignment (desc->fixed_uV = init_data->constraints.min_uV) making the
previous one (desc->fixed_uV = fixed_uV) obsolete?

I might be wrong but it seems like it should be something like

--- a/drivers/regulator/rtq2208-regulator.c
+++ b/drivers/regulator/rtq2208-regulator.c
@@ -384,7 +384,6 @@ static int rtq2208_of_get_ldo_dvs_ability(struct device *dev)
 				return -EINVAL;
 			desc->n_voltages = 1;
 			desc->fixed_uV = fixed_uV;
-			desc->fixed_uV = init_data->constraints.min_uV;
 			desc->ops = &rtq2208_regulator_ldo_fix_ops;
 		} else {
 			desc->n_voltages = ARRAY_SIZE(rtq2208_ldo_volt_table);

What do you think? Please feel free to correct me if I'm wrong.

Note: This is my first time communicating on the mailing list, please
excuse if I broken any of the mailing list etiquette.

-- 
Regards,
listout