PM / Domains: Fix integer overflows on u32 bit multiplies
Subsystems (5)
PATCH 1/1 PM / Domains: Fix integer overflows on u32 bit multiplies
From: Colin Ian King <[email protected]>
There are three occurrances of u32 variables being multiplied by 1000 using 32 bit multiplies and the result being assigned to a 64 bit signed integer. These can potentially lead to a 32 bit overflows, so fix this by casting 1000 to a UL first to force a 64 bit multiply hence avoiding the overflow.
Addresses-Coverity: ("Unintentional integer overflow")
--- drivers/base/power/domain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/base/power/domain.c +3 -3
@@ -2831,10 +2831,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 =1000UL * 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 =1000UL * exit_latency; + genpd_state->power_off_latency_ns =1000UL * entry_latency; genpd_state->fwnode = &state_node->fwnode;return 0 ;
Signature · 1 line
2.29.2
Quoted 7 lines · Colin King
From: Colin Ian King <[email protected]>
There are three occurrances of u32 variables being multiplied by 1000 using 32 bit multiplies and the result being assigned to a 64 bit signed integer. These can potentially lead to a 32 bit overflows, so fix this by casting 1000 to a UL first to force a 64 bit multiply hence avoiding the overflow.
Ummm. No?
a) Can you imagine any situation where they result in overflow?
b) How does casting to UL help on 32 bit system?
Best regards,
Pavel
Quoted 25 lines
Addresses-Coverity: ("Unintentional integer overflow")
Fixes 30f604283e05 ("PM / Domains: Allow domain power states to be read from DT")Signed-off-by Colin Ian King <[email protected]>--- drivers/base/power/domain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/base/power/domain.c +3
-3@@ -2831,10 +2831,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 =1000UL * 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 =1000UL * exit_latency; + genpd_state->power_off_latency_ns =1000UL * entry_latency; genpd_state->fwnode = &state_node->fwnode;return 0 ;
Signature · 1 line
http://www.livejournal.com/~pavelmachek
Rafael J. Wysocki
maintainerQuoted 21 lines · Colin King
From: Colin Ian King <[email protected]>
There are three occurrances of u32 variables being multiplied by 1000 using 32 bit multiplies and the result being assigned to a 64 bit signed integer. These can potentially lead to a 32 bit overflows, so fix this by casting 1000 to a UL first to force a 64 bit multiply hence avoiding the overflow.
Addresses-Coverity: ("Unintentional integer overflow")
Fixes 30f604283e05 ("PM / Domains: Allow domain power states to be read from DT")Signed-off-by Colin Ian King <[email protected]>--- drivers/base/power/domain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/base/power/domain.c +0
-0
drivers/base/power/domain.c static int genpd_parse_state(struct genpd_power_state *genpd_state, · line 2834
Quoted 5 lines
drivers/base/power/domain.c +1
-1@@ -2831,10 +2831,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 =1000UL * residency;
Wouldn't it be better to use NSEC_PER_USEC here and below?
Quoted 11 lines
drivers/base/power/domain.c +2
-3- genpd_state->power_on_latency_ns =1000 * exit_latency; - genpd_state->power_off_latency_ns =1000 * entry_latency; + genpd_state->power_on_latency_ns =1000UL * exit_latency; + genpd_state->power_off_latency_ns =1000UL * entry_latency; genpd_state->fwnode = &state_node->fwnode;return 0 ; --2.29.2