From: Viresh Kumar Date: Thu, 26 May 2022 11:51:19 +0000 (+0530) Subject: cpufreq: Optimize cpufreq_show_cpus() X-Git-Tag: v6.0-rc1~184^2~5^2~1^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=336e51283ae376835b30b9edfcddd8e7b7615798;p=thirdparty%2Fkernel%2Flinux.git cpufreq: Optimize cpufreq_show_cpus() Instead of specially adding a space for each CPU, except the first one, lets add space for each of them and remove it at the end. Signed-off-by: Viresh Kumar Signed-off-by: Rafael J. Wysocki --- diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2cad427741647..e24aa5d4bca54 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -843,12 +843,14 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf) unsigned int cpu; for_each_cpu(cpu, mask) { - if (i) - i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); - i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); + i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u ", cpu); if (i >= (PAGE_SIZE - 5)) break; } + + /* Remove the extra space at the end */ + i--; + i += sprintf(&buf[i], "\n"); return i; }