From: "Csókás, Bence" <csokas.bence@prolan.hu>
To: Sebastian Reichel <sebastian.reichel@collabora.com>,
Samuel Holland <samuel@sholland.org>, <linux-pm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: "Csókás, Bence" <csokas.bence@prolan.hu>,
"Sebastian Reichel" <sre@kernel.org>
Subject: [PATCH v5 2/8] power: ip5xxx_power: Fix return value on ADC read errors
Date: Tue, 19 Nov 2024 19:07:34 +0100 [thread overview]
Message-ID: <20241119180741.2237692-2-csokas.bence@prolan.hu> (raw)
In-Reply-To: <20241119180741.2237692-1-csokas.bence@prolan.hu>
If ADC read returns an error, the return value was silently ignored,
execution continued and an uninitialized value and a return code of 0
was passed back to userspace. The only exception was
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, which bailed out correctly.
Fix returns for the other cases as well.
Fixes: 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")
Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
---
drivers/power/supply/ip5xxx_power.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
index 2d4435881a9e..41d91504eb32 100644
--- a/drivers/power/supply/ip5xxx_power.c
+++ b/drivers/power/supply/ip5xxx_power.c
@@ -395,18 +395,24 @@ static int ip5xxx_battery_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.volt, &raw);
+ if (ret)
+ return ret;
val->intval = 2600000 + DIV_ROUND_CLOSEST(raw * 26855, 100);
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_OCV:
ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.open_volt, &raw);
+ if (ret)
+ return ret;
val->intval = 2600000 + DIV_ROUND_CLOSEST(raw * 26855, 100);
return 0;
case POWER_SUPPLY_PROP_CURRENT_NOW:
ret = ip5xxx_battery_read_adc(ip5xxx, &ip5xxx->regs.battery.adc.curr, &raw);
+ if (ret)
+ return ret;
val->intval = DIV_ROUND_CLOSEST(raw * 149197, 200);
return 0;
--
2.34.1
next prev parent reply other threads:[~2024-11-19 18:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 18:07 [PATCH v5 1/8] power: ip5xxx_power: Use regmap_field API Csókás, Bence
2024-11-19 18:07 ` Csókás, Bence [this message]
2024-12-05 11:00 ` [PATCH v5 2/8] power: ip5xxx_power: Fix return value on ADC read errors Sebastian Reichel
2024-11-19 18:07 ` [PATCH v5 3/8] power: ip5xxx_power: Allow for more parameters to be configured Csókás, Bence
2024-12-06 19:51 ` Kees Bakker
2024-12-08 13:00 ` Csókás Bence
2024-11-19 18:07 ` [PATCH v5 4/8] power: ip5xxx_power: Add battery type for 4.4V Csókás, Bence
2024-11-19 18:07 ` [PATCH v5 5/8] power: ip5xxx_power: Check for optional bits Csókás, Bence
2024-12-05 11:01 ` Sebastian Reichel
2024-11-19 18:07 ` [PATCH v5 6/8] power: ip5xxx_power: Fall back to Charge End bit if status register is absent Csókás, Bence
2024-11-19 18:07 ` [PATCH v5 7/8] dt-bindings: trivial-devices: Add Injoinic IP5306 Csókás, Bence
2024-11-19 18:07 ` [PATCH v5 8/8] power: ip5xxx_power: Add support for IP5306 Csókás, Bence
2024-12-05 1:36 ` (subset) [PATCH v5 1/8] power: ip5xxx_power: Use regmap_field API Sebastian Reichel
2024-12-05 11:02 ` 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=20241119180741.2237692-2-csokas.bence@prolan.hu \
--to=csokas.bence@prolan.hu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=samuel@sholland.org \
--cc=sebastian.reichel@collabora.com \
--cc=sre@kernel.org \
/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
all inboxes | Powered by JetHome®