[PATCH net-next v7 4/5] ip_tunnel: Preserve pointer const in ip_tunnel_info_opts

Gavin Li posted 5 patches 2 years, 11 months ago
There is a newer version of this series
[PATCH net-next v7 4/5] ip_tunnel: Preserve pointer const in ip_tunnel_info_opts
Posted by Gavin Li 2 years, 11 months ago
Change ip_tunnel_info_opts( ) from static function to macro to cast return
value and preserve the const-ness of the pointer.

Signed-off-by: Gavin Li <gavinl@nvidia.com>
---
 include/net/ip_tunnels.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index fca357679816..255b32a90850 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -67,6 +67,12 @@ struct ip_tunnel_key {
 	GENMASK((sizeof_field(struct ip_tunnel_info,		\
 			      options_len) * BITS_PER_BYTE) - 1, 0)
 
+#define ip_tunnel_info_opts(info)				\
+	_Generic(info,						\
+		 const struct ip_tunnel_info * : ((const void *)((info) + 1)),\
+		 struct ip_tunnel_info * : ((void *)((info) + 1))\
+	)
+
 struct ip_tunnel_info {
 	struct ip_tunnel_key	key;
 #ifdef CONFIG_DST_CACHE
@@ -485,11 +491,6 @@ static inline void iptunnel_xmit_stats(struct net_device *dev, int pkt_len)
 	}
 }
 
-static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info)
-{
-	return info + 1;
-}
-
 static inline void ip_tunnel_info_opts_get(void *to,
 					   const struct ip_tunnel_info *info)
 {
-- 
2.31.1
Re: [PATCH net-next v7 4/5] ip_tunnel: Preserve pointer const in ip_tunnel_info_opts
Posted by Eric Dumazet 2 years, 11 months ago
On Mon, Mar 13, 2023 at 12:51 AM Gavin Li <gavinl@nvidia.com> wrote:
>
> Change ip_tunnel_info_opts( ) from static function to macro to cast return
> value and preserve the const-ness of the pointer.
>
> Signed-off-by: Gavin Li <gavinl@nvidia.com>
> ---
>  include/net/ip_tunnels.h | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>

Reviewed-by: Eric Dumazet <edumazet@google.com>
Re: [PATCH net-next v7 4/5] ip_tunnel: Preserve pointer const in ip_tunnel_info_opts
Posted by Simon Horman 2 years, 11 months ago
On Mon, Mar 13, 2023 at 07:57:23PM -0700, Eric Dumazet wrote:
> On Mon, Mar 13, 2023 at 12:51 AM Gavin Li <gavinl@nvidia.com> wrote:
> >
> > Change ip_tunnel_info_opts( ) from static function to macro to cast return
> > value and preserve the const-ness of the pointer.
> >
> > Signed-off-by: Gavin Li <gavinl@nvidia.com>
> > ---
> >  include/net/ip_tunnels.h | 11 ++++++-----
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> >
> 
> Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks Gavin,

this addresses my concerns.

Reviewed-by: Simon Horman <simon.horman@corigine.com>