]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
batman-adv: Annotate bitwise integer pointer casts
authorSven Eckelmann <sven@narfation.org>
Thu, 28 Nov 2019 10:26:06 +0000 (11:26 +0100)
committerSimon Wunderlich <sw@simonwunderlich.de>
Sun, 8 Dec 2019 23:30:49 +0000 (00:30 +0100)
The sparse commit 6002ded74587 ("add a flag to warn on casts to/from
bitwise pointers") introduced a check for non-direct casts from/to
restricted datatypes (when -Wbitwise-pointer is enabled).

This triggered various warnings in batman-adv when some (already big
endian) buffer content was casted to/from the corresponding big endian
integer data types. But these were correct and can therefore be marked with
__force to signalize sparse an intended cast from/to a bitwise type.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/bridge_loop_avoidance.c
net/batman-adv/distributed-arp-table.c

index 663a53b6d36e65508b4296d86cecdd808c653836..0eff33580f95d488f9ec56286cf8c61a7bba68eb 100644 (file)
@@ -844,7 +844,7 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
 
        /* handle as ANNOUNCE frame */
        backbone_gw->lasttime = jiffies;
-       crc = ntohs(*((__be16 *)(&an_addr[4])));
+       crc = ntohs(*((__force __be16 *)(&an_addr[4])));
 
        batadv_dbg(BATADV_DBG_BLA, bat_priv,
                   "%s(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n",
index b0af3a11d4069cb7e44419d4494f20dd653dbca8..5004e38fe792388a812dd769cc4ffbebc7070bba 100644 (file)
@@ -246,7 +246,7 @@ static u8 *batadv_arp_hw_src(struct sk_buff *skb, int hdr_size)
  */
 static __be32 batadv_arp_ip_src(struct sk_buff *skb, int hdr_size)
 {
-       return *(__be32 *)(batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN);
+       return *(__force __be32 *)(batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN);
 }
 
 /**
@@ -270,7 +270,9 @@ static u8 *batadv_arp_hw_dst(struct sk_buff *skb, int hdr_size)
  */
 static __be32 batadv_arp_ip_dst(struct sk_buff *skb, int hdr_size)
 {
-       return *(__be32 *)(batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN * 2 + 4);
+       u8 *dst = batadv_arp_hw_src(skb, hdr_size) + ETH_ALEN * 2 + 4;
+
+       return *(__force __be32 *)dst;
 }
 
 /**
@@ -287,7 +289,7 @@ static u32 batadv_hash_dat(const void *data, u32 size)
        const unsigned char *key;
        u32 i;
 
-       key = (const unsigned char *)&dat->ip;
+       key = (__force const unsigned char *)&dat->ip;
        for (i = 0; i < sizeof(dat->ip); i++) {
                hash += key[i];
                hash += (hash << 10);