Commit 8ac67534 authored by Andrew Davis's avatar Andrew Davis Committed by Sebastian Reichel

power: supply: twl4030_madc: Use devm_iio_channel_get() helper

Use the device lifecycle managed get function. This helps prevent
mistakes like releasing out of order in cleanup functions and
forgetting to release on error paths.
Signed-off-by: default avatarAndrew Davis <afd@ti.com>
Link: https://lore.kernel.org/r/20240123163653.384385-21-afd@ti.comSigned-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 4cb372a0
...@@ -188,30 +188,23 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev) ...@@ -188,30 +188,23 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
struct twl4030_madc_battery *twl4030_madc_bat; struct twl4030_madc_battery *twl4030_madc_bat;
struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data; struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data;
struct power_supply_config psy_cfg = {}; struct power_supply_config psy_cfg = {};
int ret = 0;
twl4030_madc_bat = devm_kzalloc(&pdev->dev, sizeof(*twl4030_madc_bat), twl4030_madc_bat = devm_kzalloc(&pdev->dev, sizeof(*twl4030_madc_bat),
GFP_KERNEL); GFP_KERNEL);
if (!twl4030_madc_bat) if (!twl4030_madc_bat)
return -ENOMEM; return -ENOMEM;
twl4030_madc_bat->channel_temp = iio_channel_get(&pdev->dev, "temp"); twl4030_madc_bat->channel_temp = devm_iio_channel_get(&pdev->dev, "temp");
if (IS_ERR(twl4030_madc_bat->channel_temp)) { if (IS_ERR(twl4030_madc_bat->channel_temp))
ret = PTR_ERR(twl4030_madc_bat->channel_temp); return PTR_ERR(twl4030_madc_bat->channel_temp);
goto err;
}
twl4030_madc_bat->channel_ichg = iio_channel_get(&pdev->dev, "ichg"); twl4030_madc_bat->channel_ichg = devm_iio_channel_get(&pdev->dev, "ichg");
if (IS_ERR(twl4030_madc_bat->channel_ichg)) { if (IS_ERR(twl4030_madc_bat->channel_ichg))
ret = PTR_ERR(twl4030_madc_bat->channel_ichg); return PTR_ERR(twl4030_madc_bat->channel_ichg);
goto err_temp;
}
twl4030_madc_bat->channel_vbat = iio_channel_get(&pdev->dev, "vbat"); twl4030_madc_bat->channel_vbat = devm_iio_channel_get(&pdev->dev, "vbat");
if (IS_ERR(twl4030_madc_bat->channel_vbat)) { if (IS_ERR(twl4030_madc_bat->channel_vbat))
ret = PTR_ERR(twl4030_madc_bat->channel_vbat); return PTR_ERR(twl4030_madc_bat->channel_vbat);
goto err_ichg;
}
/* sort charging and discharging calibration data */ /* sort charging and discharging calibration data */
sort(pdata->charging, pdata->charging_size, sort(pdata->charging, pdata->charging_size,
...@@ -227,21 +220,10 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev) ...@@ -227,21 +220,10 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
twl4030_madc_bat->psy = power_supply_register(&pdev->dev, twl4030_madc_bat->psy = power_supply_register(&pdev->dev,
&twl4030_madc_bat_desc, &twl4030_madc_bat_desc,
&psy_cfg); &psy_cfg);
if (IS_ERR(twl4030_madc_bat->psy)) { if (IS_ERR(twl4030_madc_bat->psy))
ret = PTR_ERR(twl4030_madc_bat->psy); return PTR_ERR(twl4030_madc_bat->psy);
goto err_vbat;
}
return 0; return 0;
err_vbat:
iio_channel_release(twl4030_madc_bat->channel_vbat);
err_ichg:
iio_channel_release(twl4030_madc_bat->channel_ichg);
err_temp:
iio_channel_release(twl4030_madc_bat->channel_temp);
err:
return ret;
} }
static void twl4030_madc_battery_remove(struct platform_device *pdev) static void twl4030_madc_battery_remove(struct platform_device *pdev)
...@@ -249,10 +231,6 @@ static void twl4030_madc_battery_remove(struct platform_device *pdev) ...@@ -249,10 +231,6 @@ static void twl4030_madc_battery_remove(struct platform_device *pdev)
struct twl4030_madc_battery *bat = platform_get_drvdata(pdev); struct twl4030_madc_battery *bat = platform_get_drvdata(pdev);
power_supply_unregister(bat->psy); power_supply_unregister(bat->psy);
iio_channel_release(bat->channel_vbat);
iio_channel_release(bat->channel_ichg);
iio_channel_release(bat->channel_temp);
} }
static struct platform_driver twl4030_madc_battery_driver = { static struct platform_driver twl4030_madc_battery_driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment