mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] chelsio: use BUG() instead of BUG_ON(1)
@ 2019-03-25 12:49 Arnd Bergmann
  2019-03-25 17:31 ` Nick Desaulniers
  2019-03-26 18:42 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-03-25 12:49 UTC (permalink / raw)
  To: Vishal Kulkarni, David S. Miller
  Cc: clang-built-linux, Nick Desaulniers, Nathan Chancellor,
	Arnd Bergmann, Ganesh Goudar, Casey Leedom, Rahul Lakkireddy,
	Arjun Vynipadath, netdev, linux-kernel

clang warns about possible bugs in a dead code branch after
BUG_ON(1) when CONFIG_PROFILE_ALL_BRANCHES is enabled:

 drivers/net/ethernet/chelsio/cxgb4/sge.c:479:3: error: variable 'buf_size' is used uninitialized whenever 'if'
      condition is false [-Werror,-Wsometimes-uninitialized]
                BUG_ON(1);
                ^~~~~~~~~
 include/asm-generic/bug.h:61:36: note: expanded from macro 'BUG_ON'
 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                   ^~~~~~~~~~~~~~~~~~~
 include/linux/compiler.h:48:23: note: expanded from macro 'unlikely'
 #  define unlikely(x)   (__branch_check__(x, 0, __builtin_constant_p(x)))
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 drivers/net/ethernet/chelsio/cxgb4/sge.c:482:9: note: uninitialized use occurs here
        return buf_size;
               ^~~~~~~~
 drivers/net/ethernet/chelsio/cxgb4/sge.c:479:3: note: remove the 'if' if its condition is always true
                BUG_ON(1);
                ^
 include/asm-generic/bug.h:61:32: note: expanded from macro 'BUG_ON'
 #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                               ^
 drivers/net/ethernet/chelsio/cxgb4/sge.c:459:14: note: initialize the variable 'buf_size' to silence this warning
        int buf_size;
                    ^
                     = 0

Use BUG() here to create simpler code that clang understands
correctly.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 +-
 drivers/net/ethernet/chelsio/cxgb4/sge.c           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
index 3130b43bba52..02959035ed3f 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
@@ -2620,7 +2620,7 @@ static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
 	}
 
 	/* should never happen! */
-	BUG_ON(1);
+	BUG();
 	return NULL;
 }
 
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index 88773ca58e6b..b3da81e90132 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -476,7 +476,7 @@ static inline int get_buf_size(struct adapter *adapter,
 		break;
 
 	default:
-		BUG_ON(1);
+		BUG();
 	}
 
 	return buf_size;
-- 
2.20.0


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

* Re: [PATCH] chelsio: use BUG() instead of BUG_ON(1)
  2019-03-25 12:49 [PATCH] chelsio: use BUG() instead of BUG_ON(1) Arnd Bergmann
@ 2019-03-25 17:31 ` Nick Desaulniers
  2019-03-26 18:42 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2019-03-25 17:31 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Vishal Kulkarni, David S. Miller, clang-built-linux,
	Nathan Chancellor, Ganesh Goudar, Casey Leedom, Rahul Lakkireddy,
	Arjun Vynipadath, netdev, LKML

On Mon, Mar 25, 2019 at 5:49 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> clang warns about possible bugs in a dead code branch after
> BUG_ON(1) when CONFIG_PROFILE_ALL_BRANCHES is enabled:
>
>  drivers/net/ethernet/chelsio/cxgb4/sge.c:479:3: error: variable 'buf_size' is used uninitialized whenever 'if'
>       condition is false [-Werror,-Wsometimes-uninitialized]
>                 BUG_ON(1);
>                 ^~~~~~~~~
>  include/asm-generic/bug.h:61:36: note: expanded from macro 'BUG_ON'
>  #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
>                                    ^~~~~~~~~~~~~~~~~~~
>  include/linux/compiler.h:48:23: note: expanded from macro 'unlikely'
>  #  define unlikely(x)   (__branch_check__(x, 0, __builtin_constant_p(x)))
>                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  drivers/net/ethernet/chelsio/cxgb4/sge.c:482:9: note: uninitialized use occurs here
>         return buf_size;
>                ^~~~~~~~
>  drivers/net/ethernet/chelsio/cxgb4/sge.c:479:3: note: remove the 'if' if its condition is always true
>                 BUG_ON(1);
>                 ^
>  include/asm-generic/bug.h:61:32: note: expanded from macro 'BUG_ON'
>  #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
>                                ^
>  drivers/net/ethernet/chelsio/cxgb4/sge.c:459:14: note: initialize the variable 'buf_size' to silence this warning
>         int buf_size;
>                     ^
>                      = 0
>
> Use BUG() here to create simpler code that clang understands
> correctly.

This is more concise and better expresses what we want to do here.
Thanks for the patch.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 +-
>  drivers/net/ethernet/chelsio/cxgb4/sge.c           | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> index 3130b43bba52..02959035ed3f 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
> @@ -2620,7 +2620,7 @@ static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
>         }
>
>         /* should never happen! */
> -       BUG_ON(1);
> +       BUG();
>         return NULL;
>  }
>
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
> index 88773ca58e6b..b3da81e90132 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
> @@ -476,7 +476,7 @@ static inline int get_buf_size(struct adapter *adapter,
>                 break;
>
>         default:
> -               BUG_ON(1);
> +               BUG();
>         }
>
>         return buf_size;
> --
> 2.20.0
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] chelsio: use BUG() instead of BUG_ON(1)
  2019-03-25 12:49 [PATCH] chelsio: use BUG() instead of BUG_ON(1) Arnd Bergmann
  2019-03-25 17:31 ` Nick Desaulniers
@ 2019-03-26 18:42 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-03-26 18:42 UTC (permalink / raw)
  To: arnd
  Cc: vishal, clang-built-linux, ndesaulniers, natechancellor,
	ganeshgr, leedom, rahul.lakkireddy, arjun, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Mon, 25 Mar 2019 13:49:16 +0100

> clang warns about possible bugs in a dead code branch after
> BUG_ON(1) when CONFIG_PROFILE_ALL_BRANCHES is enabled:
 ...
> Use BUG() here to create simpler code that clang understands
> correctly.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

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

end of thread, other threads:[~2019-03-26 18:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 12:49 [PATCH] chelsio: use BUG() instead of BUG_ON(1) Arnd Bergmann
2019-03-25 17:31 ` Nick Desaulniers
2019-03-26 18:42 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®