Skip to contentSkip to conversation

remoteproc: sysfs: Use scnprintf instead of sprintf

PATCH Superseded Siddharth Gupta 2 participants 3 messages Mar 4, 2021 Remote processor (remoteproc)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: sysfs: Use scnprintf instead of sprintf

From: Raghavendra Rao Ananta <[email protected]>

For security reasons scnprintf() is preferred over sprintf(). Hence, convert the remoteproc's sysfs show functions accordingly.

---
 drivers/remoteproc/remoteproc_sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_sysfs.c +3 -2
index 1dbef89..853f569 100644
@@ -15,7 +15,8 @@ static ssize_t recovery_show(struct device *dev,
 {
 	struct rproc *rproc = to_rproc(dev);
 
-	return sprintf(buf, "%s", rproc->recovery_disabled ? "disabled\n" : "enabled\n");
+	return scnprintf(buf, PAGE_SIZE, "%s",
+			 rproc->recovery_disabled ? "disabled\n" : "enabled\n");
 }
 
 /*
@@ -82,7 +83,7 @@ static ssize_t coredump_show(struct device *dev,
 {
 	struct rproc *rproc = to_rproc(dev);
 
-	return sprintf(buf, "%s\n", rproc_coredump_str[rproc->dump_conf]);
+	return scnprintf(buf, PAGE_SIZE, "%s\n", rproc_coredump_str[rproc->dump_conf]);
 }
 
 /*
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 5 lines · Siddharth Gupta

From: Raghavendra Rao Ananta <[email protected]>

For security reasons scnprintf() is preferred over sprintf(). Hence, convert the remoteproc's sysfs show functions accordingly.

Thanks for the patch Siddharth.

There's no possibility for these calls to generate more than PAGE_SIZE amount of data, so this isn't really necessary. But if you insist, please let's use sysfs_emit() instead.

Regards,
Bjorn

Quoted 33 lines
---
 drivers/remoteproc/remoteproc_sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_sysfs.c +3 -2
index 1dbef89..853f569 100644
@@ -15,7 +15,8 @@ static ssize_t recovery_show(struct device *dev,
 {
 	struct rproc *rproc = to_rproc(dev);
 
-	return sprintf(buf, "%s", rproc->recovery_disabled ? "disabled\n" : "enabled\n");
+	return scnprintf(buf, PAGE_SIZE, "%s",
+			 rproc->recovery_disabled ? "disabled\n" : "enabled\n");
 }
 
 /*
@@ -82,7 +83,7 @@ static ssize_t coredump_show(struct device *dev,
 {
 	struct rproc *rproc = to_rproc(dev);
 
-	return sprintf(buf, "%s\n", rproc_coredump_str[rproc->dump_conf]);
+	return scnprintf(buf, PAGE_SIZE, "%s\n", rproc_coredump_str[rproc->dump_conf]);
 }
 
 /*
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
Quoted 7 lines · Bjorn Andersson
Quoted 5 lines · Siddharth Gupta

From: Raghavendra Rao Ananta <[email protected]>

For security reasons scnprintf() is preferred over sprintf(). Hence, convert the remoteproc's sysfs show functions accordingly.

Quoted 8 lines

Thanks for the patch Siddharth.

There's no possibility for these calls to generate more than PAGE_SIZE amount of data, so this isn't really necessary. But if you insist, please let's use sysfs_emit() instead.

Regards,
Bjorn

Sure Bjorn, I'll push the new patch immediately.

Thanks,
Siddharth

Quoted 34 lines
Quoted 34 lines
---
  drivers/remoteproc/remoteproc_sysfs.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_sysfs.c +3 -2
index 1dbef89..853f569 100644
@@ -15,7 +15,8 @@ static ssize_t recovery_show(struct device *dev,
  {
  	struct rproc *rproc = to_rproc(dev);
 
-	return sprintf(buf, "%s", rproc->recovery_disabled ? "disabled\n" : "enabled\n");
+	return scnprintf(buf, PAGE_SIZE, "%s",
+			 rproc->recovery_disabled ? "disabled\n" : "enabled\n");
  }
 
  /*
@@ -82,7 +83,7 @@ static ssize_t coredump_show(struct device *dev,
  {
  	struct rproc *rproc = to_rproc(dev);
 
-	return sprintf(buf, "%s\n", rproc_coredump_str[rproc->dump_conf]);
+	return scnprintf(buf, PAGE_SIZE, "%s\n", rproc_coredump_str[rproc->dump_conf]);
  }
 
  /*
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project