* [PATCH net-next] bnxt_en: Remove unnecessary unsigned integer comparison and initialize variable
@ 2018-10-05 20:12 Gustavo A. R. Silva
2018-10-08 3:37 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2018-10-05 20:12 UTC (permalink / raw)
To: Michael Chan, David S. Miller; +Cc: netdev, linux-kernel, Gustavo A. R. Silva
There is no need to compare *val.vu32* with < 0 because
such variable is of type u32 (32 bits, unsigned), making it
impossible to hold a negative value. Fix this by removing
such comparison.
Also, initialize variable *max_val* to -1, just in case
it is not initialized to either BNXT_MSIX_VEC_MAX or
BNXT_MSIX_VEC_MIN_MAX before using it in a comparison
with val.vu32 at line 159:
if (val.vu32 > max_val)
Addresses-Coverity-ID: 1473915 ("Unsigned compared against 0")
Addresses-Coverity-ID: 1473920 ("Uninitialized scalar variable")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
index 8a10e01..140dbd6 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
@@ -148,7 +148,7 @@ static int bnxt_dl_msix_validate(struct devlink *dl, u32 id,
union devlink_param_value val,
struct netlink_ext_ack *extack)
{
- int max_val;
+ int max_val = -1;
if (id == DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX)
max_val = BNXT_MSIX_VEC_MAX;
@@ -156,7 +156,7 @@ static int bnxt_dl_msix_validate(struct devlink *dl, u32 id,
if (id == DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN)
max_val = BNXT_MSIX_VEC_MIN_MAX;
- if (val.vu32 < 0 || val.vu32 > max_val) {
+ if (val.vu32 > max_val) {
NL_SET_ERR_MSG_MOD(extack, "MSIX value is exceeding the range");
return -EINVAL;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] bnxt_en: Remove unnecessary unsigned integer comparison and initialize variable
2018-10-05 20:12 [PATCH net-next] bnxt_en: Remove unnecessary unsigned integer comparison and initialize variable Gustavo A. R. Silva
@ 2018-10-08 3:37 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-10-08 3:37 UTC (permalink / raw)
To: gustavo; +Cc: michael.chan, netdev, linux-kernel
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Date: Fri, 5 Oct 2018 22:12:09 +0200
> There is no need to compare *val.vu32* with < 0 because
> such variable is of type u32 (32 bits, unsigned), making it
> impossible to hold a negative value. Fix this by removing
> such comparison.
>
> Also, initialize variable *max_val* to -1, just in case
> it is not initialized to either BNXT_MSIX_VEC_MAX or
> BNXT_MSIX_VEC_MIN_MAX before using it in a comparison
> with val.vu32 at line 159:
>
> if (val.vu32 > max_val)
>
> Addresses-Coverity-ID: 1473915 ("Unsigned compared against 0")
> Addresses-Coverity-ID: 1473920 ("Uninitialized scalar variable")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-08 3:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-05 20:12 [PATCH net-next] bnxt_en: Remove unnecessary unsigned integer comparison and initialize variable Gustavo A. R. Silva
2018-10-08 3:37 ` David Miller
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).