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

From: Jakub Kicinski <[email-masked]>
Date: Wed, 15 Mar 2023 16:08:28 -0700

On Wed, 15 Mar 2023 15:37:50 -0700 Eric Dumazet wrote:
> I did see container_of_const() but the default: case was not appealing to me.
> 
> Maybe something like this?
> 
> diff --git a/include/linux/container_of.h b/include/linux/container_of.h
> index 713890c867bea78804defe1a015e3c362f40f85d..9a24d8db1f4c46166c07589bb084eda9b9ede8ba
> 100644
> --- a/include/linux/container_of.h
> +++ b/include/linux/container_of.h
> @@ -35,4 +35,10 @@
>                 default: ((type *)container_of(ptr, type, member))      \
>         )
> 
> +#define promote_to_type(ptr, oldtype, newtype)                 \
> +       _Generic(ptr,                                           \
> +                const oldtype *: ((const newtype *)(ptr)),     \
> +                oldtype *: ((newtype *)(ptr))                  \
> +       )

Perfect, I'll defer to you on whether you want to patch it on top 
or repost the series.