diff options
author | Hans de Goede <hdegoede@redhat.com> | 2022-01-06 12:06:04 +0100 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2022-02-01 14:29:34 +0100 |
commit | 360108661277a784aacb22913b853e9b0fc4de1c (patch) | |
tree | 8131aa55eadf48dfb5544faabc8c24a832f185d0 /drivers/power | |
parent | 0b80eb6c3832447a28634dc2611cd2a8f53aa189 (diff) | |
download | linux-stable-360108661277a784aacb22913b853e9b0fc4de1c.tar.gz linux-stable-360108661277a784aacb22913b853e9b0fc4de1c.tar.bz2 linux-stable-360108661277a784aacb22913b853e9b0fc4de1c.zip |
power: supply: axp288_fuel_gauge: Use devm_add_action_or_reset() for iio chan release
An existing comment already mentions we: "cannot use devm_iio_channel_get
because x86 systems lack the device<->channel maps which iio_channel_get
will try to use when passed a non NULL device pointer".
Work around this by registering a devm action to free the iio-channels.
This is a step on the way to fully converting the probe() function to
only use devm managed resources.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/supply/axp288_fuel_gauge.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/drivers/power/supply/axp288_fuel_gauge.c b/drivers/power/supply/axp288_fuel_gauge.c index 35f9edf3da09..aaf2d5542316 100644 --- a/drivers/power/supply/axp288_fuel_gauge.c +++ b/drivers/power/supply/axp288_fuel_gauge.c @@ -666,6 +666,16 @@ static int axp288_fuel_gauge_read_initial_regs(struct axp288_fg_info *info) return 0; } +static void axp288_fuel_gauge_release_iio_chans(void *data) +{ + struct axp288_fg_info *info = data; + int i; + + for (i = 0; i < IIO_CHANNEL_NUM; i++) + if (!IS_ERR_OR_NULL(info->iio_channel[i])) + iio_channel_release(info->iio_channel[i]); +} + static int axp288_fuel_gauge_probe(struct platform_device *pdev) { int i, ret = 0; @@ -711,37 +721,35 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) if (ret == -ENODEV) ret = -EPROBE_DEFER; - goto out_free_iio_chan; + axp288_fuel_gauge_release_iio_chans(info); + return ret; } } + ret = devm_add_action_or_reset(dev, axp288_fuel_gauge_release_iio_chans, info); + if (ret) + return ret; + ret = iosf_mbi_block_punit_i2c_access(); if (ret < 0) - goto out_free_iio_chan; + return ret; ret = axp288_fuel_gauge_read_initial_regs(info); iosf_mbi_unblock_punit_i2c_access(); if (ret < 0) - goto out_free_iio_chan; + return ret; psy_cfg.drv_data = info; info->bat = power_supply_register(dev, &fuel_gauge_desc, &psy_cfg); if (IS_ERR(info->bat)) { ret = PTR_ERR(info->bat); dev_err(dev, "failed to register battery: %d\n", ret); - goto out_free_iio_chan; + return ret; } fuel_gauge_init_irq(info, pdev); return 0; - -out_free_iio_chan: - for (i = 0; i < IIO_CHANNEL_NUM; i++) - if (!IS_ERR_OR_NULL(info->iio_channel[i])) - iio_channel_release(info->iio_channel[i]); - - return ret; } static const struct platform_device_id axp288_fg_id_table[] = { @@ -761,9 +769,6 @@ static int axp288_fuel_gauge_remove(struct platform_device *pdev) if (info->irq[i] >= 0) free_irq(info->irq[i], info); - for (i = 0; i < IIO_CHANNEL_NUM; i++) - iio_channel_release(info->iio_channel[i]); - return 0; } |