hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/power/cpupower/lib/cpufreq.c
....@@ -1,7 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
3
- *
4
- * Licensed under the terms of the GNU GPL License version 2.
54 */
65
76
....@@ -286,7 +285,7 @@
286285 } else {
287286 first = malloc(sizeof(*first));
288287 if (!first)
289
- goto error_out;
288
+ return NULL;
290289 current = first;
291290 }
292291 current->first = first;
....@@ -344,7 +343,7 @@
344343 unsigned int len;
345344
346345 len = sysfs_cpufreq_read_file(cpu, "scaling_available_frequencies",
347
- linebuf, sizeof(linebuf));
346
+ linebuf, sizeof(linebuf));
348347 if (len == 0)
349348 return NULL;
350349
....@@ -363,7 +362,7 @@
363362 } else {
364363 first = malloc(sizeof(*first));
365364 if (!first)
366
- goto error_out;
365
+ return NULL;
367366 current = first;
368367 }
369368 current->first = first;
....@@ -389,8 +388,64 @@
389388 return NULL;
390389 }
391390
392
-void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies
393
- *any) {
391
+struct cpufreq_available_frequencies
392
+*cpufreq_get_boost_frequencies(unsigned int cpu)
393
+{
394
+ struct cpufreq_available_frequencies *first = NULL;
395
+ struct cpufreq_available_frequencies *current = NULL;
396
+ char one_value[SYSFS_PATH_MAX];
397
+ char linebuf[MAX_LINE_LEN];
398
+ unsigned int pos, i;
399
+ unsigned int len;
400
+
401
+ len = sysfs_cpufreq_read_file(cpu, "scaling_boost_frequencies",
402
+ linebuf, sizeof(linebuf));
403
+ if (len == 0)
404
+ return NULL;
405
+
406
+ pos = 0;
407
+ for (i = 0; i < len; i++) {
408
+ if (linebuf[i] == ' ' || linebuf[i] == '\n') {
409
+ if (i - pos < 2)
410
+ continue;
411
+ if (i - pos >= SYSFS_PATH_MAX)
412
+ goto error_out;
413
+ if (current) {
414
+ current->next = malloc(sizeof(*current));
415
+ if (!current->next)
416
+ goto error_out;
417
+ current = current->next;
418
+ } else {
419
+ first = malloc(sizeof(*first));
420
+ if (!first)
421
+ return NULL;
422
+ current = first;
423
+ }
424
+ current->first = first;
425
+ current->next = NULL;
426
+
427
+ memcpy(one_value, linebuf + pos, i - pos);
428
+ one_value[i - pos] = '\0';
429
+ if (sscanf(one_value, "%lu", &current->frequency) != 1)
430
+ goto error_out;
431
+
432
+ pos = i + 1;
433
+ }
434
+ }
435
+
436
+ return first;
437
+
438
+ error_out:
439
+ while (first) {
440
+ current = first->next;
441
+ free(first);
442
+ first = current;
443
+ }
444
+ return NULL;
445
+}
446
+
447
+void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *any)
448
+{
394449 struct cpufreq_available_frequencies *tmp, *next;
395450
396451 if (!any)
....@@ -402,6 +457,11 @@
402457 free(tmp);
403458 tmp = next;
404459 }
460
+}
461
+
462
+void cpufreq_put_boost_frequencies(struct cpufreq_available_frequencies *any)
463
+{
464
+ cpufreq_put_available_frequencies(any);
405465 }
406466
407467 static struct cpufreq_affected_cpus *sysfs_get_cpu_list(unsigned int cpu,
....@@ -433,7 +493,7 @@
433493 } else {
434494 first = malloc(sizeof(*first));
435495 if (!first)
436
- goto error_out;
496
+ return NULL;
437497 current = first;
438498 }
439499 current->first = first;
....@@ -666,7 +726,7 @@
666726 } else {
667727 first = malloc(sizeof(*first));
668728 if (!first)
669
- goto error_out;
729
+ return NULL;
670730 current = first;
671731 }
672732 current->first = first;