···4242 return sysfs_get_freq_hardware_limits(cpu, min, max);4343}44444545-char * cpufreq_get_driver(unsigned int cpu) {4545+char *cpufreq_get_driver(unsigned int cpu)4646+{4647 return sysfs_get_freq_driver(cpu);4748}48494949-void cpufreq_put_driver(char * ptr) {5050+void cpufreq_put_driver(char *ptr)5151+{5052 if (!ptr)5153 return;5254 free(ptr);5355}54565555-struct cpufreq_policy * cpufreq_get_policy(unsigned int cpu) {5757+struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu)5858+{5659 return sysfs_get_freq_policy(cpu);5760}58615959-void cpufreq_put_policy(struct cpufreq_policy *policy) {6262+void cpufreq_put_policy(struct cpufreq_policy *policy)6363+{6064 if ((!policy) || (!policy->governor))6165 return;6266···6965 free(policy);7066}71677272-struct cpufreq_available_governors * cpufreq_get_available_governors(unsigned int cpu) {6868+struct cpufreq_available_governors *cpufreq_get_available_governors(unsigned6969+ int cpu)7070+{7371 return sysfs_get_freq_available_governors(cpu);7472}75737676-void cpufreq_put_available_governors(struct cpufreq_available_governors *any) {7474+void cpufreq_put_available_governors(struct cpufreq_available_governors *any)7575+{7776 struct cpufreq_available_governors *tmp, *next;78777978 if (!any)···9386}948795889696-struct cpufreq_available_frequencies * cpufreq_get_available_frequencies(unsigned int cpu) {8989+struct cpufreq_available_frequencies9090+*cpufreq_get_available_frequencies(unsigned int cpu)9191+{9792 return sysfs_get_available_frequencies(cpu);9893}9994100100-void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *any) {9595+void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies9696+ *any) {10197 struct cpufreq_available_frequencies *tmp, *next;1029810399 if (!any)···115105}116106117107118118-struct cpufreq_affected_cpus * cpufreq_get_affected_cpus(unsigned int cpu) {108108+struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned int cpu)109109+{119110 return sysfs_get_freq_affected_cpus(cpu);120111}121112122122-void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any) {113113+void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any)114114+{123115 struct cpufreq_affected_cpus *tmp, *next;124116125117 if (!any)···136124}137125138126139139-struct cpufreq_affected_cpus * cpufreq_get_related_cpus(unsigned int cpu) {127127+struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned int cpu)128128+{140129 return sysfs_get_freq_related_cpus(cpu);141130}142131143143-void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *any) {132132+void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *any)133133+{144134 cpufreq_put_affected_cpus(any);145135}146136147137148148-int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy) {138138+int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy)139139+{149140 if (!policy || !(policy->governor))150141 return -EINVAL;151142···156141}157142158143159159-int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq) {144144+int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq)145145+{160146 return sysfs_modify_freq_policy_min(cpu, min_freq);161147}162148163149164164-int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq) {150150+int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq)151151+{165152 return sysfs_modify_freq_policy_max(cpu, max_freq);166153}167154168155169169-int cpufreq_modify_policy_governor(unsigned int cpu, char *governor) {156156+int cpufreq_modify_policy_governor(unsigned int cpu, char *governor)157157+{170158 if ((!governor) || (strlen(governor) > 19))171159 return -EINVAL;172160173161 return sysfs_modify_freq_policy_governor(cpu, governor);174162}175163176176-int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency) {164164+int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency)165165+{177166 return sysfs_set_frequency(cpu, target_frequency);178167}179168180180-struct cpufreq_stats * cpufreq_get_stats(unsigned int cpu, unsigned long long *total_time) {181181- struct cpufreq_stats *ret;182182-183183- ret = sysfs_get_freq_stats(cpu, total_time);184184- return (ret);169169+struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,170170+ unsigned long long *total_time)171171+{172172+ return sysfs_get_freq_stats(cpu, total_time);185173}186174187187-void cpufreq_put_stats(struct cpufreq_stats *any) {175175+void cpufreq_put_stats(struct cpufreq_stats *any)176176+{188177 struct cpufreq_stats *tmp, *next;189178190179 if (!any)···202183 }203184}204185205205-unsigned long cpufreq_get_transitions(unsigned int cpu) {206206- unsigned long ret = sysfs_get_freq_transitions(cpu);207207-208208- return (ret);186186+unsigned long cpufreq_get_transitions(unsigned int cpu)187187+{188188+ return sysfs_get_freq_transitions(cpu);209189}
+31-23
tools/power/cpupower/lib/cpufreq.h
···9393 * considerations by cpufreq policy notifiers in the kernel.9494 */95959696-extern int cpufreq_get_hardware_limits(unsigned int cpu, 9797- unsigned long *min, 9898- unsigned long *max);9696+extern int cpufreq_get_hardware_limits(unsigned int cpu,9797+ unsigned long *min,9898+ unsigned long *max);9999100100101101/* determine CPUfreq driver used···104104 * to avoid memory leakage, please.105105 */106106107107-extern char * cpufreq_get_driver(unsigned int cpu);107107+extern char *cpufreq_get_driver(unsigned int cpu);108108109109-extern void cpufreq_put_driver(char * ptr);109109+extern void cpufreq_put_driver(char *ptr);110110111111112112/* determine CPUfreq policy currently used···116116 */117117118118119119-extern struct cpufreq_policy * cpufreq_get_policy(unsigned int cpu);119119+extern struct cpufreq_policy *cpufreq_get_policy(unsigned int cpu);120120121121extern void cpufreq_put_policy(struct cpufreq_policy *policy);122122···129129 */130130131131132132-extern struct cpufreq_available_governors * cpufreq_get_available_governors(unsigned int cpu);132132+extern struct cpufreq_available_governors133133+*cpufreq_get_available_governors(unsigned int cpu);133134134134-extern void cpufreq_put_available_governors(struct cpufreq_available_governors *first);135135+extern void cpufreq_put_available_governors(136136+ struct cpufreq_available_governors *first);135137136138137139/* determine CPU frequency states available138140 *139139- * only present on _some_ ->target() cpufreq drivers. For information purposes140140- * only. Please free allocated memory by calling cpufreq_put_available_frequencies141141- * after use.141141+ * Only present on _some_ ->target() cpufreq drivers. For information purposes142142+ * only. Please free allocated memory by calling143143+ * cpufreq_put_available_frequencies after use.142144 */143145144144-extern struct cpufreq_available_frequencies * cpufreq_get_available_frequencies(unsigned int cpu);146146+extern struct cpufreq_available_frequencies147147+*cpufreq_get_available_frequencies(unsigned int cpu);145148146146-extern void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *first);149149+extern void cpufreq_put_available_frequencies(150150+ struct cpufreq_available_frequencies *first);147151148152149149-/* determine affected CPUs 153153+/* determine affected CPUs150154 *151155 * Remember to call cpufreq_put_affected_cpus when no longer needed152156 * to avoid memory leakage, please.153157 */154158155155-extern struct cpufreq_affected_cpus * cpufreq_get_affected_cpus(unsigned int cpu);159159+extern struct cpufreq_affected_cpus *cpufreq_get_affected_cpus(unsigned160160+ int cpu);156161157162extern void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *first);158163159164160160-/* determine related CPUs 165165+/* determine related CPUs161166 *162167 * Remember to call cpufreq_put_related_cpus when no longer needed163168 * to avoid memory leakage, please.164169 */165170166166-extern struct cpufreq_affected_cpus * cpufreq_get_related_cpus(unsigned int cpu);171171+extern struct cpufreq_affected_cpus *cpufreq_get_related_cpus(unsigned172172+ int cpu);167173168174extern void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *first);169175···179173 * This is not available in all kernel versions or configurations.180174 */181175182182-extern struct cpufreq_stats * cpufreq_get_stats(unsigned int cpu, unsigned long long *total_time);176176+extern struct cpufreq_stats *cpufreq_get_stats(unsigned int cpu,177177+ unsigned long long *total_time);183178184179extern void cpufreq_put_stats(struct cpufreq_stats *stats);185180186181extern unsigned long cpufreq_get_transitions(unsigned int cpu);187182188183189189-/* set new cpufreq policy 190190- * 184184+/* set new cpufreq policy185185+ *191186 * Tries to set the passed policy as new policy as close as possible,192187 * but results may differ depending e.g. on governors being available.193188 */···196189extern int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy);197190198191199199-/* modify a policy by only changing min/max freq or governor 192192+/* modify a policy by only changing min/max freq or governor200193 *201194 * Does not check whether result is what was intended.202195 */···209202/* set a specific frequency210203 *211204 * Does only work if userspace governor can be used and no external212212- * interference (other calls to this function or to set/modify_policy) 205205+ * interference (other calls to this function or to set/modify_policy)213206 * occurs. Also does not work on ->range() cpufreq drivers.214207 */215208216216-extern int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency);209209+extern int cpufreq_set_frequency(unsigned int cpu,210210+ unsigned long target_frequency);217211218212#ifdef __cplusplus219213}
+160-159
tools/power/cpupower/lib/sysfs.c
···2424static unsigned int sysfs_read_file(const char *path, char *buf, size_t buflen)2525{2626 int fd;2727- size_t numread;2727+ ssize_t numread;28282929- if ( ( fd = open(path, O_RDONLY) ) == -1 )2929+ fd = open(path, O_RDONLY);3030+ if (fd == -1)3031 return 0;31323233 numread = read(fd, buf, buflen - 1);3333- if ( numread < 1 )3434- {3434+ if (numread < 1) {3535 close(fd);3636 return 0;3737 }···3939 buf[numread] = '\0';4040 close(fd);41414242- return numread;4242+ return (unsigned int) numread;4343}44444545···6565{6666 char path[SYSFS_PATH_MAX];6767 int fd;6868- size_t numwrite;6868+ ssize_t numwrite;69697070 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpufreq/%s",7171 cpu, fname);72727373- if ( ( fd = open(path, O_WRONLY) ) == -1 )7373+ fd = open(path, O_WRONLY);7474+ if (fd == -1)7475 return 0;75767677 numwrite = write(fd, value, len);7777- if ( numwrite < 1 )7878- {7878+ if (numwrite < 1) {7979 close(fd);8080 return 0;8181 }82828383 close(fd);84848585- return numwrite;8585+ return (unsigned int) numwrite;8686}87878888/* read access to files which contain one numeric value */···114114static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,115115 enum cpufreq_value which)116116{117117- unsigned long value;117117+ unsigned long value;118118 unsigned int len;119119 char linebuf[MAX_LINE_LEN];120120 char *endp;121121122122- if ( which >= MAX_CPUFREQ_VALUE_READ_FILES )122122+ if (which >= MAX_CPUFREQ_VALUE_READ_FILES)123123 return 0;124124125125- if ( ( len = sysfs_cpufreq_read_file(cpu, cpufreq_value_files[which],126126- linebuf, sizeof(linebuf))) == 0 )125125+ len = sysfs_cpufreq_read_file(cpu, cpufreq_value_files[which],126126+ linebuf, sizeof(linebuf));127127+128128+ if (len == 0)127129 return 0;128130129131 value = strtoul(linebuf, &endp, 0);130132131131- if ( endp == linebuf || errno == ERANGE )133133+ if (endp == linebuf || errno == ERANGE)132134 return 0;133135134136 return value;···150148};151149152150153153-static char * sysfs_cpufreq_get_one_string(unsigned int cpu,151151+static char *sysfs_cpufreq_get_one_string(unsigned int cpu,154152 enum cpufreq_string which)155153{156154 char linebuf[MAX_LINE_LEN];···160158 if (which >= MAX_CPUFREQ_STRING_FILES)161159 return NULL;162160163163- if ( ( len = sysfs_cpufreq_read_file(cpu, cpufreq_string_files[which],164164- linebuf, sizeof(linebuf))) == 0 )161161+ len = sysfs_cpufreq_read_file(cpu, cpufreq_string_files[which],162162+ linebuf, sizeof(linebuf));163163+ if (len == 0)165164 return NULL;166165167167- if ( ( result = strdup(linebuf) ) == NULL )166166+ result = strdup(linebuf);167167+ if (result == NULL)168168 return NULL;169169170170 if (result[strlen(result) - 1] == '\n')···199195 if (which >= MAX_CPUFREQ_WRITE_FILES)200196 return 0;201197202202- if ( sysfs_cpufreq_write_file(cpu, cpufreq_write_files[which],203203- new_value, len) != len )198198+ if (sysfs_cpufreq_write_file(cpu, cpufreq_write_files[which],199199+ new_value, len) != len)204200 return -ENODEV;205201206202 return 0;···239235 return 0;240236}241237242242-char * sysfs_get_freq_driver(unsigned int cpu) {238238+char *sysfs_get_freq_driver(unsigned int cpu)239239+{243240 return sysfs_cpufreq_get_one_string(cpu, SCALING_DRIVER);244241}245242246246-struct cpufreq_policy * sysfs_get_freq_policy(unsigned int cpu) {243243+struct cpufreq_policy *sysfs_get_freq_policy(unsigned int cpu)244244+{247245 struct cpufreq_policy *policy;248246249247 policy = malloc(sizeof(struct cpufreq_policy));···276270 unsigned int pos, i;277271 unsigned int len;278272279279- if ( ( len = sysfs_cpufreq_read_file(cpu, "scaling_available_governors",280280- linebuf, sizeof(linebuf))) == 0 )281281- {273273+ len = sysfs_cpufreq_read_file(cpu, "scaling_available_governors",274274+ linebuf, sizeof(linebuf));275275+ if (len == 0)282276 return NULL;283283- }284277285278 pos = 0;286286- for ( i = 0; i < len; i++ )287287- {288288- if ( linebuf[i] == ' ' || linebuf[i] == '\n' )289289- {290290- if ( i - pos < 2 )279279+ for (i = 0; i < len; i++) {280280+ if (linebuf[i] == ' ' || linebuf[i] == '\n') {281281+ if (i - pos < 2)291282 continue;292292- if ( current ) {293293- current->next = malloc(sizeof *current );294294- if ( ! current->next )283283+ if (current) {284284+ current->next = malloc(sizeof(*current));285285+ if (!current->next)295286 goto error_out;296287 current = current->next;297288 } else {298298- first = malloc( sizeof *first );299299- if ( ! first )289289+ first = malloc(sizeof(*first));290290+ if (!first)300291 goto error_out;301292 current = first;302293 }···301298 current->next = NULL;302299303300 current->governor = malloc(i - pos + 1);304304- if ( ! current->governor )301301+ if (!current->governor)305302 goto error_out;306303307307- memcpy( current->governor, linebuf + pos, i - pos);304304+ memcpy(current->governor, linebuf + pos, i - pos);308305 current->governor[i - pos] = '\0';309306 pos = i + 1;310307 }···313310 return first;314311315312 error_out:316316- while ( first ) {313313+ while (first) {317314 current = first->next;318318- if ( first->governor )319319- free( first->governor );320320- free( first );315315+ if (first->governor)316316+ free(first->governor);317317+ free(first);321318 first = current;322319 }323320 return NULL;···333330 unsigned int pos, i;334331 unsigned int len;335332336336- if ( ( len = sysfs_cpufreq_read_file(cpu,337337- "scaling_available_frequencies",338338- linebuf, sizeof(linebuf))) == 0 )339339- {333333+ len = sysfs_cpufreq_read_file(cpu, "scaling_available_frequencies",334334+ linebuf, sizeof(linebuf));335335+ if (len == 0)340336 return NULL;341341- }342337343338 pos = 0;344344- for ( i = 0; i < len; i++ )345345- {346346- if ( linebuf[i] == ' ' || linebuf[i] == '\n' )347347- {348348- if ( i - pos < 2 )339339+ for (i = 0; i < len; i++) {340340+ if (linebuf[i] == ' ' || linebuf[i] == '\n') {341341+ if (i - pos < 2)349342 continue;350350- if ( i - pos >= SYSFS_PATH_MAX )343343+ if (i - pos >= SYSFS_PATH_MAX)351344 goto error_out;352352- if ( current ) {353353- current->next = malloc(sizeof *current );354354- if ( ! current->next )345345+ if (current) {346346+ current->next = malloc(sizeof(*current));347347+ if (!current->next)355348 goto error_out;356349 current = current->next;357350 } else {358358- first = malloc(sizeof *first );359359- if ( ! first )351351+ first = malloc(sizeof(*first));352352+ if (!first)360353 goto error_out;361354 current = first;362355 }···361362362363 memcpy(one_value, linebuf + pos, i - pos);363364 one_value[i - pos] = '\0';364364- if ( sscanf(one_value, "%lu", ¤t->frequency) != 1 )365365- goto error_out;366366-367367- pos = i + 1;368368- }369369- }370370-371371- return first;372372-373373- error_out:374374- while ( first ) {375375- current = first->next;376376- free(first);377377- first = current;378378- }379379- return NULL;380380-}381381-382382-static struct cpufreq_affected_cpus * sysfs_get_cpu_list(unsigned int cpu,383383- const char *file) {384384- struct cpufreq_affected_cpus *first = NULL;385385- struct cpufreq_affected_cpus *current = NULL;386386- char one_value[SYSFS_PATH_MAX];387387- char linebuf[MAX_LINE_LEN];388388- unsigned int pos, i;389389- unsigned int len;390390-391391- if ( ( len = sysfs_cpufreq_read_file(cpu, file, linebuf,392392- sizeof(linebuf))) == 0 )393393- {394394- return NULL;395395- }396396-397397- pos = 0;398398- for ( i = 0; i < len; i++ )399399- {400400- if ( i == len || linebuf[i] == ' ' || linebuf[i] == '\n' )401401- {402402- if ( i - pos < 1 )403403- continue;404404- if ( i - pos >= SYSFS_PATH_MAX )405405- goto error_out;406406- if ( current ) {407407- current->next = malloc(sizeof *current);408408- if ( ! current->next )409409- goto error_out;410410- current = current->next;411411- } else {412412- first = malloc(sizeof *first);413413- if ( ! first )414414- goto error_out;415415- current = first;416416- }417417- current->first = first;418418- current->next = NULL;419419-420420- memcpy(one_value, linebuf + pos, i - pos);421421- one_value[i - pos] = '\0';422422-423423- if ( sscanf(one_value, "%u", ¤t->cpu) != 1 )365365+ if (sscanf(one_value, "%lu", ¤t->frequency) != 1)424366 goto error_out;425367426368 pos = i + 1;···379439 return NULL;380440}381441382382-struct cpufreq_affected_cpus * sysfs_get_freq_affected_cpus(unsigned int cpu) {383383- return sysfs_get_cpu_list(cpu, "affected_cpus");384384-}385385-386386-struct cpufreq_affected_cpus * sysfs_get_freq_related_cpus(unsigned int cpu) {387387- return sysfs_get_cpu_list(cpu, "related_cpus");388388-}389389-390390-struct cpufreq_stats * sysfs_get_freq_stats(unsigned int cpu, unsigned long long *total_time) {391391- struct cpufreq_stats *first = NULL;392392- struct cpufreq_stats *current = NULL;442442+static struct cpufreq_affected_cpus *sysfs_get_cpu_list(unsigned int cpu,443443+ const char *file)444444+{445445+ struct cpufreq_affected_cpus *first = NULL;446446+ struct cpufreq_affected_cpus *current = NULL;393447 char one_value[SYSFS_PATH_MAX];394448 char linebuf[MAX_LINE_LEN];395449 unsigned int pos, i;396450 unsigned int len;397451398398- if ( ( len = sysfs_cpufreq_read_file(cpu, "stats/time_in_state",399399- linebuf, sizeof(linebuf))) == 0 )452452+ len = sysfs_cpufreq_read_file(cpu, file, linebuf, sizeof(linebuf));453453+ if (len == 0)400454 return NULL;401455402402- *total_time = 0;403456 pos = 0;404404- for ( i = 0; i < len; i++ )405405- {406406- if ( i == strlen(linebuf) || linebuf[i] == '\n' )407407- {408408- if ( i - pos < 2 )457457+ for (i = 0; i < len; i++) {458458+ if (i == len || linebuf[i] == ' ' || linebuf[i] == '\n') {459459+ if (i - pos < 1)409460 continue;410410- if ( (i - pos) >= SYSFS_PATH_MAX )461461+ if (i - pos >= SYSFS_PATH_MAX)411462 goto error_out;412412- if ( current ) {413413- current->next = malloc(sizeof *current );414414- if ( ! current->next )463463+ if (current) {464464+ current->next = malloc(sizeof(*current));465465+ if (!current->next)415466 goto error_out;416467 current = current->next;417468 } else {418418- first = malloc(sizeof *first );419419- if ( ! first )469469+ first = malloc(sizeof(*first));470470+ if (!first)420471 goto error_out;421472 current = first;422473 }···416485417486 memcpy(one_value, linebuf + pos, i - pos);418487 one_value[i - pos] = '\0';419419- if ( sscanf(one_value, "%lu %llu", ¤t->frequency, ¤t->time_in_state) != 2 )488488+489489+ if (sscanf(one_value, "%u", ¤t->cpu) != 1)490490+ goto error_out;491491+492492+ pos = i + 1;493493+ }494494+ }495495+496496+ return first;497497+498498+ error_out:499499+ while (first) {500500+ current = first->next;501501+ free(first);502502+ first = current;503503+ }504504+ return NULL;505505+}506506+507507+struct cpufreq_affected_cpus *sysfs_get_freq_affected_cpus(unsigned int cpu)508508+{509509+ return sysfs_get_cpu_list(cpu, "affected_cpus");510510+}511511+512512+struct cpufreq_affected_cpus *sysfs_get_freq_related_cpus(unsigned int cpu)513513+{514514+ return sysfs_get_cpu_list(cpu, "related_cpus");515515+}516516+517517+struct cpufreq_stats *sysfs_get_freq_stats(unsigned int cpu,518518+ unsigned long long *total_time) {519519+ struct cpufreq_stats *first = NULL;520520+ struct cpufreq_stats *current = NULL;521521+ char one_value[SYSFS_PATH_MAX];522522+ char linebuf[MAX_LINE_LEN];523523+ unsigned int pos, i;524524+ unsigned int len;525525+526526+ len = sysfs_cpufreq_read_file(cpu, "stats/time_in_state",527527+ linebuf, sizeof(linebuf));528528+ if (len == 0)529529+ return NULL;530530+531531+ *total_time = 0;532532+ pos = 0;533533+ for (i = 0; i < len; i++) {534534+ if (i == strlen(linebuf) || linebuf[i] == '\n') {535535+ if (i - pos < 2)536536+ continue;537537+ if ((i - pos) >= SYSFS_PATH_MAX)538538+ goto error_out;539539+ if (current) {540540+ current->next = malloc(sizeof(*current));541541+ if (!current->next)542542+ goto error_out;543543+ current = current->next;544544+ } else {545545+ first = malloc(sizeof(*first));546546+ if (!first)547547+ goto error_out;548548+ current = first;549549+ }550550+ current->first = first;551551+ current->next = NULL;552552+553553+ memcpy(one_value, linebuf + pos, i - pos);554554+ one_value[i - pos] = '\0';555555+ if (sscanf(one_value, "%lu %llu",556556+ ¤t->frequency,557557+ ¤t->time_in_state) != 2)420558 goto error_out;421559422560 *total_time = *total_time + current->time_in_state;···496496 return first;497497498498 error_out:499499- while ( first ) {499499+ while (first) {500500 current = first->next;501501 free(first);502502 first = current;···511511512512static int verify_gov(char *new_gov, char *passed_gov)513513{514514- unsigned int i, j=0;514514+ unsigned int i, j = 0;515515516516 if (!passed_gov || (strlen(passed_gov) > 19))517517 return -EINVAL;518518519519 strncpy(new_gov, passed_gov, 20);520520- for (i=0;i<20;i++) {520520+ for (i = 0; i < 20; i++) {521521 if (j) {522522 new_gov[i] = '\0';523523 continue;524524 }525525- if ((new_gov[i] >= 'a') && (new_gov[i] <= 'z')) {525525+ if ((new_gov[i] >= 'a') && (new_gov[i] <= 'z'))526526 continue;527527- }528528- if ((new_gov[i] >= 'A') && (new_gov[i] <= 'Z')) {527527+528528+ if ((new_gov[i] >= 'A') && (new_gov[i] <= 'Z'))529529 continue;530530- }531531- if (new_gov[i] == '-') {530530+531531+ if (new_gov[i] == '-')532532 continue;533533- }534534- if (new_gov[i] == '_') {533533+534534+ if (new_gov[i] == '_')535535 continue;536536- }536536+537537 if (new_gov[i] == '\0') {538538 j = 1;539539 continue;···627627 gov, strlen(gov));628628}629629630630-int sysfs_set_frequency(unsigned int cpu, unsigned long target_frequency) {630630+int sysfs_set_frequency(unsigned int cpu, unsigned long target_frequency)631631+{631632 struct cpufreq_policy *pol = sysfs_get_freq_policy(cpu);632633 char userspace_gov[] = "userspace";633634 char freq[SYSFS_PATH_MAX];···641640 ret = sysfs_modify_freq_policy_governor(cpu, userspace_gov);642641 if (ret) {643642 cpufreq_put_policy(pol);644644- return (ret);643643+ return ret;645644 }646645 }647646···663662664663 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/", cpu);665664666666- if ( stat(file, &statbuf) != 0 )665665+ if (stat(file, &statbuf) != 0)667666 return -ENOSYS;668667669668 return S_ISDIR(statbuf.st_mode) ? 0 : -ENOSYS;
+22-12
tools/power/cpupower/lib/sysfs.h
···55extern unsigned long sysfs_get_freq_kernel(unsigned int cpu);66extern unsigned long sysfs_get_freq_hardware(unsigned int cpu);77extern unsigned long sysfs_get_freq_transition_latency(unsigned int cpu);88-extern int sysfs_get_freq_hardware_limits(unsigned int cpu, unsigned long *min, unsigned long *max);99-extern char * sysfs_get_freq_driver(unsigned int cpu);1010-extern struct cpufreq_policy * sysfs_get_freq_policy(unsigned int cpu);1111-extern struct cpufreq_available_governors * sysfs_get_freq_available_governors(unsigned int cpu);1212-extern struct cpufreq_available_frequencies * sysfs_get_available_frequencies(unsigned int cpu);1313-extern struct cpufreq_affected_cpus * sysfs_get_freq_affected_cpus(unsigned int cpu);1414-extern struct cpufreq_affected_cpus * sysfs_get_freq_related_cpus(unsigned int cpu);1515-extern struct cpufreq_stats * sysfs_get_freq_stats(unsigned int cpu, unsigned long long *total_time);88+extern int sysfs_get_freq_hardware_limits(unsigned int cpu,99+ unsigned long *min, unsigned long *max);1010+extern char *sysfs_get_freq_driver(unsigned int cpu);1111+extern struct cpufreq_policy *sysfs_get_freq_policy(unsigned int cpu);1212+extern struct cpufreq_available_governors *sysfs_get_freq_available_governors(1313+ unsigned int cpu);1414+extern struct cpufreq_available_frequencies *sysfs_get_available_frequencies(1515+ unsigned int cpu);1616+extern struct cpufreq_affected_cpus *sysfs_get_freq_affected_cpus(1717+ unsigned int cpu);1818+extern struct cpufreq_affected_cpus *sysfs_get_freq_related_cpus(1919+ unsigned int cpu);2020+extern struct cpufreq_stats *sysfs_get_freq_stats(unsigned int cpu,2121+ unsigned long long *total_time);1622extern unsigned long sysfs_get_freq_transitions(unsigned int cpu);1717-extern int sysfs_set_freq_policy(unsigned int cpu, struct cpufreq_policy *policy);1818-extern int sysfs_modify_freq_policy_min(unsigned int cpu, unsigned long min_freq);1919-extern int sysfs_modify_freq_policy_max(unsigned int cpu, unsigned long max_freq);2323+extern int sysfs_set_freq_policy(unsigned int cpu,2424+ struct cpufreq_policy *policy);2525+extern int sysfs_modify_freq_policy_min(unsigned int cpu,2626+ unsigned long min_freq);2727+extern int sysfs_modify_freq_policy_max(unsigned int cpu,2828+ unsigned long max_freq);2029extern int sysfs_modify_freq_policy_governor(unsigned int cpu, char *governor);2121-extern int sysfs_set_frequency(unsigned int cpu, unsigned long target_frequency);3030+extern int sysfs_set_frequency(unsigned int cpu,3131+ unsigned long target_frequency);