]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpufreq: Optimize cpufreq_show_cpus()
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 26 May 2022 11:51:19 +0000 (17:21 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 14 Jun 2022 13:48:49 +0000 (15:48 +0200)
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 <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index 2cad42774164799dc1895116f5ca7783e46b281a..e24aa5d4bca54b43c4c68dafb9dcbc1ec78fb35d 100644 (file)
@@ -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;
 }