diff mbox series

[v2] power/supply: ingenic-battery: Don't change scale if there's only one

Message ID 20191114163500.57384-1-paul@crapouillou.net (mailing list archive)
State Not Applicable, archived
Headers show
Series [v2] power/supply: ingenic-battery: Don't change scale if there's only one | expand

Commit Message

Paul Cercueil Nov. 14, 2019, 4:35 p.m. UTC
The ADC in the JZ4740 can work either in high-precision mode with a 2.5V
range, or in low-precision mode with a 7.5V range. The code in place in
this driver will select the proper scale according to the maximum
voltage of the battery.

The JZ4770 however only has one mode, with a 6.6V range. If only one
scale is available, there's no need to change it (and nothing to change
it to), and trying to do so will fail with -EINVAL.

Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery driver.")

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Cc: stable@vger.kernel.org
---

Notes:
    v2: Rebased on v5.4-rc7

 drivers/power/supply/ingenic-battery.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Artur Rojek Nov. 15, 2019, 5:39 p.m. UTC | #1
Hi Paul.
Comments inline.

On 2019-11-14 17:35, Paul Cercueil wrote:
> The ADC in the JZ4740 can work either in high-precision mode with a 
> 2.5V
> range, or in low-precision mode with a 7.5V range. The code in place in
> this driver will select the proper scale according to the maximum
> voltage of the battery.
> 
> The JZ4770 however only has one mode, with a 6.6V range. If only one
> scale is available, there's no need to change it (and nothing to change
> it to), and trying to do so will fail with -EINVAL.
> 
> Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery 
> driver.")
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> Cc: stable@vger.kernel.org
> ---
> 
> Notes:
>     v2: Rebased on v5.4-rc7
> 
>  drivers/power/supply/ingenic-battery.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/power/supply/ingenic-battery.c
> b/drivers/power/supply/ingenic-battery.c
> index 35816d4b3012..5a53057b4f64 100644
> --- a/drivers/power/supply/ingenic-battery.c
> +++ b/drivers/power/supply/ingenic-battery.c
> @@ -80,6 +80,10 @@ static int ingenic_battery_set_scale(struct
> ingenic_battery *bat)
>  	if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2)
>  		return -EINVAL;
> 
> +	/* Only one (fractional) entry - nothing to change */
> +	if (scale_len == 2)
> +		return 0;
> +

This function also serves to validate that the maximum voltage is in 
range of available scales.
Please move your code down a bit so that the check for max_mV is still 
being done.

Thanks,
Artur

>  	max_mV = bat->info.voltage_max_design_uv / 1000;
> 
>  	for (i = 0; i < scale_len; i += 2) {
Paul Cercueil Nov. 16, 2019, 1:54 p.m. UTC | #2
Hi Artur,


Le ven., nov. 15, 2019 at 18:39, Artur Rojek <contact@artur-rojek.eu> a 
écrit :
> Hi Paul.
> Comments inline.
> 
> On 2019-11-14 17:35, Paul Cercueil wrote:
>> The ADC in the JZ4740 can work either in high-precision mode with a 
>> 2.5V
>> range, or in low-precision mode with a 7.5V range. The code in place 
>> in
>> this driver will select the proper scale according to the maximum
>> voltage of the battery.
>> 
>> The JZ4770 however only has one mode, with a 6.6V range. If only one
>> scale is available, there's no need to change it (and nothing to 
>> change
>> it to), and trying to do so will fail with -EINVAL.
>> 
>> Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery 
>> driver.")
>> 
>> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>> Cc: stable@vger.kernel.org
>> ---
>> 
>> Notes:
>>     v2: Rebased on v5.4-rc7
>> 
>>  drivers/power/supply/ingenic-battery.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>> 
>> diff --git a/drivers/power/supply/ingenic-battery.c
>> b/drivers/power/supply/ingenic-battery.c
>> index 35816d4b3012..5a53057b4f64 100644
>> --- a/drivers/power/supply/ingenic-battery.c
>> +++ b/drivers/power/supply/ingenic-battery.c
>> @@ -80,6 +80,10 @@ static int ingenic_battery_set_scale(struct
>> ingenic_battery *bat)
>>  	if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2)
>>  		return -EINVAL;
>> 
>> +	/* Only one (fractional) entry - nothing to change */
>> +	if (scale_len == 2)
>> +		return 0;
>> +
> 
> This function also serves to validate that the maximum voltage is in 
> range of available scales.
> Please move your code down a bit so that the check for max_mV is 
> still being done.

Good point - I'll send a V3.

-Paul

> 
> Thanks,
> Artur
> 
>>  	max_mV = bat->info.voltage_max_design_uv / 1000;
>> 
>>  	for (i = 0; i < scale_len; i += 2) {
diff mbox series

Patch

diff --git a/drivers/power/supply/ingenic-battery.c b/drivers/power/supply/ingenic-battery.c
index 35816d4b3012..5a53057b4f64 100644
--- a/drivers/power/supply/ingenic-battery.c
+++ b/drivers/power/supply/ingenic-battery.c
@@ -80,6 +80,10 @@  static int ingenic_battery_set_scale(struct ingenic_battery *bat)
 	if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2)
 		return -EINVAL;
 
+	/* Only one (fractional) entry - nothing to change */
+	if (scale_len == 2)
+		return 0;
+
 	max_mV = bat->info.voltage_max_design_uv / 1000;
 
 	for (i = 0; i < scale_len; i += 2) {