ipv6: Annotate bitwise IPv6 dsfield pointer cast
Subsystems (3)
PATCH 1/2 ipv6: Annotate bitwise IPv6 dsfield pointer cast
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 a warning in ipv6_get_dsfield() because sparse doesn't know that the buffer already points to some data in the correct bitwise integer format. This was already fixed in ipv6_change_dsfield() by the __force attribute and can be fixed here the same way.
--- include/net/dsfield.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/dsfield.h +1 -1
@@ -21,7 +21,7 @@ static inline __u8 ipv4_get_dsfield(const struct iphdr *iph)static inline __u8 ipv6_get_dsfield (const struct ipv6hdr *ipv6h) { -return ntohs (*(const __be16 *)ipv6h) >>4 ; +return ntohs (*(__force const __be16 *)ipv6h) >>4 ; }
Signature · 1 line
2.20.1
PATCH 2/2 ipv6: Annotate ipv6_addr_is_* bitwise pointer casts
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 a warning in the 64 bit optimized ipv6_addr_is_*() functions because sparse doesn't know that the buffer already points to some data in the correct bitwise integer format. But these were correct and can therefore be marked with __force to signalize sparse an intended cast to a specific bitwise type.
--- include/net/addrconf.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/net/addrconf.h +4 -4
@@ -437,7 +437,7 @@ static inline void addrconf_addr_solict_mult(const struct in6_addr *addr,static inline bool ipv6_addr_is_ll_all_nodes (const struct in6_addr *addr) {#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64 -__be64 *p = (__be64 *)addr; +__be64 *p = (__force __be64 *)addr;return ((p[0 ] ^cpu_to_be64 (0xff02000000000000UL )) | (p[1 ] ^cpu_to_be64 (1 ))) ==0UL ;#else return ((addr->s6_addr32[0] ^ htonl(0xff020000)) |
@@ -449,7 +449,7 @@ static inline bool ipv6_addr_is_ll_all_nodes(const struct in6_addr *addr)static inline bool ipv6_addr_is_ll_all_routers (const struct in6_addr *addr) {#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64 -__be64 *p = (__be64 *)addr; +__be64 *p = (__force __be64 *)addr;return ((p[0 ] ^cpu_to_be64 (0xff02000000000000UL )) | (p[1 ] ^cpu_to_be64 (2 ))) ==0UL ;#else return ((addr->s6_addr32[0] ^ htonl(0xff020000)) |
@@ -466,7 +466,7 @@ static inline bool ipv6_addr_is_isatap(const struct in6_addr *addr)static inline bool ipv6_addr_is_solict_mult (const struct in6_addr *addr) {#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64 -__be64 *p = (__be64 *)addr; +__be64 *p = (__force __be64 *)addr;return ((p[0 ] ^cpu_to_be64 (0xff02000000000000UL )) | ((p[1 ] ^cpu_to_be64 (0x00000001ff000000UL )) &cpu_to_be64 (0xffffffffff000000UL ))) ==0UL ;
@@ -481,7 +481,7 @@ static inline bool ipv6_addr_is_solict_mult(const struct in6_addr *addr)static inline bool ipv6_addr_is_all_snoopers (const struct in6_addr *addr) {#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64 -__be64 *p = (__be64 *)addr; +__be64 *p = (__force __be64 *)addr;return ((p[0 ] ^cpu_to_be64 (0xff02000000000000UL )) | (p[1 ] ^cpu_to_be64 (0x6a ))) ==0UL ;
Signature · 1 line
2.20.1
Re: [PATCH 2/2] ipv6: Annotate ipv6_addr_is_* bitwise pointer casts
From: Sven Eckelmann <[email protected]>
Date: Fri, 13 Dec 2019 21:24:28 +0100
Quoted 11 lines
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 a warning in the 64 bit optimized ipv6_addr_is_*() functions because sparse doesn't know that the buffer already points to some data in the correct bitwise integer format. But these were correct and can therefore be marked with
__forceto signalize sparse an intended cast to a specific bitwise type.Signed-off-by Sven Eckelmann <[email protected]>
Applied to net-next
From: Sven Eckelmann <[email protected]>
Date: Fri, 13 Dec 2019 21:24:27 +0100
Quoted 10 lines
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 a warning in
ipv6_get_dsfield()because sparse doesn't know that the buffer already points to some data in the correct bitwise integer format. This was already fixed inipv6_change_dsfield()by the__forceattribute and can be fixed here the same way.Signed-off-by Sven Eckelmann <[email protected]>
Applied to net-next