linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]  remoteproc: debugfs: Replace scnprintf() with sysfs_emit()
@ 2025-06-19 18:40 Abhinav Ananthu
  0 siblings, 0 replies; 3+ messages in thread
From: Abhinav Ananthu @ 2025-06-19 18:40 UTC (permalink / raw)
  To: andersson, mathieu.poirier
  Cc: linux-remoteproc, linux-kernel, Abhinav Ananthu, Abhinav Ananthu

Convert the debugfs show() functions in remoteproc_debugfs.c to use
sysfs_emit() instead of scnprintf(). The sysfs_emit() helper is the
preferred way to format sysfs output as it ensures the output is
properly bounded to PAGE_SIZE and simplifies the code.

This patch addresses three instances of scnprintf() usage in the file.

Signed-off-by: Abhinav Ananthu <your_email@example.com>
---
 drivers/remoteproc/remoteproc_debugfs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c
index b86c1d09c70c..691fd523e0b5 100644
--- a/drivers/remoteproc/remoteproc_debugfs.c
+++ b/drivers/remoteproc/remoteproc_debugfs.c
@@ -46,8 +46,9 @@ static ssize_t rproc_coredump_read(struct file *filp, char __user *userbuf,
 	char buf[20];
 	int len;
 
-	len = scnprintf(buf, sizeof(buf), "%s\n",
-			rproc_coredump_str[rproc->dump_conf]);
+	len = sysfs_emit(buf, "%s\n",
+		rproc_coredump_str[rproc->dump_conf]);
+
 
 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
 }
@@ -135,7 +136,7 @@ static ssize_t rproc_trace_read(struct file *filp, char __user *userbuf,
 	va = rproc_da_to_va(data->rproc, trace->da, trace->len, NULL);
 
 	if (!va) {
-		len = scnprintf(buf, sizeof(buf), "Trace %s not available\n",
+		len = sysfs_emit(buf, "Trace %s not available\n",
 				trace->name);
 		va = buf;
 	} else {
@@ -160,7 +161,7 @@ static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
 	char buf[100];
 	int i;
 
-	i = scnprintf(buf, sizeof(buf), "%.98s\n", rproc->name);
+	i = sysfs_emit(buf, "%.98s\n", rproc->name);
 
 	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH]  remoteproc: debugfs: Replace scnprintf() with sysfs_emit()
@ 2025-06-19 19:04 Abhinav Ananthu
  2025-06-19 19:19 ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Abhinav Ananthu @ 2025-06-19 19:04 UTC (permalink / raw)
  To: andersson, mathieu.poirier
  Cc: linux-remoteproc, linux-kernel, Abhinav Ananthu

I apologize for the mistake in the signed-off email address in the previous patch.

Convert the debugfs show() functions in remoteproc_debugfs.c to use
sysfs_emit() instead of scnprintf(). The sysfs_emit() helper is the
preferred way to format sysfs output as it ensures the output is
properly bounded to PAGE_SIZE and simplifies the code.

This patch addresses three instances of scnprintf() usage in the file.

Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com>
---
 drivers/remoteproc/remoteproc_debugfs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c
index b86c1d09c70c..691fd523e0b5 100644
--- a/drivers/remoteproc/remoteproc_debugfs.c
+++ b/drivers/remoteproc/remoteproc_debugfs.c
@@ -46,8 +46,9 @@ static ssize_t rproc_coredump_read(struct file *filp, char __user *userbuf,
 	char buf[20];
 	int len;
 
-	len = scnprintf(buf, sizeof(buf), "%s\n",
-			rproc_coredump_str[rproc->dump_conf]);
+	len = sysfs_emit(buf, "%s\n",
+		rproc_coredump_str[rproc->dump_conf]);
+
 
 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
 }
@@ -135,7 +136,7 @@ static ssize_t rproc_trace_read(struct file *filp, char __user *userbuf,
 	va = rproc_da_to_va(data->rproc, trace->da, trace->len, NULL);
 
 	if (!va) {
-		len = scnprintf(buf, sizeof(buf), "Trace %s not available\n",
+		len = sysfs_emit(buf, "Trace %s not available\n",
 				trace->name);
 		va = buf;
 	} else {
@@ -160,7 +161,7 @@ static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
 	char buf[100];
 	int i;
 
-	i = scnprintf(buf, sizeof(buf), "%.98s\n", rproc->name);
+	i = sysfs_emit(buf, "%.98s\n", rproc->name);
 
 	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] remoteproc: debugfs: Replace scnprintf() with sysfs_emit()
  2025-06-19 19:04 Abhinav Ananthu
@ 2025-06-19 19:19 ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2025-06-19 19:19 UTC (permalink / raw)
  To: Abhinav Ananthu, andersson, mathieu.poirier
  Cc: linux-remoteproc, linux-kernel

Le 19/06/2025 à 21:04, Abhinav Ananthu a écrit :
> I apologize for the mistake in the signed-off email address in the previous patch.
> 
> Convert the debugfs show() functions in remoteproc_debugfs.c to use
> sysfs_emit() instead of scnprintf(). The sysfs_emit() helper is the
> preferred way to format sysfs output as it ensures the output is
> properly bounded to PAGE_SIZE and simplifies the code.
> 
> This patch addresses three instances of scnprintf() usage in the file.

I think that this patch is just wrong.

The 3 functions below are not related to debugfs show function.

sysfs_emit() expect the buffer to be pages aligned (See [1]).
In the cases below, the buffers that are used are defined on the stack 
just a few lines above.

It is really unlikely that this condition will be met.


CJ

[1]: https://elixir.bootlin.com/linux/v6.15.2/source/fs/sysfs/file.c#L767


> 
> Signed-off-by: Abhinav Ananthu <abhinav.ogl@gmail.com>
> ---
>   drivers/remoteproc/remoteproc_debugfs.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_debugfs.c b/drivers/remoteproc/remoteproc_debugfs.c
> index b86c1d09c70c..691fd523e0b5 100644
> --- a/drivers/remoteproc/remoteproc_debugfs.c
> +++ b/drivers/remoteproc/remoteproc_debugfs.c
> @@ -46,8 +46,9 @@ static ssize_t rproc_coredump_read(struct file *filp, char __user *userbuf,
>   	char buf[20];
>   	int len;
>   
> -	len = scnprintf(buf, sizeof(buf), "%s\n",
> -			rproc_coredump_str[rproc->dump_conf]);
> +	len = sysfs_emit(buf, "%s\n",
> +		rproc_coredump_str[rproc->dump_conf]);
> +
>   
>   	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
>   }
> @@ -135,7 +136,7 @@ static ssize_t rproc_trace_read(struct file *filp, char __user *userbuf,
>   	va = rproc_da_to_va(data->rproc, trace->da, trace->len, NULL);
>   
>   	if (!va) {
> -		len = scnprintf(buf, sizeof(buf), "Trace %s not available\n",
> +		len = sysfs_emit(buf, "Trace %s not available\n",
>   				trace->name);
>   		va = buf;
>   	} else {
> @@ -160,7 +161,7 @@ static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
>   	char buf[100];
>   	int i;
>   
> -	i = scnprintf(buf, sizeof(buf), "%.98s\n", rproc->name);
> +	i = sysfs_emit(buf, "%.98s\n", rproc->name);
>   
>   	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
>   }


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-19 19:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-19 18:40 [PATCH] remoteproc: debugfs: Replace scnprintf() with sysfs_emit() Abhinav Ananthu
  -- strict thread matches above, loose matches on Subject: below --
2025-06-19 19:04 Abhinav Ananthu
2025-06-19 19:19 ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).