[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120823171155.5d9dc482@cuia.bos.redhat.com>
Date: Thu, 23 Aug 2012 17:11:55 -0400
From: Rik van Riel <riel@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: "Rafael J. Wysocki" <rjw@...k.pl>, ShuoX Liu <shuox.liu@...el.com>,
mjg59@...f.ucam.org, Boris Ostrovsky <boris.ostrovsky@....com>,
Len Brown <len.brown@...el.com>,
Deepthi Dharwar <deepthi@...ux.vnet.ibm.com>,
Arjan van de Ven <arjan@...ux.intel.com>
Subject: [RFC][PATCH 1/3] cpuidle: fix underflow in stddev calculation
The calculation to determine the standard deviation used unsigned
integers. Since some of the values are guaranteed to be below the
average, this would always lead to large unsigned 32 bit numbers,
which would then be multiplied and added to a 64 bit integer,
potentially leading to a totally unpredictable result.
I am not sure if/why this code has ever worked.
Signed-off-by: Rik van Riel <riel@...hat.com>
---
drivers/cpuidle/governors/menu.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 5b1f2c3..f4fe5c3 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -212,9 +212,10 @@ static void detect_repeating_patterns(struct menu_device *data)
if (avg > data->expected_us)
return;
- for (i = 0; i < INTERVALS; i++)
- stddev += (data->intervals[i] - avg) *
- (data->intervals[i] - avg);
+ for (i = 0; i < INTERVALS; i++) {
+ int diff = (int)data->intervals[i] - avg;
+ stddev += diff * diff;
+ }
stddev = stddev / INTERVALS;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists