Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D540C64EC4 for ; Thu, 9 Mar 2023 15:08:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbjCIPIF (ORCPT ); Thu, 9 Mar 2023 10:08:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbjCIPHh (ORCPT ); Thu, 9 Mar 2023 10:07:37 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFA27F5D25 for ; Thu, 9 Mar 2023 07:05:26 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id j2so2174662wrh.9 for ; Thu, 09 Mar 2023 07:05:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678374325; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fprW8tKIJpNzkLRvXOdERhC1G75znrKGsVPaP20fW+w=; b=J47UBp+wxM1KsM1vSCnlEL6q+hv+bNiGs/S9ezNZ3FczAvPEOX6REYsGl9e8y7Kbgi t5yvgu0EEzLYK5ax9pbvEWlXWeG4xwvYLD+iRkI4eeYAVBiwRZdxoC4hcxTKEvoxB77D /XoNjLGzs1QwWmkc18cq/P6rMHkbWHCrsA+Zcvkz2HIQ1ixuuESeBlZu2fCp1dyb7itC Mb/hVCNN/MEhXlOv8lfZELVazX9djURCqc4gk/Wb73mm1vW7fXkRrrjWchmb6dhl7Qr5 zRC+MMJLXrHpC6tLqV6PDj7t0x12U/LrM5GCNrjJ/S1qA4PeqlvyH7/0PFuXxnLyxLHx VLKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678374325; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fprW8tKIJpNzkLRvXOdERhC1G75znrKGsVPaP20fW+w=; b=42jBZNCBkebGzuav1Q0jpm97vadDwdYMUCQkyENBsaY65NWEzEcKOh8POFba2/N2X5 jxye5BaJInCP1m/FmMvaip/P9jOS9A2pm5YA3pP2d64T/m1DwcgGnC5uYUoxwHV3diP7 3MaOgNSnL4Sx/XkONvqzFncn3cj5dseWGZaFuO5iUySKmZVfnQPpxy9lUOU7V7hpzX5f GYSgXUJuq5pZ7E80rawIOnnMOrkXSSIO1/AqRPNm7degskqk49yotq2HxaKtxGMuxxWn q1vdEthZpoH5VTeX8ifEy0sGAXTa/hyP6b87k1oYvEsI9kqv7LQk4ZsKXfip7+kD3vgx NFdg== X-Gm-Message-State: AO0yUKXnYiwbmZ1RLYjNHp4m/mVjJqH+rdttf/bSgUTRP7/vdmkYiZ0+ ftJONILLRs5/SaLURBiaGCbN9gSdReddgBRwPBUoYg== X-Google-Smtp-Source: AK7set887nr6XBTqOK05PdAz44JZdvwltzyYf1Oyh2sWKb7bxgmtbjPGrGWiHv4JHYEf8xQDCPIO/0u/eeRBu46mEwA= X-Received: by 2002:adf:f38d:0:b0:2cb:3b68:3a88 with SMTP id m13-20020adff38d000000b002cb3b683a88mr4826450wro.7.1678374325103; Thu, 09 Mar 2023 07:05:25 -0800 (PST) MIME-Version: 1.0 References: <20230309134718.306570-1-gavinl@nvidia.com> <20230309134718.306570-5-gavinl@nvidia.com> In-Reply-To: From: Eric Dumazet Date: Thu, 9 Mar 2023 16:05:13 +0100 Message-ID: Subject: Re: [PATCH net-next v6 4/5] ip_tunnel: Preserve pointer const in ip_tunnel_info_opts To: Gavin Li Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, roopa@nvidia.com, eng.alaamohamedsoliman.am@gmail.com, bigeasy@linutronix.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, gavi@nvidia.com, roid@nvidia.com, maord@nvidia.com, saeedm@nvidia.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 9, 2023 at 3:59=E2=80=AFPM Eric Dumazet w= rote: > > On Thu, Mar 9, 2023 at 2:48=E2=80=AFPM Gavin Li wrote= : > > > > Change ip_tunnel_info_opts( ) from static function to macro to cast ret= urn > > value and preserve the const-ness of the pointer. > > > > Signed-off-by: Gavin Li > > --- > > 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..3e5c102b841f 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 typeof(*(info)) * : ((const void *)((info) + 1)),= \ > > + default : ((void *)((info) + 1)) \ > > + ) > > + > > Hmm... > > This looks quite dangerous, we lost type safety with the 'default' > case, with all these casts. > > What about using something cleaner instead ? > > (Not sure why we do not have an available generic helper for this kind > of repetitive things) > Or more exactly : diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index fca3576798166416982ee6a9100b003810c49830..17fc6c8f7e0b9e5303c1fb9e5da= d77c5310e01a9 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -485,10 +485,11 @@ 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; -} +#define ip_tunnel_info_opts(info) \ + (_Generic(info, \ + const struct ip_tunnel_info * : (const void *)((info) + 1), \ + struct ip_tunnel_info * : (void *)((info) + 1)) \ + ) static inline void ip_tunnel_info_opts_get(void *to, const struct ip_tunnel_info *inf= o)