netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6/6] qlcnic_dcb.c : possible division by zero.
@ 2015-02-25 21:56 Ameen Ali
  2015-02-25 22:01 ` David Miller
  2015-02-26 14:22 ` Sergei Shtylyov
  0 siblings, 2 replies; 4+ messages in thread
From: Ameen Ali @ 2015-02-25 21:56 UTC (permalink / raw)
  To: shahed.shaikh, Dept-GELinuxNICDev; +Cc: linux-kernel, netdev, 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.

Signed-off-by : Ameen Ali <Ameenali023@gmail.com>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
index a72bcdd..c1d5e48 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
@@ -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;
 }
-- 
2.1.0

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

* Re: [PATCH 6/6] qlcnic_dcb.c : possible division by zero.
  2015-02-25 21:56 Ameen Ali
@ 2015-02-25 22:01 ` David Miller
  2015-02-26 14:22 ` Sergei Shtylyov
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-02-25 22:01 UTC (permalink / raw)
  To: ameenali023; +Cc: shahed.shaikh, Dept-GELinuxNICDev, linux-kernel, netdev

From: Ameen Ali <ameenali023@gmail.com>
Date: Wed, 25 Feb 2015 23:56:43 +0200

> @@ -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.

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

* [PATCH 6/6] qlcnic_dcb.c : possible division by zero.
@ 2015-02-25 22:05 Ameen Ali
  0 siblings, 0 replies; 4+ messages in thread
From: Ameen Ali @ 2015-02-25 22:05 UTC (permalink / raw)
  To: shahed.shaikh, Dept-GELinuxNICDev; +Cc: linux-kernel, netdev, 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.

Signed-off-by : Ameen Ali <Ameenali023@gmail.com>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
index a72bcdd..c1d5e48 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
@@ -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;
 }
-- 
2.1.0

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

* Re: [PATCH 6/6] qlcnic_dcb.c : possible division by zero.
  2015-02-25 21:56 Ameen Ali
  2015-02-25 22:01 ` David Miller
@ 2015-02-26 14:22 ` Sergei Shtylyov
  1 sibling, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2015-02-26 14:22 UTC (permalink / raw)
  To: Ameen Ali, shahed.shaikh, Dept-GELinuxNICDev; +Cc: linux-kernel, netdev

Hello.

On 02/26/2015 12:56 AM, Ameen Ali wrote:

> 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.

> Signed-off-by : Ameen Ali <Ameenali023@gmail.com>
> ---
>   drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
> index a72bcdd..c1d5e48 100644
> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
> @@ -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.

>   	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.

>   	*bw_per = tc_cfg->bwg_percent;
>   }

WBR, Sergei

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

end of thread, other threads:[~2015-02-26 14:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-25 22:05 [PATCH 6/6] qlcnic_dcb.c : possible division by zero Ameen Ali
  -- strict thread matches above, loose matches on Subject: below --
2015-02-25 21:56 Ameen Ali
2015-02-25 22:01 ` David Miller
2015-02-26 14:22 ` Sergei Shtylyov

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).