[PATCH net-next v2 2/4] rds: Fix endianness annotation of jhash wrappers

Ujwal Kundur posted 4 patches 1 month, 2 weeks ago
[PATCH net-next v2 2/4] rds: Fix endianness annotation of jhash wrappers
Posted by Ujwal Kundur 1 month, 2 weeks ago
__ipv6_addr_jhash (wrapper around jhash2()) and __inet_ehashfn (wrapper
around jhash_3words()) work with u32 (host endian) values but accept big
endian inputs. Declare the local variables as big endian to avoid
unnecessary casts.

Flagged by Sparse.

Signed-off-by: Ujwal Kundur <ujwal.kundur@gmail.com>
---
 net/rds/connection.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/rds/connection.c b/net/rds/connection.c
index d62f486ab29f..ba6fb87647ac 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -57,16 +57,17 @@ static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr,
 	static u32 rds6_hash_secret __read_mostly;
 	static u32 rds_hash_secret __read_mostly;
 
-	u32 lhash, fhash, hash;
+	u32 hash;
+	__be32 lhash, fhash;
 
 	net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
 	net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret));
 
-	lhash = (__force u32)laddr->s6_addr32[3];
+	lhash = laddr->s6_addr32[3];
 #if IS_ENABLED(CONFIG_IPV6)
-	fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret);
+	fhash = (__force __be32)__ipv6_addr_jhash(faddr, rds6_hash_secret);
 #else
-	fhash = (__force u32)faddr->s6_addr32[3];
+	fhash = faddr->s6_addr32[3];
 #endif
 	hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);
 
-- 
2.30.2
Re: [PATCH net-next v2 2/4] rds: Fix endianness annotation of jhash wrappers
Posted by Allison Henderson 1 month, 1 week ago
On Wed, 2025-08-20 at 23:25 +0530, Ujwal Kundur wrote:
> __ipv6_addr_jhash (wrapper around jhash2()) and __inet_ehashfn (wrapper
> around jhash_3words()) work with u32 (host endian) values but accept big
> endian inputs. Declare the local variables as big endian to avoid
> unnecessary casts.
> 
> Flagged by Sparse.
> 
> Signed-off-by: Ujwal Kundur <ujwal.kundur@gmail.com>
This looks ok now.  Thank you!
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
> ---
>  net/rds/connection.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/net/rds/connection.c b/net/rds/connection.c
> index d62f486ab29f..ba6fb87647ac 100644
> --- a/net/rds/connection.c
> +++ b/net/rds/connection.c
> @@ -57,16 +57,17 @@ static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr,
>  	static u32 rds6_hash_secret __read_mostly;
>  	static u32 rds_hash_secret __read_mostly;
>  
> -	u32 lhash, fhash, hash;
> +	u32 hash;
> +	__be32 lhash, fhash;
>  
>  	net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
>  	net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret));
>  
> -	lhash = (__force u32)laddr->s6_addr32[3];
> +	lhash = laddr->s6_addr32[3];
>  #if IS_ENABLED(CONFIG_IPV6)
> -	fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret);
> +	fhash = (__force __be32)__ipv6_addr_jhash(faddr, rds6_hash_secret);
>  #else
> -	fhash = (__force u32)faddr->s6_addr32[3];
> +	fhash = faddr->s6_addr32[3];
>  #endif
>  	hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);
>