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

power: supply: lp8788: Fix an error handling path in 'lp8788_charger_probe()'

In the probe function, in case of error, resources allocated in
'lp8788_setup_adc_channel()' must be released.

This can be achieved easily by using the devm_ variant of
'iio_channel_get()'.
This has the extra benefit to simplify the remove function and to axe the
'lp8788_release_adc_channel()' function which is now useless.

Fixes: 98a276649358 ("power_supply: Add new lp8788 charger driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Christophe JAILLET and committed by
Sebastian Reichel
934ed384 a776f560

+2 -16
+2 -16
drivers/power/supply/lp8788-charger.c
··· 572 572 return; 573 573 574 574 /* ADC channel for battery voltage */ 575 - chan = iio_channel_get(dev, pdata->adc_vbatt); 575 + chan = devm_iio_channel_get(dev, pdata->adc_vbatt); 576 576 pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan; 577 577 578 578 /* ADC channel for battery temperature */ 579 - chan = iio_channel_get(dev, pdata->adc_batt_temp); 579 + chan = devm_iio_channel_get(dev, pdata->adc_batt_temp); 580 580 pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan; 581 - } 582 - 583 - static void lp8788_release_adc_channel(struct lp8788_charger *pchg) 584 - { 585 - int i; 586 - 587 - for (i = 0; i < LP8788_NUM_CHG_ADC; i++) { 588 - if (!pchg->chan[i]) 589 - continue; 590 - 591 - iio_channel_release(pchg->chan[i]); 592 - pchg->chan[i] = NULL; 593 - } 594 581 } 595 582 596 583 static ssize_t lp8788_show_charger_status(struct device *dev, ··· 722 735 flush_work(&pchg->charger_work); 723 736 lp8788_irq_unregister(pdev, pchg); 724 737 lp8788_psy_unregister(pchg); 725 - lp8788_release_adc_channel(pchg); 726 738 727 739 return 0; 728 740 }