Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d06563cb authored by Axel Lin's avatar Axel Lin Committed by Liam Girdwood
Browse files

regulator: 88pm8607 - fix value range checking for accessing info->vol_table



In choose_voltage(), we use i as array index of info->vol_table.
The valid value range for i should be 0 .. ARRAY_SIZE(info->vol_table) - 1.

Take LDO1 as example, ARRAY_SIZE(LDO1_table) is 4, vol_nbits of LDO1 is 2.
for (i = 0; i < (2 << info->vol_nbits); i++)  is equivalent to
for (i = 0; i < 8; i++)
which is wrong.

The same value range checking also applies for index in pm8607_list_voltage().

Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Acked-by: default avatarMark Brown <broonie@openource.wolfsonmicro.com>
Signed-off-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent b9e5d11a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -215,7 +215,7 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
	struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
	struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
	int ret = -EINVAL;
	int ret = -EINVAL;


	if (info->vol_table && (index < (2 << info->vol_nbits))) {
	if (info->vol_table && (index < (1 << info->vol_nbits))) {
		ret = info->vol_table[index];
		ret = info->vol_table[index];
		if (info->slope_double)
		if (info->slope_double)
			ret <<= 1;
			ret <<= 1;
@@ -233,7 +233,7 @@ static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
		max_uV = max_uV >> 1;
		max_uV = max_uV >> 1;
	}
	}
	if (info->vol_table) {
	if (info->vol_table) {
		for (i = 0; i < (2 << info->vol_nbits); i++) {
		for (i = 0; i < (1 << info->vol_nbits); i++) {
			if (!info->vol_table[i])
			if (!info->vol_table[i])
				break;
				break;
			if ((min_uV <= info->vol_table[i])
			if ((min_uV <= info->vol_table[i])