* re: thermal: introduce the Power Allocator governor
@ 2015-11-21 10:42 Dan Carpenter
2015-11-23 11:23 ` [PATCH] thermal: power_allocator: req_range multiplication should be a 64 bit type Javi Merino
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2015-11-21 10:42 UTC (permalink / raw)
To: javi.merino; +Cc: linux-pm
Hello Javi Merino,
The patch 6b775e870c56: "thermal: introduce the Power Allocator
governor" from Mar 2, 2015, leads to the following static checker
warning:
drivers/thermal/power_allocator.c:304 divvy_up_power()
warn: should 'req_power[i] * power_range' be a 64 bit type?
drivers/thermal/power_allocator.c
288 static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
289 u32 total_req_power, u32 power_range,
290 u32 *granted_power, u32 *extra_actor_power)
291 {
292 u32 extra_power, capped_extra_power;
293 int i;
294
295 /*
296 * Prevent division by 0 if none of the actors request power.
297 */
298 if (!total_req_power)
299 total_req_power = 1;
300
301 capped_extra_power = 0;
302 extra_power = 0;
303 for (i = 0; i < num_actors; i++) {
304 u64 req_range = req_power[i] * power_range;
Both req_power[i] and power_range are u32 so the high bits of req_range
are not used.
305
306 granted_power[i] = DIV_ROUND_CLOSEST_ULL(req_range,
307 total_req_power);
308
309 if (granted_power[i] > max_power[i]) {
310 extra_power += granted_power[i] - max_power[i];
311 granted_power[i] = max_power[i];
312 }
313
314 extra_actor_power[i] = max_power[i] - granted_power[i];
315 capped_extra_power += extra_actor_power[i];
316 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] thermal: power_allocator: req_range multiplication should be a 64 bit type
2015-11-21 10:42 thermal: introduce the Power Allocator governor Dan Carpenter
@ 2015-11-23 11:23 ` Javi Merino
0 siblings, 0 replies; 2+ messages in thread
From: Javi Merino @ 2015-11-23 11:23 UTC (permalink / raw)
To: linux-pm; +Cc: dan.carpenter, edubezval, Javi Merino, Zhang Rui
req_range is declared as a u64 to cope with overflows in the
multiplication of two u32. As both req_power and power_range are u32,
we need to make sure the multiplication is done with u64 types.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
drivers/thermal/power_allocator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allocator.c
index f0fbea386869..a58ae2e1f3cd 100644
--- a/drivers/thermal/power_allocator.c
+++ b/drivers/thermal/power_allocator.c
@@ -303,7 +303,7 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
capped_extra_power = 0;
extra_power = 0;
for (i = 0; i < num_actors; i++) {
- u64 req_range = req_power[i] * power_range;
+ u64 req_range = (u64)req_power[i] * power_range;
granted_power[i] = DIV_ROUND_CLOSEST_ULL(req_range,
total_req_power);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-23 11:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-21 10:42 thermal: introduce the Power Allocator governor Dan Carpenter
2015-11-23 11:23 ` [PATCH] thermal: power_allocator: req_range multiplication should be a 64 bit type Javi Merino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox