linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] arch/ia64/kernel/module.c: fix bugon.cocci warnings
@ 2021-08-23  1:51 CGEL
  2021-08-23 19:31 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: CGEL @ 2021-08-23  1:51 UTC (permalink / raw)
  To: Gustavo A . R . Silva
  Cc: Sergei Trofimovich, Andrew Morton, linux-ia64, linux-kernel,
	Jing Yangyang, Zeal Robot

From: Jing Yangyang <jing.yangyang@zte.com.cn>

Use BUG_ON instead of a if condition followed by BUG.

Generated by: scripts/coccinelle/misc/bugon.cocci

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Jing Yangyang <jing.yangyang@zte.com.cn>
---
 arch/ia64/kernel/module.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
index 2cba53c..f199378 100644
--- a/arch/ia64/kernel/module.c
+++ b/arch/ia64/kernel/module.c
@@ -560,8 +560,7 @@ struct plt_entry {
 	while (plt->bundle[0][0]) {
 		if (plt_target(plt) == target_ip)
 			goto found;
-		if (++plt >= plt_end)
-			BUG();
+		BUG_ON(++plt >= plt_end);
 	}
 	*plt = ia64_plt_template;
 	if (!patch_plt(mod, plt, target_ip, target_gp)) {
@@ -605,8 +604,7 @@ struct plt_entry {
 	while (fdesc->ip) {
 		if (fdesc->ip == value)
 			return (uint64_t)fdesc;
-		if ((uint64_t) ++fdesc >= mod->arch.opd->sh_addr + mod->arch.opd->sh_size)
-			BUG();
+		BUG_ON((uint64_t) ++fdesc >= mod->arch.opd->sh_addr + mod->arch.opd->sh_size);
 	}
 
 	/* Create new one */
-- 
1.8.3.1



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

* Re: [PATCH linux-next] arch/ia64/kernel/module.c: fix bugon.cocci warnings
  2021-08-23  1:51 [PATCH linux-next] arch/ia64/kernel/module.c: fix bugon.cocci warnings CGEL
@ 2021-08-23 19:31 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2021-08-23 19:31 UTC (permalink / raw)
  To: CGEL
  Cc: Gustavo A . R . Silva, Sergei Trofimovich, linux-ia64,
	linux-kernel, Jing Yangyang, Zeal Robot

On Sun, 22 Aug 2021 18:51:10 -0700 CGEL <cgel.zte@gmail.com> wrote:

> From: Jing Yangyang <jing.yangyang@zte.com.cn>
> 
> Use BUG_ON instead of a if condition followed by BUG.
> 
> Generated by: scripts/coccinelle/misc/bugon.cocci
> 
> ...
>
> --- a/arch/ia64/kernel/module.c
> +++ b/arch/ia64/kernel/module.c
> @@ -560,8 +560,7 @@ struct plt_entry {
>  	while (plt->bundle[0][0]) {
>  		if (plt_target(plt) == target_ip)
>  			goto found;
> -		if (++plt >= plt_end)
> -			BUG();
> +		BUG_ON(++plt >= plt_end);

There are concerns that there might be a config combination in which
BUG_ON() expands to a no-op.  It this situation, `plt' won't get
incremented and we have a bug.

Now, we have taken care to prevent this from happening, via the
implementations of BUG_ON().  But still, mistakes happen and out of an
abundance of caution people avoid statements of the form

	assert(expression-with-side-effects)



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

end of thread, other threads:[~2021-08-23 19:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23  1:51 [PATCH linux-next] arch/ia64/kernel/module.c: fix bugon.cocci warnings CGEL
2021-08-23 19:31 ` Andrew Morton

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