All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf
@ 2023-01-09  4:06 Quanfa Fu
  2023-01-09 14:59 ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Quanfa Fu @ 2023-01-09  4:06 UTC (permalink / raw)
  To: rostedt, mhiramat; +Cc: linux-kernel, linux-trace-kernel, Quanfa Fu

No need to check for negative return value from snprintf() as the
code does not return negative values.

Signed-off-by: Quanfa Fu <quanfafu@gmail.com>

-----
V2 -> V3: continue to use snprintf
V1 -> V2: memory allc uses kzalloc and replace snprintf with memcpy
---
 kernel/trace/trace_eprobe.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
index 352b65e2b910..594ac1d086aa 100644
--- a/kernel/trace/trace_eprobe.c
+++ b/kernel/trace/trace_eprobe.c
@@ -923,17 +923,13 @@ static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const ch
 
 	p = ep->filter_str;
 	for (i = 0; i < argc; i++) {
-		ret = snprintf(p, len, "%s ", argv[i]);
-		if (ret < 0)
-			goto error;
-		if (ret > len) {
-			ret = -E2BIG;
-			goto error;
-		}
+		if (i)
+			ret = snprintf(p, len, " %s", argv[i]);
+		else
+			ret = snprintf(p, len, "%s", argv[i]);
 		p += ret;
 		len -= ret;
 	}
-	p[-1] = '\0';
 
 	/*
 	 * Ensure the filter string can be parsed correctly. Note, this
-- 
2.31.1


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

* Re: [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf
  2023-01-09  4:06 [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf Quanfa Fu
@ 2023-01-09 14:59 ` Masami Hiramatsu
  2023-01-09 15:12   ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2023-01-09 14:59 UTC (permalink / raw)
  To: Quanfa Fu; +Cc: rostedt, linux-kernel, linux-trace-kernel

On Mon,  9 Jan 2023 12:06:25 +0800
Quanfa Fu <quanfafu@gmail.com> wrote:

> No need to check for negative return value from snprintf() as the
> code does not return negative values.
> 

Thanks for simplifying, this looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

> Signed-off-by: Quanfa Fu <quanfafu@gmail.com>
> 
> -----
> V2 -> V3: continue to use snprintf
> V1 -> V2: memory allc uses kzalloc and replace snprintf with memcpy
> ---
>  kernel/trace/trace_eprobe.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c
> index 352b65e2b910..594ac1d086aa 100644
> --- a/kernel/trace/trace_eprobe.c
> +++ b/kernel/trace/trace_eprobe.c
> @@ -923,17 +923,13 @@ static int trace_eprobe_parse_filter(struct trace_eprobe *ep, int argc, const ch
>  
>  	p = ep->filter_str;
>  	for (i = 0; i < argc; i++) {
> -		ret = snprintf(p, len, "%s ", argv[i]);
> -		if (ret < 0)
> -			goto error;
> -		if (ret > len) {
> -			ret = -E2BIG;
> -			goto error;
> -		}
> +		if (i)
> +			ret = snprintf(p, len, " %s", argv[i]);
> +		else
> +			ret = snprintf(p, len, "%s", argv[i]);
>  		p += ret;
>  		len -= ret;
>  	}
> -	p[-1] = '\0';
>  
>  	/*
>  	 * Ensure the filter string can be parsed correctly. Note, this
> -- 
> 2.31.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

* Re: [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf
  2023-01-09 14:59 ` Masami Hiramatsu
@ 2023-01-09 15:12   ` Steven Rostedt
  2023-01-10  0:29     ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2023-01-09 15:12 UTC (permalink / raw)
  To: Masami Hiramatsu (Google); +Cc: Quanfa Fu, linux-kernel, linux-trace-kernel

On Mon, 9 Jan 2023 23:59:13 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:

> On Mon,  9 Jan 2023 12:06:25 +0800
> Quanfa Fu <quanfafu@gmail.com> wrote:
> 
> > No need to check for negative return value from snprintf() as the
> > code does not return negative values.
> >   
> 
> Thanks for simplifying, this looks good to me.
> 
> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Masami, do you want to take it into the probes branch, or do you want me to
take it into the tracing branch?

-- Steve


> 
> > Signed-off-by: Quanfa Fu <quanfafu@gmail.com>
> > 

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

* Re: [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf
  2023-01-09 15:12   ` Steven Rostedt
@ 2023-01-10  0:29     ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2023-01-10  0:29 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Quanfa Fu, linux-kernel, linux-trace-kernel

On Mon, 9 Jan 2023 10:12:26 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Mon, 9 Jan 2023 23:59:13 +0900
> Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> 
> > On Mon,  9 Jan 2023 12:06:25 +0800
> > Quanfa Fu <quanfafu@gmail.com> wrote:
> > 
> > > No need to check for negative return value from snprintf() as the
> > > code does not return negative values.
> > >   
> > 
> > Thanks for simplifying, this looks good to me.
> > 
> > Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> 
> Masami, do you want to take it into the probes branch, or do you want me to
> take it into the tracing branch?

Yes, I'll take it to probe/for-next.

Thank you!

> 
> -- Steve
> 
> 
> > 
> > > Signed-off-by: Quanfa Fu <quanfafu@gmail.com>
> > > 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

end of thread, other threads:[~2023-01-10  0:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09  4:06 [PATCH v3] tracing/eprobe: no need to check for negative ret value for snprintf Quanfa Fu
2023-01-09 14:59 ` Masami Hiramatsu
2023-01-09 15:12   ` Steven Rostedt
2023-01-10  0:29     ` Masami Hiramatsu

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.