From: Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
To: Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
Subject: [PATCH] remoteproc: debugfs: use sysfs_streq() for write parsing
Date: Tue, 17 Nov 2026 00:12:30 +0530 [thread overview]
Message-ID: <20261116184230.1885-1-saileshnandanavanam@gmail.com> (raw)
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
next reply other threads:[~2026-11-16 18:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 18:42 Sailesh Nandanavanam [this message]
2026-11-25 23:04 ` [PATCH] remoteproc: debugfs: use sysfs_streq() for write parsing Francesco Valla
2026-11-26 17:28 ` Mathieu Poirier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116184230.1885-1-saileshnandanavanam@gmail.com \
--to=saileshnandanavanam@gmail.com \
--cc=andersson@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.