All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "David S . Miller" <davem@davemloft.net>,
	Paolo Abeni <pabeni@redhat.com>, David Ahern <dsahern@kernel.org>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk()
Date: Wed, 15 Mar 2023 15:37:50 -0700	[thread overview]
Message-ID: <CANn89iLbOqjWVmgZKdGjbdsHw1EwO9d_w+dgKsyzLoq9pOsurQ@mail.gmail.com> (raw)
In-Reply-To: <20230315142841.3a2ac99a@kernel.org>

On Wed, Mar 15, 2023 at 2:28 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 15 Mar 2023 15:42:38 +0000 Eric Dumazet wrote:
> > -static inline struct inet_sock *inet_sk(const struct sock *sk)
> > -{
> > -     return (struct inet_sock *)sk;
> > -}
> > +#define inet_sk(sk) \
> > +       _Generic(sk,                                                          \
> > +                const struct sock * : ((const struct inet_sock *)(sk)),      \
> > +                struct sock * : ((struct inet_sock *)(sk))           \
> > +       )
>
> Could we possibly use container_of_const() or define a new common
> macro for this downcast? I'm worried it will spread and it's a bit
> verbose.

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))                  \
+       )
+
 #endif /* _LINUX_CONTAINER_OF_H */
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index 6eb8235be67f8b8265cd86782aed2b489e8850ee..96f41b3c1a3e4b6ad1c6d2058ca46686be282c03
100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -305,11 +305,7 @@ static inline struct sock *skb_to_full_sk(const
struct sk_buff *skb)
        return sk_to_full_sk(skb->sk);
 }

-#define inet_sk(sk) \
-       _Generic(sk,                                                    \
-                const struct sock * : ((const struct inet_sock
*)(sk)),        \
-                struct sock * : ((struct inet_sock *)(sk))             \
-       )
+#define inet_sk(sk) promote_to_type(sk, struct sock, struct inet_sock)

 static inline void __inet_sk_copy_descendant(struct sock *sk_to,
                                             const struct sock *sk_from,

  reply	other threads:[~2023-03-15 22:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 15:42 [PATCH net-next 0/8] inet: better const qualifier awareness Eric Dumazet
2023-03-15 15:42 ` [PATCH net-next 1/8] inet: preserve const qualifier in inet_sk() Eric Dumazet
2023-03-15 18:52   ` Simon Horman
2023-03-15 21:28   ` Jakub Kicinski
2023-03-15 22:37     ` Eric Dumazet [this message]
2023-03-15 23:08       ` Jakub Kicinski
2023-03-15 23:16         ` Eric Dumazet
2023-03-15 23:21       ` Linus Torvalds
2023-03-15 23:37         ` Eric Dumazet
2023-03-15 23:47           ` Linus Torvalds
2023-03-15 23:39         ` Linus Torvalds
2023-03-15 23:45           ` Eric Dumazet
2023-03-15 23:54             ` Linus Torvalds
2023-03-15 23:56               ` Eric Dumazet
2023-03-16  0:02                 ` Linus Torvalds
2023-03-16  0:11                   ` Eric Dumazet
2023-03-16  0:23                     ` Eric Dumazet
2023-03-16  0:34                       ` Linus Torvalds
2023-03-15 15:42 ` [PATCH net-next 2/8] ipv4: constify ip_mc_sf_allow() socket argument Eric Dumazet
2023-03-15 18:52   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 3/8] udp: constify __udp_is_mcast_sock() " Eric Dumazet
2023-03-15 18:53   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 4/8] ipv6: constify inet6_mc_check() Eric Dumazet
2023-03-15 18:53   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 5/8] udp6: constify __udp_v6_is_mcast_sock() socket argument Eric Dumazet
2023-03-15 18:53   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 6/8] ipv6: raw: constify raw_v6_match() " Eric Dumazet
2023-03-15 18:54   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 7/8] ipv4: raw: constify raw_v4_match() " Eric Dumazet
2023-03-15 18:54   ` Simon Horman
2023-03-15 15:42 ` [PATCH net-next 8/8] inet_diag: constify raw_lookup() " Eric Dumazet
2023-03-15 18:54   ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANn89iLbOqjWVmgZKdGjbdsHw1EwO9d_w+dgKsyzLoq9pOsurQ@mail.gmail.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eric.dumazet@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.