bnx2x: fix assignment of signed expression to unsigned variable
PATCH 1/1 bnx2x: fix assignment of signed expression to unsigned variable
fix for incorrect assignment of signed expression to unsigned variable.
--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +10 -10
@@ -2139,12 +2139,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)break ;default :BNX2X_ERR ("Non valid capability ID\n" ); - rval = -EINVAL ; + rval =EINVAL ;break ; } }else {DP (BNX2X_MSG_DCB ,"DCB disabled\n" ); - rval = -EINVAL ; + rval =EINVAL ; }DP (BNX2X_MSG_DCB ,"capid %d:%x\n" , capid, *cap);
@@ -2154,7 +2154,7 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)static int bnx2x_dcbnl_get_numtcs (struct net_device *netdev,int tcid,u8 *num) {struct bnx2x *bp =netdev_priv (netdev); -u8 rval =0 ; +s8 rval =0 ;DP (BNX2X_MSG_DCB ,"tcid %d\n" , tcid);
@@ -2188,7 +2188,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)return -EINVAL ; } -static u8 bnx2x_dcbnl_get_pfc_state (struct net_device *netdev) +static u8 bnx2x_dcbnl_get_pfc_state (struct net_device *netdev) {struct bnx2x *bp =netdev_priv (netdev);DP (BNX2X_MSG_DCB ,"state = %d\n" , bp->dcbx_local_feat.pfc.enabled);
@@ -2282,7 +2282,7 @@ static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)else {/* app table is full */ BNX2X_ERR ("Application table is too large\n" ); -return -EBUSY ; +return EBUSY ; }/* up configured, if not 0 make sure feature is enabled */
@@ -2312,7 +2312,7 @@ static u8 bnx2x_dcbnl_set_app_up(struct net_device *netdev, u8 idtype,break ;default :DP (BNX2X_MSG_DCB ,"Wrong ID type\n" ); -return -EINVAL ; +return EINVAL ; }return bnx2x_set_admin_app_up (bp, idtype, idval, up); }
@@ -2390,12 +2390,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,break ;default :BNX2X_ERR ("Non valid featrue-ID\n" ); - rval = -EINVAL ; + rval =EINVAL ;break ; } }else {DP (BNX2X_MSG_DCB ,"DCB disabled\n" ); - rval = -EINVAL ; + rval =EINVAL ; }return rval;
@@ -2431,12 +2431,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,break ;default :BNX2X_ERR ("Non valid featrue-ID\n" ); - rval = -EINVAL ; + rval =EINVAL ;break ; } }else {DP (BNX2X_MSG_DCB ,"dcbnl call not valid\n" ); - rval = -EINVAL ; + rval =EINVAL ; }return rval;
Signature · 1 line
1.7.9.5
Quoted 2 lines · Kumar Amit Mehta
fix for incorrect assignment of signed expression to unsigned variable.
This fix isn't right.
Quoted 11 lines
Signed-off-by Kumar Amit Mehta <[email protected]>--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +0
-0@@ -2139,12 +2139,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)break ;
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap) · line 2147
Quoted 10 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +2
-2default :BNX2X_ERR ("Non valid capability ID\n" ); - rval = -EINVAL ; + rval =EINVAL ;break ; } }else {DP (BNX2X_MSG_DCB ,"DCB disabled\n" ); - rval = -EINVAL ; + rval =EINVAL ;
This function is called from dcbnl_getcap(). It returns zero on success, but it's not clear what it should return on failure. But certainly it's not a positive EINVAL.
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap) · line 2157
Quoted 9 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +1
-1}DP (BNX2X_MSG_DCB ,"capid %d:%x\n" , capid, *cap);@@ -2154,7 +2154,7 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)static int bnx2x_dcbnl_get_numtcs (struct net_device *netdev,int tcid,u8 *num) {struct bnx2x *bp =netdev_priv (netdev); -u8 rval =0 ; +s8 rval =0 ;
Just use "int" here.
Quoted 13 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +1
-1DP (BNX2X_MSG_DCB ,"tcid %d\n" , tcid);@@ -2188,7 +2188,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)return -EINVAL ; } -static u8 bnx2x_dcbnl_get_pfc_state (struct net_device *netdev) +static u8 bnx2x_dcbnl_get_pfc_state (struct net_device *netdev) {struct bnx2x *bp =netdev_priv (netdev);DP (BNX2X_MSG_DCB ,"state = %d\n" , bp->dcbx_local_feat.pfc.enabled);
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up) · line 2286
Quoted 6 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +1
-1@@ -2282,7 +2282,7 @@ static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)else {/* app table is full */ BNX2X_ERR ("Application table is too large\n" ); -return -EBUSY ; +return EBUSY ; }
The fix for this is more involved. The function prototype should be changed to return an int. The caller should be updated to check for errors.
Etc.
regards,
dan carpenter
Quoted 51 lines · Dan Carpenter
Quoted 2 lines · Kumar Amit Mehta
fix for incorrect assignment of signed expression to unsigned variable.
This fix isn't right.
Quoted 11 lines
Signed-off-by Kumar Amit Mehta <[email protected]>--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +0
-0@@ -2139,12 +2139,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)break ;drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap) · line 2147
Quoted 10 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +2
-2default :BNX2X_ERR ("Non valid capability ID\n" ); - rval = -EINVAL ; + rval =EINVAL ;break ; } }else {DP (BNX2X_MSG_DCB ,"DCB disabled\n" ); - rval = -EINVAL ; + rval =EINVAL ;This function is called from
dcbnl_getcap(). It returns zero on success, but it's not clear what it should return on failure. But certainly it's not a positive EINVAL.drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap) · line 2157
Quoted 9 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +1
-1}DP (BNX2X_MSG_DCB ,"capid %d:%x\n" , capid, *cap);@@ -2154,7 +2154,7 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)static int bnx2x_dcbnl_get_numtcs (struct net_device *netdev,int tcid,u8 *num) {struct bnx2x *bp =netdev_priv (netdev); -u8 rval =0 ; +s8 rval =0 ;Just use "int" here.
Quoted 7 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +0
-0DP (BNX2X_MSG_DCB ,"tcid %d\n" , tcid);@@ -2188,7 +2188,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)return -EINVAL ; }
Quoted 17 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up) · line 2286
Quoted 12 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c +2
-2-static u8 bnx2x_dcbnl_get_pfc_state (struct net_device *netdev) +static u8 bnx2x_dcbnl_get_pfc_state (struct net_device *netdev) {struct bnx2x *bp =netdev_priv (netdev);DP (BNX2X_MSG_DCB ,"state = %d\n" , bp->dcbx_local_feat.pfc.enabled);@@ -2282,7 +2282,7 @@ static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)else {/* app table is full */ BNX2X_ERR ("Application table is too large\n" ); -return -EBUSY ; +return EBUSY ; }The fix for this is more involved. The function prototype should be changed to return an int. The caller should be updated to check for errors.
I wonder, why these callbacks are restricting the lower layers to return only unsigned values, However Updating the prototype doesn't seem a good idea as then it would require changes in various existing drivers.
Quoted 9 lines · Kumar amit mehta
Quoted 5 lines · Dan Carpenter
The fix for this is more involved. The function prototype should be changed to return an int. The caller should be updated to check for errors.
I wonder, why these callbacks are restricting the lower layers to return only unsigned values, However Updating the prototype doesn't seem a good idea as then it would require changes in various existing drivers.
Yes. Everything will need to be updated. I've known this code is buggy for years but I've never tried patching it because I'm very lazy. :)
But actually it's only three drivers I think: bnx2x, ixgbe, and
mlx4. I suspect that most of the functions always return zero and
won't need to be modified.
regards,
dan carpenter
David Miller
maintainerFrom: Kumar Amit Mehta <[email protected]>
Date: Sat, 23 Mar 2013 11:52:55 -0700
Quoted 3 lines
fix for incorrect assignment of signed expression to unsigned variable.
Signed-off-by Kumar Amit Mehta <[email protected]>
Returning positive error codes is just as broken as what is there currently.
These routines should return 0 or 1, the return value isn't even used in any way, it is just tested against zero.