intel-wired-lan.osuosl.org archive mirror
 help / color / mirror / Atom feed
* [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div() to use u64 arg
@ 2015-04-09 21:45 Jeff Kirsher
  2015-04-09 22:45 ` Alexander Duyck
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Kirsher @ 2015-04-09 21:45 UTC (permalink / raw)
  To: intel-wired-lan

We were using s64 for lat_ns (latency nano-second value) since in
our calculations a negative value could be a resultant.  For negative
values, we then assign lat_ns to be zero, so the value passed to
do_div() was never negative, but do_div() expects the argument type
to be u64, so do a cast to resolve a compile warning seen on
PowerPC.

CC: Yanjiang Jin <yanjiang.jin@windriver.com>
CC: Yanir Lubetkin <yanirx.lubetkin@intel.com>
Reported-by: Yanjiang Jin <yanjiang.jin@windriver.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
v2: fixed the patch to not use a cast to resolve the PowerPC compile
    warning
---
 drivers/net/ethernet/intel/e1000e/ich8lan.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
index 9d81c03..7053863 100644
--- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
+++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
@@ -1015,7 +1015,7 @@ static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
 		u16 max_snoop, max_nosnoop;
 		u16 max_ltr_enc;	/* max LTR latency encoded */
 		s64 lat_ns;	/* latency (ns) */
-		s64 value;
+		u64 value;
 		u32 rxa;
 
 		if (!hw->adapter->max_frame_size) {
@@ -1042,12 +1042,13 @@ static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
 		 */
 		lat_ns = ((s64)rxa * 1024 -
 			  (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
-		if (lat_ns < 0)
-			lat_ns = 0;
-		else
-			do_div(lat_ns, speed);
+		if (lat_ns < 0) {
+			value = 0;
+		} else {
+			value = lat_ns;
+			do_div(value, speed);
+		}
 
-		value = lat_ns;
 		while (value > PCI_LTR_VALUE_MASK) {
 			scale++;
 			value = DIV_ROUND_UP(value, (1 << 5));


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

* [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div() to use u64 arg
  2015-04-09 21:45 [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div() to use u64 arg Jeff Kirsher
@ 2015-04-09 22:45 ` Alexander Duyck
  2015-04-21  3:15   ` Brown, Aaron F
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Duyck @ 2015-04-09 22:45 UTC (permalink / raw)
  To: intel-wired-lan



On 04/09/2015 02:45 PM, Jeff Kirsher wrote:
> We were using s64 for lat_ns (latency nano-second value) since in
> our calculations a negative value could be a resultant.  For negative
> values, we then assign lat_ns to be zero, so the value passed to
> do_div() was never negative, but do_div() expects the argument type
> to be u64, so do a cast to resolve a compile warning seen on
> PowerPC.
>
> CC: Yanjiang Jin <yanjiang.jin@windriver.com>
> CC: Yanir Lubetkin <yanirx.lubetkin@intel.com>
> Reported-by: Yanjiang Jin <yanjiang.jin@windriver.com>
> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> ---
> v2: fixed the patch to not use a cast to resolve the PowerPC compile
>      warning
> ---
>   drivers/net/ethernet/intel/e1000e/ich8lan.c |   13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
> index 9d81c03..7053863 100644
> --- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
> +++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
> @@ -1015,7 +1015,7 @@ static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
>   		u16 max_snoop, max_nosnoop;
>   		u16 max_ltr_enc;	/* max LTR latency encoded */
>   		s64 lat_ns;	/* latency (ns) */
> -		s64 value;
> +		u64 value;
>   		u32 rxa;
>
>   		if (!hw->adapter->max_frame_size) {
> @@ -1042,12 +1042,13 @@ static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
>   		 */
>   		lat_ns = ((s64)rxa * 1024 -
>   			  (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
> -		if (lat_ns < 0)
> -			lat_ns = 0;
> -		else
> -			do_div(lat_ns, speed);
> +		if (lat_ns < 0) {
> +			value = 0;
> +		} else {
> +			value = lat_ns;
> +			do_div(value, speed);
> +		}
>
> -		value = lat_ns;
>   		while (value > PCI_LTR_VALUE_MASK) {
>   			scale++;
>   			value = DIV_ROUND_UP(value, (1 << 5));


Honestly the whole signed/unsigned thing is kind of a waste anyway.  You 
could probably rewrite it to something like this and drop lat_ns entirely.

rxa *= 512;
value = (rxa > hw->adapter->max_frame_size) ?
	(rxa - hw->adapter->max_frame_size) * (16000 / speed) : 0;

That should give you the same result without any need for the do_div or 
the signed values.

- Alex

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

* [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div() to use u64 arg
  2015-04-09 22:45 ` Alexander Duyck
@ 2015-04-21  3:15   ` Brown, Aaron F
  2015-04-21  8:04     ` Jeff Kirsher
  0 siblings, 1 reply; 4+ messages in thread
From: Brown, Aaron F @ 2015-04-21  3:15 UTC (permalink / raw)
  To: intel-wired-lan

> From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On
> Behalf Of Alexander Duyck
> Sent: Thursday, April 09, 2015 3:45 PM
> To: Kirsher, Jeffrey T; intel-wired-lan at lists.osuosl.org
> Cc: david.laight at aculab.com; Jin, Yanjiang (Wind River)
> Subject: Re: [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div()
> to use u64 arg
> 
> 
> 
> On 04/09/2015 02:45 PM, Jeff Kirsher wrote:
> > We were using s64 for lat_ns (latency nano-second value) since in
> > our calculations a negative value could be a resultant.  For negative
> > values, we then assign lat_ns to be zero, so the value passed to
> > do_div() was never negative, but do_div() expects the argument type
> > to be u64, so do a cast to resolve a compile warning seen on
> > PowerPC.
> >
> > CC: Yanjiang Jin <yanjiang.jin@windriver.com>
> > CC: Yanir Lubetkin <yanirx.lubetkin@intel.com>
> > Reported-by: Yanjiang Jin <yanjiang.jin@windriver.com>
> > Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
> > ---
> > v2: fixed the patch to not use a cast to resolve the PowerPC compile
> >      warning
> > ---
> >   drivers/net/ethernet/intel/e1000e/ich8lan.c |   13 +++++++------
> >   1 file changed, 7 insertions(+), 6 deletions(-)

<snip>
> 
> Honestly the whole signed/unsigned thing is kind of a waste anyway.  You
> could probably rewrite it to something like this and drop lat_ns entirely.
> 
> rxa *= 512;
> value = (rxa > hw->adapter->max_frame_size) ?
> 	(rxa - hw->adapter->max_frame_size) * (16000 / speed) : 0;
> 
> That should give you the same result without any need for the do_div or
> the signed values.
> 
> - Alex

Anyone want to take a stab at striking out the signed / unsigned thing per Alex's suggestion?

Meanwhile I've run tons of tests with this in the queue and don't want to old things up, so...

Tested-by: Aaron Brown <aaron.f.brown@intel.com>

> _______________________________________________
> Intel-wired-lan mailing list
> Intel-wired-lan at lists.osuosl.org
> http://lists.osuosl.org/mailman/listinfo/intel-wired-lan

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

* [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div() to use u64 arg
  2015-04-21  3:15   ` Brown, Aaron F
@ 2015-04-21  8:04     ` Jeff Kirsher
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Kirsher @ 2015-04-21  8:04 UTC (permalink / raw)
  To: intel-wired-lan

On Mon, 2015-04-20 at 20:15 -0700, Brown, Aaron F wrote:
> > 
> > Honestly the whole signed/unsigned thing is kind of a waste anyway.
> You
> > could probably rewrite it to something like this and drop lat_ns
> entirely.
> > 
> > rxa *= 512;
> > value = (rxa > hw->adapter->max_frame_size) ?
> >       (rxa - hw->adapter->max_frame_size) * (16000 / speed) : 0;
> > 
> > That should give you the same result without any need for the do_div
> or
> > the signed values.
> > 
> > - Alex
> 
> Anyone want to take a stab at striking out the signed / unsigned thing
> per Alex's suggestion?
> 
> Meanwhile I've run tons of tests with this in the queue and don't want
> to old things up, so...
> 
> Tested-by: Aaron Brown <aaron.f.brown@intel.com>

Yeah, I will be working on a follow on patch to implement Alex's
suggestions.  For now, I wanted to go forward with this change to
resolve the compile warning.  I should have a patch later this week to
implement Alex's suggestions, unless Yanir gets to it before me. :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20150421/4d60ed61/attachment.asc>

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

end of thread, other threads:[~2015-04-21  8:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-09 21:45 [Intel-wired-lan] [net-next v2] e1000e: fix call to do_div() to use u64 arg Jeff Kirsher
2015-04-09 22:45 ` Alexander Duyck
2015-04-21  3:15   ` Brown, Aaron F
2015-04-21  8:04     ` Jeff Kirsher

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