* [PATCH] tracing: Do PTR_ERR() after IS_ERR()
@ 2022-07-27 15:35 Li Qiong
2022-07-27 16:28 ` Steven Rostedt
0 siblings, 1 reply; 5+ messages in thread
From: Li Qiong @ 2022-07-27 15:35 UTC (permalink / raw)
To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, yuzhe, renyu, jiaming, Li Qiong
Check IS_ERR() firstly, then do PTR_ERR().
Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
kernel/trace/ring_buffer_benchmark.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c
index 78e576575b79..a8f6b0725c45 100644
--- a/kernel/trace/ring_buffer_benchmark.c
+++ b/kernel/trace/ring_buffer_benchmark.c
@@ -439,17 +439,19 @@ static int __init ring_buffer_benchmark_init(void)
if (!disable_reader) {
consumer = kthread_create(ring_buffer_consumer_thread,
NULL, "rb_consumer");
- ret = PTR_ERR(consumer);
- if (IS_ERR(consumer))
+ if (IS_ERR(consumer)) {
+ ret = PTR_ERR(consumer);
goto out_fail;
+ }
}
producer = kthread_run(ring_buffer_producer_thread,
NULL, "rb_producer");
- ret = PTR_ERR(producer);
- if (IS_ERR(producer))
+ if (IS_ERR(producer)) {
+ ret = PTR_ERR(producer);
goto out_kill;
+ }
/*
* Run them as low-prio background tasks by default:
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] tracing: Do PTR_ERR() after IS_ERR()
2022-07-27 15:35 [PATCH] tracing: Do PTR_ERR() after IS_ERR() Li Qiong
@ 2022-07-27 16:28 ` Steven Rostedt
2022-07-28 0:28 ` liqiong
0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2022-07-27 16:28 UTC (permalink / raw)
To: Li Qiong; +Cc: Ingo Molnar, linux-kernel, yuzhe, renyu, jiaming
On Wed, 27 Jul 2022 23:35:19 +0800
Li Qiong <liqiong@nfschina.com> wrote:
> Check IS_ERR() firstly, then do PTR_ERR().
Why?
The code is fine as is.
-- Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tracing: Do PTR_ERR() after IS_ERR()
2022-07-27 16:28 ` Steven Rostedt
@ 2022-07-28 0:28 ` liqiong
2022-07-29 16:56 ` Steven Rostedt
0 siblings, 1 reply; 5+ messages in thread
From: liqiong @ 2022-07-28 0:28 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Ingo Molnar, linux-kernel, yuzhe, renyu, jiaming
在 2022年07月28日 00:28, Steven Rostedt 写道:
> On Wed, 27 Jul 2022 23:35:19 +0800
> Li Qiong <liqiong@nfschina.com> wrote:
>
>> Check IS_ERR() firstly, then do PTR_ERR().
> Why?
>
> The code is fine as is.
>
> -- Steve
>
Hi,
It's all right, assign PTR_ERR() to 'ret' anyway.
But this assignment is valid only at the "IS_ERR()" path.
Maybe it is better put "PTR_ERR()" at error path, keep the code clear.
--
李力琼 <13524287433>
上海市浦东新区海科路99号中科院上海高等研究院3号楼3楼
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tracing: Do PTR_ERR() after IS_ERR()
2022-07-28 0:28 ` liqiong
@ 2022-07-29 16:56 ` Steven Rostedt
2022-07-30 1:20 ` 李力琼
0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2022-07-29 16:56 UTC (permalink / raw)
To: liqiong; +Cc: Ingo Molnar, linux-kernel, yuzhe, renyu, jiaming
On Thu, 28 Jul 2022 08:28:08 +0800
liqiong <liqiong@nfschina.com> wrote:
> It's all right, assign PTR_ERR() to 'ret' anyway.
> But this assignment is valid only at the "IS_ERR()" path.
> Maybe it is better put "PTR_ERR()" at error path, keep the code clear.
No it does not. It adds unnecessary brackets.
It is common in the kernel to have:
ret = ERROR;
if (some_condition())
goto out;
ret = ERROR1;
if (some_other_condition())
goto out;
ret = ERROR2;
if (some_new_condition())
goto out;
ret = 0;
out:
return ret;
And your change breaks this.
-- Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tracing: Do PTR_ERR() after IS_ERR()
2022-07-29 16:56 ` Steven Rostedt
@ 2022-07-30 1:20 ` 李力琼
0 siblings, 0 replies; 5+ messages in thread
From: 李力琼 @ 2022-07-30 1:20 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Ingo Molnar, linux-kernel, yuzhe, renyu, jiaming
在 2022/7/30 00:56, Steven Rostedt 写道:
> On Thu, 28 Jul 2022 08:28:08 +0800
> liqiong <liqiong@nfschina.com> wrote:
>
>> It's all right, assign PTR_ERR() to 'ret' anyway.
>> But this assignment is valid only at the "IS_ERR()" path.
>> Maybe it is better put "PTR_ERR()" at error path, keep the code clear.
> No it does not. It adds unnecessary brackets.
>
> It is common in the kernel to have:
>
> ret = ERROR;
> if (some_condition())
> goto out;
>
> ret = ERROR1;
> if (some_other_condition())
> goto out;
>
> ret = ERROR2;
> if (some_new_condition())
> goto out;
>
> ret = 0;
> out:
> return ret;
>
> And your change breaks this.
>
> -- Steve
I got it, Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-30 1:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 15:35 [PATCH] tracing: Do PTR_ERR() after IS_ERR() Li Qiong
2022-07-27 16:28 ` Steven Rostedt
2022-07-28 0:28 ` liqiong
2022-07-29 16:56 ` Steven Rostedt
2022-07-30 1:20 ` 李力琼
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.