linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG
@ 2021-05-10  1:38 zhouchuangao
  2021-05-12 12:54 ` Jessica Yu
  0 siblings, 1 reply; 5+ messages in thread
From: zhouchuangao @ 2021-05-10  1:38 UTC (permalink / raw)
  To: jeyu; +Cc: linux-kernel, zhouchuangao

This patch comes from cocinelle warning.

BUG_ON uses unlikely in if(). Through disassembly, we can see that
brk #0x800 is compiled to the end of the function.
As you can see below:
    ......
    ffffff8008660bec:   d65f03c0    ret
    ffffff8008660bf0:   d4210000    brk #0x800

Usually, the condition in if () is not satisfied. For the
multi-stage pipeline, we do not need to perform fetch decode
and excute operation on brk instruction.

In my opinion, this can improve the efficiency of the
multi-stage pipeline.

Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
---
 kernel/module.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index b5dd92e..faf9114 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1014,8 +1014,7 @@ void __symbol_put(const char *symbol)
 	};
 
 	preempt_disable();
-	if (!find_symbol(&fsa))
-		BUG();
+	BUG_ON(!find_symbol(&fsa));
 	module_put(fsa.owner);
 	preempt_enable();
 }
-- 
2.7.4


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

* Re: [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG
  2021-05-10  1:38 [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG zhouchuangao
@ 2021-05-12 12:54 ` Jessica Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Jessica Yu @ 2021-05-12 12:54 UTC (permalink / raw)
  To: zhouchuangao; +Cc: linux-kernel

+++ zhouchuangao [09/05/21 18:38 -0700]:
>This patch comes from cocinelle warning.

Please include the output of the cocinelle warning here as well.

See commit 56149c8cd820 ("media: pci: saa7164-core.c: replace if
(cond) BUG() with BUG_ON()") for an example. Thanks.

>BUG_ON uses unlikely in if(). Through disassembly, we can see that
>brk #0x800 is compiled to the end of the function.
>As you can see below:
>    ......
>    ffffff8008660bec:   d65f03c0    ret
>    ffffff8008660bf0:   d4210000    brk #0x800
>
>Usually, the condition in if () is not satisfied. For the
>multi-stage pipeline, we do not need to perform fetch decode
>and excute operation on brk instruction.
>
>In my opinion, this can improve the efficiency of the
>multi-stage pipeline.
>
>Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
>---
> kernel/module.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
>diff --git a/kernel/module.c b/kernel/module.c
>index b5dd92e..faf9114 100644
>--- a/kernel/module.c
>+++ b/kernel/module.c
>@@ -1014,8 +1014,7 @@ void __symbol_put(const char *symbol)
> 	};
>
> 	preempt_disable();
>-	if (!find_symbol(&fsa))
>-		BUG();
>+	BUG_ON(!find_symbol(&fsa));
> 	module_put(fsa.owner);
> 	preempt_enable();
> }
>-- 
>2.7.4
>

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

* [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG.
@ 2021-04-17 10:22 zhouchuangao
  0 siblings, 0 replies; 5+ messages in thread
From: zhouchuangao @ 2021-04-17 10:22 UTC (permalink / raw)
  To: Jessica Yu, linux-kernel; +Cc: zhouchuangao

First:
This patch comes from cocinelle warning.

Second:
BUG_ON uses unlikely in if(). Through disassembly, we can see that
brk #0x800 is compiled to the end of the function.
As you can see below:
    ......
    ffffff8008660bec:   d65f03c0    ret
    ffffff8008660bf0:   d4210000    brk #0x800

Usually, the condition in if () is not satisfied. For the
multi-stage pipeline, we do not need to perform fetch decode
and excute operation on brk instruction.

In my opinion, this can improve the efficiency of the
multi-stage pipeline.

Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
---
 kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 3047935..f46fc4f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1014,8 +1014,8 @@ void __symbol_put(const char *symbol)
 	};
 
 	preempt_disable();
-	if (!find_symbol(&fsa))
-		BUG();
+	BUG_ON(!find_symbol(&fsa));
+
 	module_put(fsa.owner);
 	preempt_enable();
 }
-- 
2.7.4


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

* Re: [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG.
  2021-03-30 12:07 zhouchuangao
@ 2021-04-12 13:04 ` Jessica Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Jessica Yu @ 2021-04-12 13:04 UTC (permalink / raw)
  To: zhouchuangao; +Cc: linux-kernel

+++ zhouchuangao [30/03/21 05:07 -0700]:
>It can be optimized at compile time.
>
>Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>

Hi,

Could you please provide a more descriptive changelog? I.e., Is this
a fix for a cocinelle warning? What are the optimization(s)?

Thanks,

Jessica

>---
> kernel/module.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/kernel/module.c b/kernel/module.c
>index 3047935..f46fc4f 100644
>--- a/kernel/module.c
>+++ b/kernel/module.c
>@@ -1014,8 +1014,8 @@ void __symbol_put(const char *symbol)
> 	};
>
> 	preempt_disable();
>-	if (!find_symbol(&fsa))
>-		BUG();
>+	BUG_ON(!find_symbol(&fsa));
>+
> 	module_put(fsa.owner);
> 	preempt_enable();
> }
>-- 
>2.7.4
>

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

* [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG.
@ 2021-03-30 12:07 zhouchuangao
  2021-04-12 13:04 ` Jessica Yu
  0 siblings, 1 reply; 5+ messages in thread
From: zhouchuangao @ 2021-03-30 12:07 UTC (permalink / raw)
  To: Jessica Yu, linux-kernel; +Cc: zhouchuangao

It can be optimized at compile time.

Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
---
 kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 3047935..f46fc4f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1014,8 +1014,8 @@ void __symbol_put(const char *symbol)
 	};
 
 	preempt_disable();
-	if (!find_symbol(&fsa))
-		BUG();
+	BUG_ON(!find_symbol(&fsa));
+
 	module_put(fsa.owner);
 	preempt_enable();
 }
-- 
2.7.4


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

end of thread, other threads:[~2021-05-12 12:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10  1:38 [PATCH] kernel/module: Use BUG_ON instead of if condition followed by BUG zhouchuangao
2021-05-12 12:54 ` Jessica Yu
  -- strict thread matches above, loose matches on Subject: below --
2021-04-17 10:22 zhouchuangao
2021-03-30 12:07 zhouchuangao
2021-04-12 13:04 ` Jessica Yu

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).