power: add get/set empty-poll maximum API
[dpdk.git] / lib / power / power_pstate_cpufreq.c
index ba28ddc..f4c3617 100644 (file)
@@ -3,20 +3,14 @@
  */
 
 #include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
-#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <signal.h>
 #include <limits.h>
 #include <errno.h>
 #include <inttypes.h>
 
 #include <rte_memcpy.h>
-#include <rte_memory.h>
-#include <rte_string_fns.h>
 
 #include "power_pstate_cpufreq.h"
 #include "power_common.h"
@@ -419,6 +413,11 @@ power_get_available_freqs(struct pstate_power_info *pi)
         */
        num_freqs = (base_max_freq - sys_min_freq) / BUS_FREQ + 1 +
                pi->turbo_available;
+       if (num_freqs >= RTE_MAX_LCORE_FREQS) {
+               RTE_LOG(ERR, POWER, "Too many available frequencies: %d\n",
+                               num_freqs);
+               goto out;
+       }
 
        /* Generate the freq bucket array.
         * If turbo is available the freq bucket[0] value is base_max +1
@@ -440,8 +439,10 @@ power_get_available_freqs(struct pstate_power_info *pi)
                        num_freqs, pi->lcore_id);
 
 out:
-       fclose(f_min);
-       fclose(f_max);
+       if (f_min != NULL)
+               fclose(f_min);
+       if (f_max != NULL)
+               fclose(f_max);
 
        return ret;
 }