* [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test
@ 2022-08-27 7:32 Wei Yongjun
2022-08-27 7:32 ` [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Wei Yongjun
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Wei Yongjun @ 2022-08-27 7:32 UTC (permalink / raw)
To: Michael Hennerich, Sebastian Reichel; +Cc: Wei Yongjun, linux-pm, linux-kernel
This series fixes some issues found by device mockup unittest, not
sure how about the real device.
Wei Yongjun (2):
power: supply: adp5061: fix out-of-bounds read in
adp5061_get_chg_type()
power: supply: adp5061: show unknown capacity_level as text
drivers/power/supply/adp5061.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type()
2022-08-27 7:32 [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Wei Yongjun
@ 2022-08-27 7:32 ` Wei Yongjun
2022-09-05 11:46 ` Hennerich, Michael
2022-08-27 7:32 ` [PATCH -next 2/2] power: supply: adp5061: show unknown capacity_level as text Wei Yongjun
2022-09-11 12:19 ` [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Sebastian Reichel
2 siblings, 1 reply; 6+ messages in thread
From: Wei Yongjun @ 2022-08-27 7:32 UTC (permalink / raw)
To: Michael Hennerich, Sebastian Reichel; +Cc: Wei Yongjun, linux-pm, linux-kernel
ADP5061_CHG_STATUS_1_CHG_STATUS is masked with 0x07, which means a length
of 8, but adp5061_chg_type array size is 4, may end up reading 4 elements
beyond the end of the adp5061_chg_type[] array.
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
drivers/power/supply/adp5061.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index 003557043ab3..daee1161c305 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -427,11 +427,11 @@ static int adp5061_get_chg_type(struct adp5061_state *st,
if (ret < 0)
return ret;
- chg_type = adp5061_chg_type[ADP5061_CHG_STATUS_1_CHG_STATUS(status1)];
- if (chg_type > ADP5061_CHG_FAST_CV)
+ chg_type = ADP5061_CHG_STATUS_1_CHG_STATUS(status1);
+ if (chg_type >= ARRAY_SIZE(adp5061_chg_type))
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
else
- val->intval = chg_type;
+ val->intval = adp5061_chg_type[chg_type];
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 2/2] power: supply: adp5061: show unknown capacity_level as text
2022-08-27 7:32 [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Wei Yongjun
2022-08-27 7:32 ` [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Wei Yongjun
@ 2022-08-27 7:32 ` Wei Yongjun
2022-09-05 11:46 ` Hennerich, Michael
2022-09-11 12:19 ` [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Sebastian Reichel
2 siblings, 1 reply; 6+ messages in thread
From: Wei Yongjun @ 2022-08-27 7:32 UTC (permalink / raw)
To: Michael Hennerich, Sebastian Reichel; +Cc: Wei Yongjun, linux-pm, linux-kernel
adp5061_get_battery_status() only defined show chg_status <= 4, others will
be show as '-1731902199' from /sys/class/power_supply/xx/capacity_level.
switch to show them as 'Unknown'.
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
drivers/power/supply/adp5061.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index daee1161c305..fcf8ff0bc974 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -493,6 +493,9 @@ static int adp5061_get_battery_status(struct adp5061_state *st,
case 0x4: /* VBAT_SNS > VWEAK */
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
break;
+ default:
+ val->intval = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
+ break;
}
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [PATCH -next 2/2] power: supply: adp5061: show unknown capacity_level as text
2022-08-27 7:32 ` [PATCH -next 2/2] power: supply: adp5061: show unknown capacity_level as text Wei Yongjun
@ 2022-09-05 11:46 ` Hennerich, Michael
0 siblings, 0 replies; 6+ messages in thread
From: Hennerich, Michael @ 2022-09-05 11:46 UTC (permalink / raw)
To: Wei Yongjun, Sebastian Reichel; +Cc: linux-pm, linux-kernel
> -----Original Message-----
> From: Wei Yongjun <weiyongjun1@huawei.com>
> Sent: Samstag, 27. August 2022 09:32
> To: Hennerich, Michael <Michael.Hennerich@analog.com>; Sebastian
> Reichel <sre@kernel.org>
> Cc: Wei Yongjun <weiyongjun1@huawei.com>; linux-pm@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: [PATCH -next 2/2] power: supply: adp5061: show unknown
> capacity_level as text
>
>
> adp5061_get_battery_status() only defined show chg_status <= 4, others will
> be show as '-1731902199' from /sys/class/power_supply/xx/capacity_level.
> switch to show them as 'Unknown'.
>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
> ---
> drivers/power/supply/adp5061.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/power/supply/adp5061.c
> b/drivers/power/supply/adp5061.c index daee1161c305..fcf8ff0bc974
> 100644
> --- a/drivers/power/supply/adp5061.c
> +++ b/drivers/power/supply/adp5061.c
> @@ -493,6 +493,9 @@ static int adp5061_get_battery_status(struct
> adp5061_state *st,
> case 0x4: /* VBAT_SNS > VWEAK */
> val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
> break;
> + default:
> + val->intval = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN;
> + break;
> }
>
> return ret;
> --
> 2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type()
2022-08-27 7:32 ` [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Wei Yongjun
@ 2022-09-05 11:46 ` Hennerich, Michael
0 siblings, 0 replies; 6+ messages in thread
From: Hennerich, Michael @ 2022-09-05 11:46 UTC (permalink / raw)
To: Wei Yongjun, Sebastian Reichel; +Cc: linux-pm, linux-kernel
> -----Original Message-----
> From: Wei Yongjun <weiyongjun1@huawei.com>
> Sent: Samstag, 27. August 2022 09:32
> To: Hennerich, Michael <Michael.Hennerich@analog.com>; Sebastian
> Reichel <sre@kernel.org>
> Cc: Wei Yongjun <weiyongjun1@huawei.com>; linux-pm@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in
> adp5061_get_chg_type()
>
>
> ADP5061_CHG_STATUS_1_CHG_STATUS is masked with 0x07, which means
> a length of 8, but adp5061_chg_type array size is 4, may end up reading 4
> elements beyond the end of the adp5061_chg_type[] array.
>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
> ---
> drivers/power/supply/adp5061.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/power/supply/adp5061.c
> b/drivers/power/supply/adp5061.c index 003557043ab3..daee1161c305
> 100644
> --- a/drivers/power/supply/adp5061.c
> +++ b/drivers/power/supply/adp5061.c
> @@ -427,11 +427,11 @@ static int adp5061_get_chg_type(struct
> adp5061_state *st,
> if (ret < 0)
> return ret;
>
> - chg_type =
> adp5061_chg_type[ADP5061_CHG_STATUS_1_CHG_STATUS(status1)];
> - if (chg_type > ADP5061_CHG_FAST_CV)
> + chg_type = ADP5061_CHG_STATUS_1_CHG_STATUS(status1);
> + if (chg_type >= ARRAY_SIZE(adp5061_chg_type))
> val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
> else
> - val->intval = chg_type;
> + val->intval = adp5061_chg_type[chg_type];
>
> return ret;
> }
> --
> 2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test
2022-08-27 7:32 [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Wei Yongjun
2022-08-27 7:32 ` [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Wei Yongjun
2022-08-27 7:32 ` [PATCH -next 2/2] power: supply: adp5061: show unknown capacity_level as text Wei Yongjun
@ 2022-09-11 12:19 ` Sebastian Reichel
2 siblings, 0 replies; 6+ messages in thread
From: Sebastian Reichel @ 2022-09-11 12:19 UTC (permalink / raw)
To: Wei Yongjun; +Cc: Michael Hennerich, linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 539 bytes --]
Hi,
On Sat, Aug 27, 2022 at 07:32:22AM +0000, Wei Yongjun wrote:
> This series fixes some issues found by device mockup unittest, not
> sure how about the real device.
>
> Wei Yongjun (2):
> power: supply: adp5061: fix out-of-bounds read in
> adp5061_get_chg_type()
> power: supply: adp5061: show unknown capacity_level as text
>
> drivers/power/supply/adp5061.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
Thanks, I queued both patches into power-supply's for-next branch.
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-09-12 10:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 7:32 [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Wei Yongjun
2022-08-27 7:32 ` [PATCH -next 1/2] power: supply: adp5061: fix out-of-bounds read in adp5061_get_chg_type() Wei Yongjun
2022-09-05 11:46 ` Hennerich, Michael
2022-08-27 7:32 ` [PATCH -next 2/2] power: supply: adp5061: show unknown capacity_level as text Wei Yongjun
2022-09-05 11:46 ` Hennerich, Michael
2022-09-11 12:19 ` [PATCH -next 0/2] power: supply: adp5061: some fixes from device mockup test Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).