Skip to contentSkip to conversation

drm: panel: replace snprintf in show functions with sysfs_emit

PATCH In review Qing Wang 3 participants 3 messages Oct 15, 2021

Subsystems (3)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 drm: panel: replace snprintf in show functions with sysfs_emit

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/gpu/drm/panel/panel-dsi-cm.c:251: WARNING: use scnprintf or sprintf. drivers/gpu/drm/panel/panel-dsi-cm.c:271: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

---
 drivers/gpu/drm/panel/panel-dsi-cm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/panel/panel-dsi-cm.c +2 -2
index 5fbfb71..a8efb06 100644
@@ -248,7 +248,7 @@ static ssize_t num_dsi_errors_show(struct device *dev,
 	if (r)
 		return r;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", errors);
+	return sysfs_emit(buf, "%d\n", errors);
 }
 
 static ssize_t hw_revision_show(struct device *dev,
@@ -268,7 +268,7 @@ static ssize_t hw_revision_show(struct device *dev,
 	if (r)
 		return r;
 
-	return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
+	return sysfs_emit(buf, "%02x.%02x.%02x\n", id1, id2, id3);
 }
 
 static DEVICE_ATTR_RO(num_dsi_errors);
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 11 lines · Qing Wang

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/gpu/drm/panel/panel-dsi-cm.c:251: WARNING: use scnprintf or sprintf. drivers/gpu/drm/panel/panel-dsi-cm.c:271: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

---

The patch subject could be more specific (this updates just one panel driver). Otherwise:

-- Sebastian

Quoted 28 lines
 drivers/gpu/drm/panel/panel-dsi-cm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/panel/panel-dsi-cm.c +2 -2
index 5fbfb71..a8efb06 100644
@@ -248,7 +248,7 @@ static ssize_t num_dsi_errors_show(struct device *dev,
 	if (r)
 		return r;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", errors);
+	return sysfs_emit(buf, "%d\n", errors);
 }
 
 static ssize_t hw_revision_show(struct device *dev,
@@ -268,7 +268,7 @@ static ssize_t hw_revision_show(struct device *dev,
 	if (r)
 		return r;
 
-	return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
+	return sysfs_emit(buf, "%02x.%02x.%02x\n", id1, id2, id3);
 }
 
 static DEVICE_ATTR_RO(num_dsi_errors);
Signature · 1 line
2.7.4
#2 lore raw

Hi Qing and Sebastian.

Quoted 12 lines · Sebastian Reichel

Hi,

Quoted 9 lines · Qing Wang

show() must not use snprintf() when formatting the value to be returned to user space.

Fix the following coccicheck warning:
drivers/gpu/drm/panel/panel-dsi-cm.c:251: WARNING: use scnprintf or sprintf. drivers/gpu/drm/panel/panel-dsi-cm.c:271: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Quoted 7 lines
Quoted 2 lines

---

The patch subject could be more specific (this updates just one panel driver). Otherwise:

Updated the patch subject and applied the patch to drm-misc-next. It will show up in -next in 1-2 weeks.

Sam