Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1429742ybh; Thu, 23 Jul 2020 08:42:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtvaJAnYm3KgfVzbR2YyqfG6wF5T3n2DmOair4E7xgbSP3m14D5A6DUsIs1pzR1686MeJ6 X-Received: by 2002:a17:906:5f98:: with SMTP id a24mr1013038eju.241.1595518928915; Thu, 23 Jul 2020 08:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595518928; cv=none; d=google.com; s=arc-20160816; b=hquRDO97Dvrno2GwIPDvG/FRwxiRShAn5ibmAevhqaRz95PdDNf1vreHCwBCIB/6fB 7aw6nMJnhWeQ9Bps6Bmgf3QCQokrGhnIMH0rTHQ6WjuVKB+dU+IGt78N4GdfWf7bYVpl xzujuhB+FB20Tp+Y/AqlpKOqqLCC8tgnCs4MOQtNxkibJA0RIOZtmnanOVLdDyKa58F4 l9N9yEehJ0dZRuHB7t/Psv8fSyx7waN0wYgRMjiWrpo0VlE0KSDLUPefcIx+L4svO2j4 iyw+ifxXZvfXS0xnjlxiCWKMMx0XisxvmX8w2Y4fg0ZMf3OxF+YRZRHT1A5eFXBR3y6P 85pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=YN6Ikue0xdvT8uoLrJ09TYdMi50adTtRyUO3OGFpiv4=; b=XPf7IkqFl1Q71+okshAAR34g7D5+piPfA82FTvdmsWVslVH5m3+3e/X9RA0oA1UoxW h2g/HVX8mE67TYpC0puJib676+IIIqd+CDxQnfH8YwP3oD2hx/I2pW6P29Sy7PvG/Pn0 VB7G5fS+Ab75BQ3dK85face/hNK+9dcYix+r2QZc+nBP+C6xjhQPeT4qp/9D+fQlbbWw f/Ik1MhFQQa+WaHSj00ZPQH6iGFyKajAw6z0Sp7SwFIU57qN0KoGwr+XncYD9eKCAx2F R7ruXTHqrY7TrDUCdDOd+p4tC7A4o1T8hiDBcDO2TaFnsSOoV+gsJc3Q/ka2Kbp8SALP 1Pmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si2078919ejd.687.2020.07.23.08.41.30; Thu, 23 Jul 2020 08:42:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729626AbgGWPlD (ORCPT + 99 others); Thu, 23 Jul 2020 11:41:03 -0400 Received: from a3.inai.de ([88.198.85.195]:44866 "EHLO a3.inai.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729551AbgGWPlC (ORCPT ); Thu, 23 Jul 2020 11:41:02 -0400 Received: by a3.inai.de (Postfix, from userid 25121) id 049975872C746; Thu, 23 Jul 2020 17:40:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by a3.inai.de (Postfix) with ESMTP id 038D360C4009F; Thu, 23 Jul 2020 17:40:49 +0200 (CEST) Date: Thu, 23 Jul 2020 17:40:49 +0200 (CEST) From: Jan Engelhardt To: Christoph Hellwig cc: "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Alexey Kuznetsov , Hideaki YOSHIFUJI , Eric Dumazet , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Netfilter Developer Mailing List , coreteam@netfilter.org, linux-sctp@vger.kernel.org, linux-hams@vger.kernel.org, linux-bluetooth@vger.kernel.org, bridge@lists.linux-foundation.org, linux-can@vger.kernel.org, dccp@vger.kernel.org, linux-decnet-user@lists.sourceforge.net, linux-wpan@vger.kernel.org, linux-s390@vger.kernel.org, mptcp@lists.01.org, lvs-devel@vger.kernel.org, rds-devel@oss.oracle.com, linux-afs@lists.infradead.org, tipc-discussion@lists.sourceforge.net, linux-x25@vger.kernel.org Subject: Re: [PATCH 04/26] net: add a new sockptr_t type In-Reply-To: <20200723060908.50081-5-hch@lst.de> Message-ID: References: <20200723060908.50081-1-hch@lst.de> <20200723060908.50081-5-hch@lst.de> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Thursday 2020-07-23 08:08, Christoph Hellwig wrote: >+typedef struct { >+ union { >+ void *kernel; >+ void __user *user; >+ }; >+ bool is_kernel : 1; >+} sockptr_t; >+ >+static inline bool sockptr_is_null(sockptr_t sockptr) >+{ >+ return !sockptr.user && !sockptr.kernel; >+} """If the member used to access the contents of a union is not the same as the member last used to store a value, the object representation of the value that was stored is reinterpreted as an object representation of the new type (this is known as type punning). If the size of the new type is larger than the size of the last-written type, the contents of the excess bytes are unspecified (and may be a trap representation)""" As I am not too versed with the consequences of trap representations, I will just point out that a future revision of the C standard may introduce (proposal N2362) stronger C++-like requirements; as for union, that would imply a simple: """It's undefined behavior to read from the member of the union that wasn't most recently written.""" [cppreference.com] So, in the spirit of copy_from/to_sockptr, the is_null function should read { return sockptr.is_kernel ? !sockptr.user : !sockptr.kernel; }