From: Andrew Davis <afd@ti.com>
To: "Sebastian Reichel" <sre@kernel.org>,
"Support Opensource" <support.opensource@diasemi.com>,
"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
"Pali Rohár" <pali@kernel.org>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Andrew Davis <afd@ti.com>
Subject: [PATCH 20/21] power: supply: twl4030_madc: Use devm_iio_channel_get() helper
Date: Tue, 23 Jan 2024 10:36:52 -0600 [thread overview]
Message-ID: <20240123163653.384385-21-afd@ti.com> (raw)
In-Reply-To: <20240123163653.384385-1-afd@ti.com>
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: Andrew Davis <afd@ti.com>
---
drivers/power/supply/twl4030_madc_battery.c | 44 ++++++---------------
1 file changed, 11 insertions(+), 33 deletions(-)
diff --git a/drivers/power/supply/twl4030_madc_battery.c b/drivers/power/supply/twl4030_madc_battery.c
index 33106476bea2c..cd9e94134ab21 100644
--- a/drivers/power/supply/twl4030_madc_battery.c
+++ b/drivers/power/supply/twl4030_madc_battery.c
@@ -188,30 +188,23 @@ static int twl4030_madc_battery_probe(struct platform_device *pdev)
struct twl4030_madc_battery *twl4030_madc_bat;
struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data;
struct power_supply_config psy_cfg = {};
- int ret = 0;
twl4030_madc_bat = devm_kzalloc(&pdev->dev, sizeof(*twl4030_madc_bat),
GFP_KERNEL);
if (!twl4030_madc_bat)
return -ENOMEM;
- twl4030_madc_bat->channel_temp = iio_channel_get(&pdev->dev, "temp");
- if (IS_ERR(twl4030_madc_bat->channel_temp)) {
- ret = PTR_ERR(twl4030_madc_bat->channel_temp);
- goto err;
- }
+ twl4030_madc_bat->channel_temp = devm_iio_channel_get(&pdev->dev, "temp");
+ if (IS_ERR(twl4030_madc_bat->channel_temp))
+ return PTR_ERR(twl4030_madc_bat->channel_temp);
- twl4030_madc_bat->channel_ichg = iio_channel_get(&pdev->dev, "ichg");
- if (IS_ERR(twl4030_madc_bat->channel_ichg)) {
- ret = PTR_ERR(twl4030_madc_bat->channel_ichg);
- goto err_temp;
- }
+ twl4030_madc_bat->channel_ichg = devm_iio_channel_get(&pdev->dev, "ichg");
+ if (IS_ERR(twl4030_madc_bat->channel_ichg))
+ return PTR_ERR(twl4030_madc_bat->channel_ichg);
- twl4030_madc_bat->channel_vbat = iio_channel_get(&pdev->dev, "vbat");
- if (IS_ERR(twl4030_madc_bat->channel_vbat)) {
- ret = PTR_ERR(twl4030_madc_bat->channel_vbat);
- goto err_ichg;
- }
+ twl4030_madc_bat->channel_vbat = devm_iio_channel_get(&pdev->dev, "vbat");
+ if (IS_ERR(twl4030_madc_bat->channel_vbat))
+ return PTR_ERR(twl4030_madc_bat->channel_vbat);
/* sort charging and discharging calibration data */
sort(pdata->charging, pdata->charging_size,
@@ -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_desc,
&psy_cfg);
- if (IS_ERR(twl4030_madc_bat->psy)) {
- ret = PTR_ERR(twl4030_madc_bat->psy);
- goto err_vbat;
- }
+ if (IS_ERR(twl4030_madc_bat->psy))
+ return PTR_ERR(twl4030_madc_bat->psy);
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)
@@ -249,10 +231,6 @@ static void twl4030_madc_battery_remove(struct platform_device *pdev)
struct twl4030_madc_battery *bat = platform_get_drvdata(pdev);
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 = {
--
2.39.2
next prev parent reply other threads:[~2024-01-23 16:37 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 16:36 [PATCH 00/21] Power supply register with devm Andrew Davis
2024-01-23 16:36 ` [PATCH 01/21] power: supply: da9030: Use devm_power_supply_register() helper Andrew Davis
2024-01-23 16:36 ` [PATCH 02/21] power: supply: da9052: " Andrew Davis
2024-01-23 16:36 ` [PATCH 03/21] power: supply: ds2760: " Andrew Davis
2024-01-23 16:36 ` [PATCH 04/21] power: supply: goldfish: " Andrew Davis
2024-01-23 16:36 ` [PATCH 05/21] power: supply: lp8727: " Andrew Davis
2024-01-23 16:36 ` [PATCH 06/21] power: supply: lp8788: " Andrew Davis
2024-01-23 16:36 ` [PATCH 07/21] power: supply: max14577: " Andrew Davis
2024-01-23 16:36 ` [PATCH 08/21] power: supply: max77693: " Andrew Davis
2024-01-26 11:56 ` kernel test robot
2024-01-23 16:36 ` [PATCH 09/21] power: supply: max8925: " Andrew Davis
2024-01-26 12:28 ` kernel test robot
2024-01-23 16:36 ` [PATCH 10/21] power: supply: pcf50633: " Andrew Davis
2024-01-23 16:36 ` [PATCH 11/21] power: supply: rt5033: " Andrew Davis
2024-01-23 16:36 ` [PATCH 12/21] power: supply: tps65090: " Andrew Davis
2024-01-23 16:36 ` [PATCH 13/21] power: supply: wm831x: " Andrew Davis
2024-01-23 16:36 ` [PATCH 14/21] " Andrew Davis
2024-01-23 16:36 ` [PATCH 15/21] power: supply: wm8350: " Andrew Davis
2024-01-26 13:00 ` kernel test robot
2024-01-23 16:36 ` [PATCH 16/21] power: supply: da9150: Use devm_iio_channel_get() helper Andrew Davis
2024-01-23 16:36 ` [PATCH 17/21] power: supply: da9150: Use devm_power_supply_register() helper Andrew Davis
2024-01-23 16:36 ` [PATCH 18/21] power: supply: rx51: Use devm_iio_channel_get() helper Andrew Davis
2024-01-23 16:36 ` [PATCH 19/21] power: supply: rx51: Use devm_power_supply_register() helper Andrew Davis
2024-01-23 16:36 ` Andrew Davis [this message]
2024-01-23 16:36 ` [PATCH 21/21] power: supply: twl4030_madc: " Andrew Davis
2024-01-27 0:48 ` (subset) [PATCH 00/21] Power supply register with devm Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240123163653.384385-21-afd@ti.com \
--to=afd@ti.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pali@kernel.org \
--cc=sre@kernel.org \
--cc=support.opensource@diasemi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox