Subject: Re: [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk()

From: Simon Horman <[email-masked]>
Date: Wed, 15 Mar 2023 19:52:16 +0100

On Wed, Mar 15, 2023 at 03:42:38PM +0000, Eric Dumazet wrote:
> We can change inet_sk() to propagate const qualifier of its argument.
> 
> This should avoid some potential errors caused by accidental
> (const -> not_const) promotion.
> 
> Signed-off-by: Eric Dumazet <[email-masked]>

Thanks Eric,

very nice to see this kind of change.

Reviewed-by: Simon Horman <[email-masked]>

...

> diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
> index 51857117ac0995cee20c1e62752c470d2a473fa8..6eb8235be67f8b8265cd86782aed2b489e8850ee 100644
> --- a/include/net/inet_sock.h
> +++ b/include/net/inet_sock.h
> @@ -305,10 +305,11 @@ static inline struct sock *skb_to_full_sk(const struct sk_buff *skb)
>  	return sk_to_full_sk(skb->sk);
>  }
>  
> -static inline struct inet_sock *inet_sk(const struct sock *sk)
> -{
> -	return (struct inet_sock *)sk;
> -}
> +#define inet_sk(sk) \
> +       _Generic(sk,                                          		\

nit: checkpatch tells me that
     There are spaces before tabs (before the '\') on the line above,
     and this macro uses spaces for indentation.

> +                const struct sock * : ((const struct inet_sock *)(sk)),	\
> +                struct sock * : ((struct inet_sock *)(sk))		\
> +       )
>  
>  static inline void __inet_sk_copy_descendant(struct sock *sk_to,
>  					     const struct sock *sk_from,

...