Skip to content

Commit 3288757

Browse files
tititiou36sre
authored andcommitted
power: supply: ab8500: Fix error handling when calling iio_read_channel_processed()
The ab8500_charger_get_[ac|vbus]_[current|voltage]() functions should return an error code on error. Up to now, an un-initialized value is returned. This makes the error handling of the callers un-reliable. Return the error code instead, to fix the issue. Fixes: 97ab78b ("power: supply: ab8500_charger: Convert to IIO ADC") Signed-off-by: Christophe JAILLET <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/f9f65642331c9e40aaebb888589db043db80b7eb.1719037737.git.christophe.jaillet@wanadoo.fr Signed-off-by: Sebastian Reichel <[email protected]>
1 parent ad175de commit 3288757

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/power/supply/ab8500_charger.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,10 @@ static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di)
488488
/* Only measure voltage if the charger is connected */
489489
if (di->ac.charger_connected) {
490490
ret = iio_read_channel_processed(di->adc_main_charger_v, &vch);
491-
if (ret < 0)
491+
if (ret < 0) {
492492
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
493+
return ret;
494+
}
493495
} else {
494496
vch = 0;
495497
}
@@ -540,8 +542,10 @@ static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di)
540542
/* Only measure voltage if the charger is connected */
541543
if (di->usb.charger_connected) {
542544
ret = iio_read_channel_processed(di->adc_vbus_v, &vch);
543-
if (ret < 0)
545+
if (ret < 0) {
544546
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
547+
return ret;
548+
}
545549
} else {
546550
vch = 0;
547551
}
@@ -563,8 +567,10 @@ static int ab8500_charger_get_usb_current(struct ab8500_charger *di)
563567
/* Only measure current if the charger is online */
564568
if (di->usb.charger_online) {
565569
ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich);
566-
if (ret < 0)
570+
if (ret < 0) {
567571
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
572+
return ret;
573+
}
568574
} else {
569575
ich = 0;
570576
}
@@ -586,8 +592,10 @@ static int ab8500_charger_get_ac_current(struct ab8500_charger *di)
586592
/* Only measure current if the charger is online */
587593
if (di->ac.charger_online) {
588594
ret = iio_read_channel_processed(di->adc_main_charger_c, &ich);
589-
if (ret < 0)
595+
if (ret < 0) {
590596
dev_err(di->dev, "%s ADC conv failed,\n", __func__);
597+
return ret;
598+
}
591599
} else {
592600
ich = 0;
593601
}

0 commit comments

Comments
 (0)