Skip to contentSkip to conversation

cpufreq: stats: Convert to use sysfs_emit_at() API

PATCH Applied [email protected] 3 participants 3 messages Dec 6, 2022 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: stats: Convert to use sysfs_emit_at() API

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/cpufreq/cpufreq_stats.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/cpufreq/cpufreq_stats.c +7 -9
index 1570d6f3e75d..55c7ffd37d1c 100644
@@ -128,25 +128,23 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
 	ssize_t len = 0;
 	int i, j, count;
 
-	len += scnprintf(buf + len, PAGE_SIZE - len, "   From  :    To\n");
-	len += scnprintf(buf + len, PAGE_SIZE - len, "         : ");
+	len += sysfs_emit_at(buf, len, "   From  :    To\n");
+	len += sysfs_emit_at(buf, len, "         : ");
 	for (i = 0; i < stats->state_num; i++) {
 		if (len >= PAGE_SIZE)
 			break;
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ",
-				stats->freq_table[i]);
+		len += sysfs_emit_at(buf, len, "%9u ", stats->freq_table[i]);
 	}
 	if (len >= PAGE_SIZE)
 		return PAGE_SIZE;
 
-	len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+	len += sysfs_emit_at(buf, len, "\n");
 
 	for (i = 0; i < stats->state_num; i++) {
 		if (len >= PAGE_SIZE)
 			break;
 
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%9u: ",
-				stats->freq_table[i]);
+		len += sysfs_emit_at(buf, len, "%9u: ", stats->freq_table[i]);
 
 		for (j = 0; j < stats->state_num; j++) {
 			if (len >= PAGE_SIZE)
@@ -157,11 +155,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
 			else
 				count = stats->trans_table[i * stats->max_state + j];
 
-			len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ", count);
+			len += sysfs_emit_at(buf, len, "%9u ", count);
 		}
 		if (len >= PAGE_SIZE)
 			break;
-		len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+		len += sysfs_emit_at(buf, len, "\n");
 	}
 
 	if (len >= PAGE_SIZE) {
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 50 lines · On 06-12-22, 16:15, [email protected] wrote:

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/cpufreq/cpufreq_stats.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/cpufreq/cpufreq_stats.c +5 -7
index 1570d6f3e75d..55c7ffd37d1c 100644
@@ -128,25 +128,23 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
 	ssize_t len = 0;
 	int i, j, count;
 
-	len += scnprintf(buf + len, PAGE_SIZE - len, "   From  :    To\n");
-	len += scnprintf(buf + len, PAGE_SIZE - len, "         : ");
+	len += sysfs_emit_at(buf, len, "   From  :    To\n");
+	len += sysfs_emit_at(buf, len, "         : ");
 	for (i = 0; i < stats->state_num; i++) {
 		if (len >= PAGE_SIZE)
 			break;
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ",
-				stats->freq_table[i]);
+		len += sysfs_emit_at(buf, len, "%9u ", stats->freq_table[i]);
 	}
 	if (len >= PAGE_SIZE)
 		return PAGE_SIZE;
 
-	len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+	len += sysfs_emit_at(buf, len, "\n");
 
 	for (i = 0; i < stats->state_num; i++) {
 		if (len >= PAGE_SIZE)
 			break;
 
-		len += scnprintf(buf + len, PAGE_SIZE - len, "%9u: ",
-				stats->freq_table[i]);
+		len += sysfs_emit_at(buf, len, "%9u: ", stats->freq_table[i]);
 
 		for (j = 0; j < stats->state_num; j++) {
 			if (len >= PAGE_SIZE)
@@ -157,11 +155,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
 			else
 				count = stats->trans_table[i * stats->max_state + j];
 

drivers/cpufreq/cpufreq_stats.c static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) · line 165

Quoted 10 lines
drivers/cpufreq/cpufreq_stats.c +2 -2
-			len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ", count);
+			len += sysfs_emit_at(buf, len, "%9u ", count);
 		}
 		if (len >= PAGE_SIZE)
 			break;
-		len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+		len += sysfs_emit_at(buf, len, "\n");
 	}
 
 	if (len >= PAGE_SIZE) {
Signature · 1 line
viresh
maintainer Applied
#2 lore raw
Quoted 61 lines · Viresh Kumar
Quoted 59 lines · On 06-12-22, 16:15, [email protected] wrote:

From: ye xingchen <[email protected]>

Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/cpufreq/cpufreq_stats.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/cpufreq/cpufreq_stats.c +7 -9
index 1570d6f3e75d..55c7ffd37d1c 100644
@@ -128,25 +128,23 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
      ssize_t len = 0;
      int i, j, count;
 
-     len += scnprintf(buf + len, PAGE_SIZE - len, "   From  :    To\n");
-     len += scnprintf(buf + len, PAGE_SIZE - len, "         : ");
+     len += sysfs_emit_at(buf, len, "   From  :    To\n");
+     len += sysfs_emit_at(buf, len, "         : ");
      for (i = 0; i < stats->state_num; i++) {
              if (len >= PAGE_SIZE)
                      break;
-             len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ",
-                             stats->freq_table[i]);
+             len += sysfs_emit_at(buf, len, "%9u ", stats->freq_table[i]);
      }
      if (len >= PAGE_SIZE)
              return PAGE_SIZE;
 
-     len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+     len += sysfs_emit_at(buf, len, "\n");
 
      for (i = 0; i < stats->state_num; i++) {
              if (len >= PAGE_SIZE)
                      break;
 
-             len += scnprintf(buf + len, PAGE_SIZE - len, "%9u: ",
-                             stats->freq_table[i]);
+             len += sysfs_emit_at(buf, len, "%9u: ", stats->freq_table[i]);
 
              for (j = 0; j < stats->state_num; j++) {
                      if (len >= PAGE_SIZE)
@@ -157,11 +155,11 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
                      else
                              count = stats->trans_table[i * stats->max_state + j];
 
-                     len += scnprintf(buf + len, PAGE_SIZE - len, "%9u ", count);
+                     len += sysfs_emit_at(buf, len, "%9u ", count);
              }
              if (len >= PAGE_SIZE)
                      break;
-             len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
+             len += sysfs_emit_at(buf, len, "\n");
      }
 
Quoted 5 lines

drivers/cpufreq/cpufreq_stats.c static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) · line 165

Quoted 1 line
drivers/cpufreq/cpufreq_stats.c +0 -0
      if (len >= PAGE_SIZE) {

--

Applied as 6.2 material, thanks!