Skip to contentSkip to conversation

counter: replace snprintf in show functions with sysfs_emit

PATCH In review Qing Wang 2 participants 2 messages Oct 13, 2021 – Oct 14, 2021

Subsystems (4)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 counter: replace snprintf in show functions with sysfs_emit

coccicheck complains about the use of snprintf() in sysfs show functions.

Fix the following coccicheck warning:
drivers/counter/stm32-lptimer-cnt.c:265:8-16: WARNING: use scnprintf or sprintf. drivers/counter/stm32-lptimer-cnt.c:176:8-16: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

---
 drivers/counter/stm32-lptimer-cnt.c | 2 +-
 drivers/counter/stm32-timer-cnt.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/counter/stm32-lptimer-cnt.c +1 -1
index c19d998..6f1113a 100644
@@ -262,7 +262,7 @@ static ssize_t stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
 {
 	struct stm32_lptim_cnt *const priv = counter->priv;
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", priv->ceiling);
+	return sysfs_emit(buf, "%u\n", priv->ceiling);
 }
 
 static ssize_t stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
drivers/counter/stm32-timer-cnt.c +1 -1
index 603b30a..e772586 100644
@@ -173,7 +173,7 @@ static ssize_t stm32_count_ceiling_read(struct counter_device *counter,
 
 	regmap_read(priv->regmap, TIM_ARR, &arr);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", arr);
+	return sysfs_emit(buf, "%u\n", arr);
 }
 
 static ssize_t stm32_count_ceiling_write(struct counter_device *counter,
Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines · Qing Wang

coccicheck complains about the use of snprintf() in sysfs show functions.

Fix the following coccicheck warning:
drivers/counter/stm32-lptimer-cnt.c:265:8-16: WARNING: use scnprintf or sprintf. drivers/counter/stm32-lptimer-cnt.c:176:8-16: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Hello Qing Wang,

Thank you for your submission. I believe these warnings are already resolved by commit d70e46af7531 ("counter: Internalize sysfs interface code") in the linux-next tree. Would you verify whether that is the case or if we still need to fix this?

Sincerely,

William Breathitt Gray

Quoted 34 lines
---
 drivers/counter/stm32-lptimer-cnt.c | 2 +-
 drivers/counter/stm32-timer-cnt.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/counter/stm32-lptimer-cnt.c +1 -1
index c19d998..6f1113a 100644
@@ -262,7 +262,7 @@ static ssize_t stm32_lptim_cnt_ceiling_read(struct counter_device *counter,
 {
 	struct stm32_lptim_cnt *const priv = counter->priv;
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", priv->ceiling);
+	return sysfs_emit(buf, "%u\n", priv->ceiling);
 }
 
 static ssize_t stm32_lptim_cnt_ceiling_write(struct counter_device *counter,
drivers/counter/stm32-timer-cnt.c +1 -1
index 603b30a..e772586 100644
@@ -173,7 +173,7 @@ static ssize_t stm32_count_ceiling_read(struct counter_device *counter,
 
 	regmap_read(priv->regmap, TIM_ARR, &arr);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", arr);
+	return sysfs_emit(buf, "%u\n", arr);
 }
 
 static ssize_t stm32_count_ceiling_write(struct counter_device *counter,
Signature · 1 line
2.7.4