Message ID | 20190708231154.89969-1-natechancellor@gmail.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | net/mlx5e: Return in default case statement in tx_post_resync_params | expand |
On Mon, Jul 8, 2019 at 4:13 PM Nathan Chancellor <natechancellor@gmail.com> wrote: > > clang warns: > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:251:2: > warning: variable 'rec_seq_sz' is used uninitialized whenever switch > default is taken [-Wsometimes-uninitialized] > default: > ^~~~~~~ > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:255:46: note: > uninitialized use occurs here > skip_static_post = !memcmp(rec_seq, &rn_be, rec_seq_sz); > ^~~~~~~~~~ > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:239:16: note: > initialize the variable 'rec_seq_sz' to silence this warning > u16 rec_seq_sz; > ^ > = 0 > 1 warning generated. > > This case statement was clearly designed to be one that should not be > hit during runtime because of the WARN_ON statement so just return early > to prevent copying uninitialized memory up into rn_be. > > Fixes: d2ead1f360e8 ("net/mlx5e: Add kTLS TX HW offload support") > Link: https://github.com/ClangBuiltLinux/linux/issues/590 > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> > --- > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > index 3f5f4317a22b..5c08891806f0 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > @@ -250,6 +250,7 @@ tx_post_resync_params(struct mlx5e_txqsq *sq, > } > default: > WARN_ON(1); > + return; > } hmm...a switch statement with a single case is a code smell. How about a single conditional with early return? Then the "meat" of the happy path doesn't need an additional level of indentation.
On Tue, Jul 09, 2019 at 03:44:59PM -0700, Nick Desaulniers wrote: > On Mon, Jul 8, 2019 at 4:13 PM Nathan Chancellor > <natechancellor@gmail.com> wrote: > > > > clang warns: > > > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:251:2: > > warning: variable 'rec_seq_sz' is used uninitialized whenever switch > > default is taken [-Wsometimes-uninitialized] > > default: > > ^~~~~~~ > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:255:46: note: > > uninitialized use occurs here > > skip_static_post = !memcmp(rec_seq, &rn_be, rec_seq_sz); > > ^~~~~~~~~~ > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:239:16: note: > > initialize the variable 'rec_seq_sz' to silence this warning > > u16 rec_seq_sz; > > ^ > > = 0 > > 1 warning generated. > > > > This case statement was clearly designed to be one that should not be > > hit during runtime because of the WARN_ON statement so just return early > > to prevent copying uninitialized memory up into rn_be. > > > > Fixes: d2ead1f360e8 ("net/mlx5e: Add kTLS TX HW offload support") > > Link: https://github.com/ClangBuiltLinux/linux/issues/590 > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> > > --- > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > > index 3f5f4317a22b..5c08891806f0 100644 > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > > @@ -250,6 +250,7 @@ tx_post_resync_params(struct mlx5e_txqsq *sq, > > } > > default: > > WARN_ON(1); > > + return; > > } > > hmm...a switch statement with a single case is a code smell. How > about a single conditional with early return? Then the "meat" of the > happy path doesn't need an additional level of indentation. > -- > Thanks, > ~Nick Desaulniers I assume that the reason for this is there may be other cipher types added in the future? I suppose the maintainers can give more clarity to that. Furthermore, if they want the switch statements to remain, it looks like fill_static_params_ctx also returns in the default statement so it seems like this is the right fix. Cheers, Nathan
On Tue, Jul 09, 2019 at 04:10:24PM -0700, Nathan Chancellor wrote: > On Tue, Jul 09, 2019 at 03:44:59PM -0700, Nick Desaulniers wrote: > > On Mon, Jul 8, 2019 at 4:13 PM Nathan Chancellor > > <natechancellor@gmail.com> wrote: > > > > > > clang warns: > > > > > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:251:2: > > > warning: variable 'rec_seq_sz' is used uninitialized whenever switch > > > default is taken [-Wsometimes-uninitialized] > > > default: > > > ^~~~~~~ > > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:255:46: note: > > > uninitialized use occurs here > > > skip_static_post = !memcmp(rec_seq, &rn_be, rec_seq_sz); > > > ^~~~~~~~~~ > > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:239:16: note: > > > initialize the variable 'rec_seq_sz' to silence this warning > > > u16 rec_seq_sz; > > > ^ > > > = 0 > > > 1 warning generated. > > > > > > This case statement was clearly designed to be one that should not be > > > hit during runtime because of the WARN_ON statement so just return early > > > to prevent copying uninitialized memory up into rn_be. > > > > > > Fixes: d2ead1f360e8 ("net/mlx5e: Add kTLS TX HW offload support") > > > Link: https://github.com/ClangBuiltLinux/linux/issues/590 > > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> > > > --- > > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > > > index 3f5f4317a22b..5c08891806f0 100644 > > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c > > > @@ -250,6 +250,7 @@ tx_post_resync_params(struct mlx5e_txqsq *sq, > > > } > > > default: > > > WARN_ON(1); > > > + return; > > > } > > > > hmm...a switch statement with a single case is a code smell. How > > about a single conditional with early return? Then the "meat" of the > > happy path doesn't need an additional level of indentation. > > -- > > Thanks, > > ~Nick Desaulniers > > I assume that the reason for this is there may be other cipher types > added in the future? I suppose the maintainers can give more clarity to > that. Our devices supports extra ciphers, for example TLS_CIPHER_AES_GCM_256. So I assume this was the reason for switch<->case, but because such implementation doesn't exist in any driver, I recommend to rewrite the code to have "if" statement and return early. > > Furthermore, if they want the switch statements to remain, it looks like > fill_static_params_ctx also returns in the default statement so it seems > like this is the right fix. > > Cheers, > Nathan
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c index 3f5f4317a22b..5c08891806f0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c @@ -250,6 +250,7 @@ tx_post_resync_params(struct mlx5e_txqsq *sq, } default: WARN_ON(1); + return; } skip_static_post = !memcmp(rec_seq, &rn_be, rec_seq_sz);
clang warns: drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:251:2: warning: variable 'rec_seq_sz' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized] default: ^~~~~~~ drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:255:46: note: uninitialized use occurs here skip_static_post = !memcmp(rec_seq, &rn_be, rec_seq_sz); ^~~~~~~~~~ drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c:239:16: note: initialize the variable 'rec_seq_sz' to silence this warning u16 rec_seq_sz; ^ = 0 1 warning generated. This case statement was clearly designed to be one that should not be hit during runtime because of the WARN_ON statement so just return early to prevent copying uninitialized memory up into rn_be. Fixes: d2ead1f360e8 ("net/mlx5e: Add kTLS TX HW offload support") Link: https://github.com/ClangBuiltLinux/linux/issues/590 Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c | 1 + 1 file changed, 1 insertion(+)