2023-05-30 11:47:34

by Yi-ming Tseng

[permalink] [raw]
Subject: [PATCH] PM: domains: fix overflow in genpd_parse_state

Add type casters to prevent 32-bit overflow before assigning to s64
variables. It allows full 32-bit range support for latency and
residency.

Signed-off-by: YiMing Tseng <[email protected]>
---
drivers/base/power/domain.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 32084e38b73d..26a04cd8d8dc 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2939,10 +2939,10 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state,

err = of_property_read_u32(state_node, "min-residency-us", &residency);
if (!err)
- genpd_state->residency_ns = 1000 * residency;
+ genpd_state->residency_ns = (s64)1000 * residency;

- genpd_state->power_on_latency_ns = 1000 * exit_latency;
- genpd_state->power_off_latency_ns = 1000 * entry_latency;
+ genpd_state->power_on_latency_ns = (s64)1000 * exit_latency;
+ genpd_state->power_off_latency_ns = (s64)1000 * entry_latency;
genpd_state->fwnode = &state_node->fwnode;

return 0;
--
2.41.0.rc0.172.g3f132b7071-goog



2023-06-16 18:26:29

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] PM: domains: fix overflow in genpd_parse_state

On Tue, May 30, 2023 at 1:42 PM YiMing Tseng <[email protected]> wrote:
>
> Add type casters to prevent 32-bit overflow before assigning to s64
> variables. It allows full 32-bit range support for latency and
> residency.

OK, but is it really a practical problem?

Ulf, what do you think?

> Signed-off-by: YiMing Tseng <[email protected]>
> ---
> drivers/base/power/domain.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 32084e38b73d..26a04cd8d8dc 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2939,10 +2939,10 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state,
>
> err = of_property_read_u32(state_node, "min-residency-us", &residency);
> if (!err)
> - genpd_state->residency_ns = 1000 * residency;
> + genpd_state->residency_ns = (s64)1000 * residency;
>
> - genpd_state->power_on_latency_ns = 1000 * exit_latency;
> - genpd_state->power_off_latency_ns = 1000 * entry_latency;
> + genpd_state->power_on_latency_ns = (s64)1000 * exit_latency;
> + genpd_state->power_off_latency_ns = (s64)1000 * entry_latency;
> genpd_state->fwnode = &state_node->fwnode;
>
> return 0;
> --

2023-06-21 08:56:29

by Yi-ming Tseng

[permalink] [raw]
Subject: Re: [PATCH] PM: domains: fix overflow in genpd_parse_state

Oh I just found there is a similar patch from Nikita Zhandarovich
and it will be applied in v6.5. I think we can drop this patch. Thanks
and sorry for duplicated patches.

The patch from Nikita Zhandarovich and the discussion:
https://lore.kernel.org/all/CAJZ5v0gx7bD9EZKPQWyAAZ6hSKjK4hr-nkrJu84HEK-g2AMAaw@mail.gmail.com/

Thanks again.

On Sat, Jun 17, 2023 at 1:44 AM Rafael J. Wysocki <[email protected]> wrote:
>
> On Tue, May 30, 2023 at 1:42 PM YiMing Tseng <[email protected]> wrote:
> >
> > Add type casters to prevent 32-bit overflow before assigning to s64
> > variables. It allows full 32-bit range support for latency and
> > residency.
>
> OK, but is it really a practical problem?
>
> Ulf, what do you think?
>
> > Signed-off-by: YiMing Tseng <[email protected]>
> > ---
> > drivers/base/power/domain.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> > index 32084e38b73d..26a04cd8d8dc 100644
> > --- a/drivers/base/power/domain.c
> > +++ b/drivers/base/power/domain.c
> > @@ -2939,10 +2939,10 @@ static int genpd_parse_state(struct genpd_power_state *genpd_state,
> >
> > err = of_property_read_u32(state_node, "min-residency-us", &residency);
> > if (!err)
> > - genpd_state->residency_ns = 1000 * residency;
> > + genpd_state->residency_ns = (s64)1000 * residency;
> >
> > - genpd_state->power_on_latency_ns = 1000 * exit_latency;
> > - genpd_state->power_off_latency_ns = 1000 * entry_latency;
> > + genpd_state->power_on_latency_ns = (s64)1000 * exit_latency;
> > + genpd_state->power_off_latency_ns = (s64)1000 * entry_latency;
> > genpd_state->fwnode = &state_node->fwnode;
> >
> > return 0;
> > --