mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] remoteproc: debugfs: use sysfs_streq() for write parsing
@ 2026-11-16 18:42 Sailesh Nandanavanam
  0 siblings, 0 replies; only message in thread
From: Sailesh Nandanavanam @ 2026-11-16 18:42 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Sailesh Nandanavanam

The debugfs coredump and recovery write handlers compare input with
strncmp() bounded by the write length, which accepts any prefix of a
valid command (e.g. "e" matches "enabled"). The sysfs counterparts in
remoteproc_sysfs.c already use sysfs_streq(), which requires an exact
match and tolerates a single trailing newline.

Switch the debugfs handlers to sysfs_streq() for consistent parsing
between the two interfaces, and explicitly NUL-terminate the copied
buffer since sysfs_streq() expects a string. Tighten the length check
to leave room for the terminator.

Truncated commands that were previously accepted by prefix match are
now rejected with -EINVAL.

Signed-off-by: Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
---
 drivers/remoteproc/remoteproc_debugfs.c | 33 ++++++++++---------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c
index e8e7b6a3769b..ef6761a13c6c 100644
--- a/drivers/remoteproc/remoteproc_debugfs.c
+++ b/drivers/remoteproc/remoteproc_debugfs.c
@@ -73,19 +73,16 @@ static ssize_t rproc_coredump_write(struct file *filp,
 				    loff_t *ppos)
 {
 	struct rproc *rproc = filp->private_data;
-	int ret, err = 0;
+	int err = 0;
 	char buf[20];
 
-	if (count < 1 || count > sizeof(buf))
+	if (count < 1 || count >= sizeof(buf))
 		return -EINVAL;
 
-	ret = copy_from_user(buf, user_buf, count);
-	if (ret)
+	if (copy_from_user(buf, user_buf, count))
 		return -EFAULT;
 
-	/* remove end of line */
-	if (buf[count - 1] == '\n')
-		buf[count - 1] = '\0';
+	buf[count] = '\0';
 
 	if (rproc->state == RPROC_CRASHED) {
 		dev_err(&rproc->dev, "can't change coredump configuration\n");
@@ -93,11 +90,11 @@ static ssize_t rproc_coredump_write(struct file *filp,
 		goto out;
 	}
 
-	if (!strncmp(buf, "disabled", count)) {
+	if (sysfs_streq(buf, "disabled")) {
 		rproc->dump_conf = RPROC_COREDUMP_DISABLED;
-	} else if (!strncmp(buf, "enabled", count)) {
+	} else if (sysfs_streq(buf, "enabled")) {
 		rproc->dump_conf = RPROC_COREDUMP_ENABLED;
-	} else if (!strncmp(buf, "inline", count)) {
+	} else if (sysfs_streq(buf, "inline")) {
 		rproc->dump_conf = RPROC_COREDUMP_INLINE;
 	} else {
 		dev_err(&rproc->dev, "Invalid coredump configuration\n");
@@ -211,26 +208,22 @@ rproc_recovery_write(struct file *filp, const char __user *user_buf,
 {
 	struct rproc *rproc = filp->private_data;
 	char buf[10];
-	int ret;
 
-	if (count < 1 || count > sizeof(buf))
+	if (count < 1 || count >= sizeof(buf))
 		return -EINVAL;
 
-	ret = copy_from_user(buf, user_buf, count);
-	if (ret)
+	if (copy_from_user(buf, user_buf, count))
 		return -EFAULT;
 
-	/* remove end of line */
-	if (buf[count - 1] == '\n')
-		buf[count - 1] = '\0';
+	buf[count] = '\0';
 
-	if (!strncmp(buf, "enabled", count)) {
+	if (sysfs_streq(buf, "enabled")) {
 		/* change the flag and begin the recovery process if needed */
 		rproc->recovery_disabled = false;
 		rproc_trigger_recovery(rproc);
-	} else if (!strncmp(buf, "disabled", count)) {
+	} else if (sysfs_streq(buf, "disabled")) {
 		rproc->recovery_disabled = true;
-	} else if (!strncmp(buf, "recover", count)) {
+	} else if (sysfs_streq(buf, "recover")) {
 		/* begin the recovery process without changing the flag */
 		rproc_trigger_recovery(rproc);
 	} else {
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-16 18:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 18:42 [PATCH] remoteproc: debugfs: use sysfs_streq() for write parsing Sailesh Nandanavanam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®