lkml.org 
[lkml]   [2020]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 4.19 17/36] cxgb4: use correct type for all-mask IP address comparison
Hi!

> From: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
>
> [ Upstream commit f286dd8eaad5a2758750f407ab079298e0bcc8a5 ]
>
> Use correct type to check for all-mask exact match IP addresses.
>
> Fixes following sparse warnings due to big endian value checks
> against 0xffffffff in is_addr_all_mask():
> cxgb4_filter.c:977:25: warning: restricted __be32 degrades to integer
> cxgb4_filter.c:983:37: warning: restricted __be32 degrades to integer
> cxgb4_filter.c:984:37: warning: restricted __be32 degrades to integer
> cxgb4_filter.c:985:37: warning: restricted __be32 degrades to integer
> cxgb4_filter.c:986:37: warning: restricted __be32 degrades to integer

> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
> index 7dddb9e748b81..86745f33a252d 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
> @@ -810,16 +810,16 @@ static bool is_addr_all_mask(u8 *ipmask, int family)
> struct in_addr *addr;
>
> addr = (struct in_addr *)ipmask;
> - if (addr->s_addr == 0xffffffff)
> + if (ntohl(addr->s_addr) == 0xffffffff)

Endianity does not really matter for ~0, but can compiler figure it
out?

would it be better to do these tests as

if (foo == htonl(0xffffffff))

to make it clear to the compiler?

Thanks,
Pavel

> } else if (family == AF_INET6) {
> struct in6_addr *addr6;
>
> addr6 = (struct in6_addr *)ipmask;
> - if (addr6->s6_addr32[0] == 0xffffffff &&
> - addr6->s6_addr32[1] == 0xffffffff &&
> - addr6->s6_addr32[2] == 0xffffffff &&
> - addr6->s6_addr32[3] == 0xffffffff)
> + if (ntohl(addr6->s6_addr32[0]) == 0xffffffff &&
> + ntohl(addr6->s6_addr32[1]) == 0xffffffff &&
> + ntohl(addr6->s6_addr32[2]) == 0xffffffff &&
> + ntohl(addr6->s6_addr32[3]) == 0xffffffff)
> return true;
> }
> return false;

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2020-07-07 23:39    [W:0.187 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site