cpufreq: Rewrite __check_freq_deviation() function

Add the check to make sure that the array that stores
frequency results is not empty before computing
deviations.

If the array is empty, return 1.

Signed-off-by: Lisa Nguyen <lisa.nguyen@linaro.org>
diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh
index b86db34..b323dc8 100755
--- a/cpufreq/cpufreq_06.sh
+++ b/cpufreq/cpufreq_06.sh
@@ -59,20 +59,23 @@
 }
 
 __check_freq_deviation() {
-
     res=$(eval echo \$$freq_results_array$index)
 
-    # compute deviation
-    dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}')
+    if [ ! -z "$res" ]; then
+        # compute deviation
+        dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}')
 
-    # change to absolute
-    dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
+        # change to absolute
+        dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
 
-    index=$((index + 1))
+        index=$((index + 1))
+        res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}')
 
-    res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}')
-    if [ "$res" = "1" ]; then
-	return 1
+        if [ "$res" = "1" ]; then
+            return 1
+        fi
+    else
+        return 1
     fi
 
     return 0