Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1332027rdb; Mon, 21 Aug 2023 04:55:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7cGDUEYvoV0d2BihQXGIUK/pkW0wbXLOEiUUvl4vV5ThfU4p+a6Stnw/45lcqkUlmmTSg X-Received: by 2002:ac2:499e:0:b0:4fb:fe00:49c2 with SMTP id f30-20020ac2499e000000b004fbfe0049c2mr3632565lfl.32.1692618902646; Mon, 21 Aug 2023 04:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692618902; cv=none; d=google.com; s=arc-20160816; b=P6OZ877+y8jvDDAL1XgCQGjp8cZUxej21hqq0YVt5ER7V4S7uHqDhABUSXEi4T/6Ux hMQ+EpCine6FgOETaow7TwyTdZyMhFIfu30KEjcGFFOqOyb69v3HP5RdYDNj/5aFyCPC NvCVesVxK8mNTplusy+dkPc1JaTO8bEqTx82Ox18id4q5t3Q6C1LC670St4YF5s6xvJB rRBsDdeAvC+DllM6boBbezcSuXOu2DIqd3fCoUkY+Y0H3qVWUwM1IMaPqEU2yvv2j5Bj TJFBbB8MuxfSoVdT3kANGtSDnN/IaMPs0fZ324aRBfCJ13opaFUhPngPCUFW+GxAf20a i+Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=owS6KuHfPtOO5IZUDJyhheqYuOwIovqejqm1eUVOESQ=; fh=a9BrcaqqY5aTMaOSjVIgPpNdicB8N7D5ypuZ+TpXkC0=; b=XT7S+Hanqwb7iDJYXEXLivo24aTtL75NmdTBGx9PFIEef/JcM8298m6bHFBNaX/wlF ezYu+DNtUufNLTxsXBSSWMYkWSDtiuN9lC1rnjneLG0qIgXNhDcllPmfIsdCiigV6k1s BafdvGLBjJKnHJyv9S1IhopceCsobZbFGtFwgfqvyyQwFYhnRRkLQtmoldBtX2v4kfM8 9Vrde5q2bxXMHKTu9PuvIrtZxu5Q4AgvHxo0cgorJvyl5r/8PkSX//056tOjmZhmCYUP HjHCTqb+TSAPI6VG8CXuKaz3qBnkRaDhcxX0h+2p+yW4/3MTjEmrrD69snroR05ruYe1 q6kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=osKG4Opy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020a1709065f8700b009a16d2fa98esi4183884eju.619.2023.08.21.04.54.38; Mon, 21 Aug 2023 04:55:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=osKG4Opy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231918AbjHULXs (ORCPT + 99 others); Mon, 21 Aug 2023 07:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbjHULXr (ORCPT ); Mon, 21 Aug 2023 07:23:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F7BD8; Mon, 21 Aug 2023 04:23:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 00F016100B; Mon, 21 Aug 2023 11:23:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C0EFC433C8; Mon, 21 Aug 2023 11:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692617025; bh=v4yx1jU68ILujJ9Flvf3NQrZH6ekak8E8uv+0YCIRjk=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=osKG4OpylgJrXV6nktjlRCaGsfMdp5qEq0SFhzKunOWwS8T26Ar+H87wl7UjUf8LY KukTl4j4PPMqsJGAGDloN8Zc1Vw4oV5zj7XghPq/rn6PiwzJP2ZxhgS9VCz93HNaAh fPStFfWIc578y09Gl86Qfi7HDhbznVqm66x4rGMKJ7a2JplF8Y5v+qg7GgbF20BozV n4MGcoj9Y/REeNWKwa/dtv6Qa6yF8sKhCvsSRHCT1xeEwOaXyEpjvawOJqAh+oAu9l 95scwyVykPL9Q5GG5IltfF/wlaqS5RBdbef+1BRU1a+SavPIRgg2hvbNS1tvZWS4Fz m6XogVB1qC8xQ== Message-ID: Date: Mon, 21 Aug 2023 13:23:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.1 Subject: Re: [PATCH] linux/container_of.h: Add memberof() To: Andy Shevchenko Cc: qat-linux@intel.com, Alejandro Colomar , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Herbert Xu , Lucas Segarra Fernandez , Giovanni Cabiddu References: <20230820195222.279069-1-alx@kernel.org> Content-Language: en-US From: Alejandro Colomar Organization: Linux In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Andy, On 2023-08-21 13:18, Andy Shevchenko wrote: > On Sun, Aug 20, 2023 at 09:52:22PM +0200, Alejandro Colomar wrote: >> >> -#define typeof_member(T, m) typeof(((T*)0)->m) >> + >> +#define memberof(T, member) ((T){}.member) > > I'm not sure. This seems to me utilization of compound literal, while above > uses direct struct member pointer calculations. Both can be used in most cases. The only exception is offsetof(3), where you need the pointer calculation. The good thing about the compound literal is that it's farther away from causing UB, but if that's not a concern --using sizeof() or typeof() will usually make things safe from UB, as there's really no dereference, but just to be a little paranoic--, I could change the definition of memberof() to use the pointer thing. Should I send a v2 with the pointer thing? [I'll take some time, as I need to restore my USB with keys, which just died yesterday. I didn't sign this email due to that.] Cheers, Alex > >> +#define typeof_member(T, m) typeof(memberof(T, m)) > -- GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5