Skip to contentSkip to conversation

qlcnic_dcb.c : possible division by zero.

PATCH In review Ameen Ali 3 participants 3 messages Feb 25, 2015 – Feb 26, 2015

Subsystems (3)
lore
Share & tools
lore

Ameen Ali

author
#0 lore raw

PATCH 6/6 qlcnic_dcb.c : possible division by zero.

Whenever there is a division it is usually worthwhile to add some belt'n'braces code to ensure that cnt != 0, otherwise a machine signal can occur.

---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +1 -1
index a72bcdd..c1d5e48 100644
@@ -822,7 +822,7 @@ qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio,
 		if (temp->valid && (pg == temp->pgid))
 			cnt++;
 	}
-
+	if(cnt != 0)
 	tc_cfg->bwg_percent = (100 / cnt);
 	*bw_per = tc_cfg->bwg_percent;
 }
Signature · 1 line
2.1.0
maintainer
#1 lore raw

From: Ameen Ali <[email protected]>
Date: Wed, 25 Feb 2015 23:56:43 +0200

drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio, · line 826

Quoted 7 lines
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +1 -1
@@ -822,7 +822,7 @@ qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio,
 		if (temp->valid && (pg == temp->pgid))
 			cnt++;
 	}
-
+	if(cnt != 0)
 	tc_cfg->bwg_percent = (100 / cnt);

This is not acceptable.

Your conditional expression is not spaced properly, there must be a space between "if" and the openning parenthesis of the condition.

You also must properly re-indent the statement the new if() condition is protecting.

#2 lore raw
In reply to Ameen Ali

Hello.

Quoted 14 lines · Ameen Ali

Whenever there is a division it is usually worthwhile to add some belt'n'braces code to ensure that cnt != 0, otherwise a machine signal can occur.

---
  drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +0 -0
index a72bcdd..c1d5e48 100644

drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio, · line 825

Quoted 5 lines
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +1 -1
@@ -822,7 +822,7 @@ qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio,
  		if (temp->valid && (pg == temp->pgid))
  			cnt++;
  	}
-
+	if(cnt != 0)

Space needed after *if*. Please run your patches thru
scripts/checkpatch.pl before posting.

drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio, · line 826

Quoted 1 line
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +0 -0
  	tc_cfg->bwg_percent = (100 / cnt);

What happens to 'tc_cfg->bwg_percent' when cnt == 0?
You need to indent this line by an extra TAB, since it's a part of the
*if* statment now.

drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio, · line 828

Quoted 2 lines
drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c +0 -0
  	*bw_per = tc_cfg->bwg_percent;
  }

WBR, Sergei