public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: qat-linux@intel.com, Alejandro Colomar <alx.manpages@gmail.com>,
	linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Lucas Segarra Fernandez <lucas.segarra.fernandez@intel.com>,
	Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Subject: Re: [PATCH] linux/container_of.h: Add memberof()
Date: Mon, 21 Aug 2023 13:23:41 +0200	[thread overview]
Message-ID: <c750428f-cbeb-53f5-5865-fa0af263b15e@kernel.org> (raw)
In-Reply-To: <ZONIFMSmLZMeFPOY@smile.fi.intel.com>

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))
> 

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5


      reply	other threads:[~2023-08-21 11:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 14:33 [PATCH 0/4] Add debugfs pm_status for qat driver Lucas Segarra Fernandez
2023-08-17 14:33 ` [PATCH 1/4] linux/array_size.h: Move ARRAY_SIZE(arr) to a separate header Lucas Segarra Fernandez
2023-08-17 20:24   ` Alejandro Colomar
2023-08-17 14:33 ` [PATCH 2/4] linux/array_size.h: Add ARRAY_SIZE_OF_FIELD() Lucas Segarra Fernandez
2023-08-17 20:34   ` Alejandro Colomar
2023-08-17 21:30     ` Andy Shevchenko
2023-08-17 22:03       ` Alejandro Colomar
2023-08-17 14:33 ` [PATCH 3/4] crypto: qat - refactor included headers Lucas Segarra Fernandez
2023-08-17 14:33 ` [PATCH 4/4] crypto: qat - add pm_status debugfs file Lucas Segarra Fernandez
2023-08-18  5:28   ` Herbert Xu
2023-08-18  8:46     ` Andy Shevchenko
2023-08-18  8:51       ` Herbert Xu
2023-08-20 19:52       ` [PATCH] linux/container_of.h: Add memberof() Alejandro Colomar
2023-08-21 11:18         ` Andy Shevchenko
2023-08-21 11:23           ` Alejandro Colomar [this message]

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=c750428f-cbeb-53f5-5865-fa0af263b15e@kernel.org \
    --to=alx@kernel.org \
    --cc=alx.manpages@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.segarra.fernandez@intel.com \
    --cc=qat-linux@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox