Thread (26 messages) 26 messages, 9 authors, 2023-01-11

Re: [PATCH 3/5] driver core: make struct device_type.uevent() take a const *

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: 2022-11-23 18:14:56
Also in: alsa-devel, linux-acpi, linux-block, linux-devicetree, linux-i2c, linux-i3c, linux-media, linux-serial, linux-usb, lkml, platform-driver-x86

On Wed, Nov 23, 2022 at 05:49:36PM +0000, Matthew Wilcox wrote:
On Wed, Nov 23, 2022 at 01:29:56PM -0400, Jason Gunthorpe wrote:
quoted
#define generic_container_of(in_type, in, out_type, out_member) \
	_Generic(in,                                        \
                  const in_type *: ((const out_type *)container_of(in, out_type, out_member)),   \
                  in_type *: ((out_type *)container_of(in, out_type, out_member)) \
		  )
There's a neat trick I found in seqlock.h:

#define generic_container_of(in_t, in, out_t, m)			\
	_Generic(*(in),							\
		const in_t: ((const out_t *)container_of(in, out_t, m)), \
		in_t: ((out_t *)container_of(in, out_type, m))	\
	)

and now it fits in 80 columns ;-)
Nice trick!  Dropping the inline functions is a bit different, let me
see if that still gives a sane error if we pass an incorrect type or
mess with the const * the wrong way.  I'll run some tests tomorrow
afternoon...

thanks,

greg k-h
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help