Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 97ab78bac5d0 ("power: supply: ab8500_charger: Convert to IIO ADC")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/f9f65642331c9e40aaebb888589db043db80b7eb.1719037737.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Christophe JAILLET and committed by
Sebastian Reichel
32887570 ad175de1

+12 -4
+12 -4
drivers/power/supply/ab8500_charger.c
··· 488 488 /* Only measure voltage if the charger is connected */ 489 489 if (di->ac.charger_connected) { 490 490 ret = iio_read_channel_processed(di->adc_main_charger_v, &vch); 491 - if (ret < 0) 491 + if (ret < 0) { 492 492 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 493 + return ret; 494 + } 493 495 } else { 494 496 vch = 0; 495 497 } ··· 542 540 /* Only measure voltage if the charger is connected */ 543 541 if (di->usb.charger_connected) { 544 542 ret = iio_read_channel_processed(di->adc_vbus_v, &vch); 545 - if (ret < 0) 543 + if (ret < 0) { 546 544 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 545 + return ret; 546 + } 547 547 } else { 548 548 vch = 0; 549 549 } ··· 567 563 /* Only measure current if the charger is online */ 568 564 if (di->usb.charger_online) { 569 565 ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich); 570 - if (ret < 0) 566 + if (ret < 0) { 571 567 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 568 + return ret; 569 + } 572 570 } else { 573 571 ich = 0; 574 572 } ··· 592 586 /* Only measure current if the charger is online */ 593 587 if (di->ac.charger_online) { 594 588 ret = iio_read_channel_processed(di->adc_main_charger_c, &ich); 595 - if (ret < 0) 589 + if (ret < 0) { 596 590 dev_err(di->dev, "%s ADC conv failed,\n", __func__); 591 + return ret; 592 + } 597 593 } else { 598 594 ich = 0; 599 595 }