netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH NET] ethtool: silence warning on bit loss
@ 2016-10-13 23:13 Jesse Brandeburg
  2016-10-14  9:26 ` David Laight
  2016-10-14 20:06 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Jesse Brandeburg @ 2016-10-13 23:13 UTC (permalink / raw)
  To: netdev

Sparse was complaining when we went to prototype some code
using ethtool_cmd_speed_set and SPEED_100000, which uses
the upper 16 bits of __u32 speed for the first time.

CHECK
...
.../uapi/linux/ethtool.h:123:28: warning:
  cast truncates bits from constant value (186a0 becomes 86a0)

The warning is actually bogus, as no bits are really lost, but
we can get rid of the sparse warning with this one small change.

Reported-by: Preethi Banala <preethi.banala@intel.com>
Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 include/uapi/linux/ethtool.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index 099a420..8e54723 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -119,8 +119,7 @@ struct ethtool_cmd {
 static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
 					 __u32 speed)
 {
-
-	ep->speed = (__u16)speed;
+	ep->speed = (__u16)(speed & 0xFFFF);
 	ep->speed_hi = (__u16)(speed >> 16);
 }
 
-- 
1.8.3.1

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

* RE: [PATCH NET] ethtool: silence warning on bit loss
  2016-10-13 23:13 [PATCH NET] ethtool: silence warning on bit loss Jesse Brandeburg
@ 2016-10-14  9:26 ` David Laight
  2016-10-14 20:06 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2016-10-14  9:26 UTC (permalink / raw)
  To: 'Jesse Brandeburg', netdev@vger.kernel.org

From: Jesse Brandeburg
> Sent: 14 October 2016 00:14
> Sparse was complaining when we went to prototype some code
> using ethtool_cmd_speed_set and SPEED_100000, which uses
> the upper 16 bits of __u32 speed for the first time.
...
> Reported-by: Preethi Banala <preethi.banala@intel.com>
> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
> ---
>  include/uapi/linux/ethtool.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
> index 099a420..8e54723 100644
> --- a/include/uapi/linux/ethtool.h
> +++ b/include/uapi/linux/ethtool.h
> @@ -119,8 +119,7 @@ struct ethtool_cmd {
>  static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
>  					 __u32 speed)
>  {
> -
> -	ep->speed = (__u16)speed;
> +	ep->speed = (__u16)(speed & 0xFFFF);
>  	ep->speed_hi = (__u16)(speed >> 16);

I suspect that deleting both (__u16) casts also fixes it?

	David

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

* Re: [PATCH NET] ethtool: silence warning on bit loss
  2016-10-13 23:13 [PATCH NET] ethtool: silence warning on bit loss Jesse Brandeburg
  2016-10-14  9:26 ` David Laight
@ 2016-10-14 20:06 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-10-14 20:06 UTC (permalink / raw)
  To: jesse.brandeburg; +Cc: netdev

From: Jesse Brandeburg <jesse.brandeburg@intel.com>
Date: Thu, 13 Oct 2016 16:13:55 -0700

> Sparse was complaining when we went to prototype some code
> using ethtool_cmd_speed_set and SPEED_100000, which uses
> the upper 16 bits of __u32 speed for the first time.
> 
> CHECK
> ...
> .../uapi/linux/ethtool.h:123:28: warning:
>   cast truncates bits from constant value (186a0 becomes 86a0)
> 
> The warning is actually bogus, as no bits are really lost, but
> we can get rid of the sparse warning with this one small change.
> 
> Reported-by: Preethi Banala <preethi.banala@intel.com>
> Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>

Ok, I'll apply this.

There were alternative suggestions but I like this patch
because it makes it explicit what is going on.

Just removing the u16 cast requires the reader to implicitly
understand and know the types in the structure.

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

end of thread, other threads:[~2016-10-14 20:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-13 23:13 [PATCH NET] ethtool: silence warning on bit loss Jesse Brandeburg
2016-10-14  9:26 ` David Laight
2016-10-14 20:06 ` 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).