diff mbox

[OPW,kernel] staging:rtl8187se: Fix sparse warning restricted __le16 degrades to integer

Message ID 20140304160105.GA18577@himangi-Inspiron-N5110gmail.com
State New, archived
Headers show

Commit Message

HIMANGI SARAOGI March 4, 2014, 4:01 p.m. UTC
This patch fixes the following sparse warning in r8180_core.c - warning:
restricted __le16 degrades to integer.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
---
 drivers/staging/rtl8187se/r8180_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bob Copeland March 4, 2014, 6:02 p.m. UTC | #1
On Tue, Mar 04, 2014 at 09:31:05PM +0530, Himangi Saraogi wrote:
> This patch fixes the following sparse warning in r8180_core.c - warning:
> restricted __le16 degrades to integer.

> -	short morefrag = (h->frame_control) & IEEE80211_FCTL_MOREFRAGS;
> +	short morefrag = le16_to_cpu(h->frame_control) & IEEE80211_FCTL_MOREFRAGS;

This is fine, but it would be good to also change the type of
morefrag to bool, as that is how it is used here.  The reason is
there are often hard to spot bugs of the form:

    u8 is_set;
    int some_val = 0x100;
    int some_bit = BIT(8);

    is_set = some_val & some_bit;
    if (is_set) {
        /* oops, overflow caused this not to happen.. */
    }

One way to fix it is to use instead:

    is_set = !!(some_val & some_bit);

This forces the test into the range 0-1 which will fit in a char.
Another way is to make is_set type bool.
diff mbox

Patch

diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index 6cafee2..d76f00a 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -1539,7 +1539,7 @@  static void rtl8180_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
 	int mode;
 	struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
-	short morefrag = (h->frame_control) & IEEE80211_FCTL_MOREFRAGS;
+	short morefrag = le16_to_cpu(h->frame_control) & IEEE80211_FCTL_MOREFRAGS;
 	unsigned long flags;
 	int priority;
 
@@ -1807,7 +1807,7 @@  short rtl8180_tx(struct net_device *dev, u8 *txbuf, int len, int priority,
 				TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
 			}
 
-			if (!(frag_hdr->frame_control & IEEE80211_FCTL_MOREFRAGS)) {
+			if (!(le16_to_cpu(frag_hdr->frame_control) & IEEE80211_FCTL_MOREFRAGS)) {
 				/* ThisFrame-ACK. */
 				Duration = aSifsTime + AckTime;
 			} else { /* One or more fragments remained. */