[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y35YlI93UBuTfgYy@ziepe.ca>
Date: Wed, 23 Nov 2022 13:29:56 -0400
From: Jason Gunthorpe <jgg@...pe.ca>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Matthew Wilcox <willy@...radead.org>,
Maximilian Luz <luzmaximilian@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
linux-kernel@...r.kernel.org, Jens Axboe <axboe@...nel.dk>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Len Brown <lenb@...nel.org>,
Stefan Richter <stefanr@...6.in-berlin.de>,
Wolfram Sang <wsa@...nel.org>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
Sean Young <sean@...s.org>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>,
Hans de Goede <hdegoede@...hat.com>,
Mark Gross <markgross@...nel.org>,
Vinod Koul <vkoul@...nel.org>,
Bard Liao <yung-chuan.liao@...ux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>,
Sanyog Kale <sanyog.r.kale@...el.com>,
Andreas Noever <andreas.noever@...il.com>,
Michael Jamet <michael.jamet@...el.com>,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
Yehezkel Bernat <YehezkelShB@...il.com>,
Jiri Slaby <jirislaby@...nel.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
Chaitanya Kulkarni <kch@...dia.com>,
Ming Lei <ming.lei@...hat.com>,
Jilin Yuan <yuanjilin@...rlc.com>,
Alan Stern <stern@...land.harvard.edu>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ira Weiny <ira.weiny@...el.com>,
Dan Williams <dan.j.williams@...el.com>,
Won Chung <wonchung@...gle.com>, alsa-devel@...a-project.org,
devicetree@...r.kernel.org, linux-acpi@...r.kernel.org,
linux-block@...r.kernel.org, linux-i2c@...r.kernel.org,
linux-i3c@...ts.infradead.org, linux-input@...r.kernel.org,
linux-media@...r.kernel.org, linux-serial@...r.kernel.org,
linux-usb@...r.kernel.org, linux1394-devel@...ts.sourceforge.net,
platform-driver-x86@...r.kernel.org
Subject: Re: [PATCH 3/5] driver core: make struct device_type.uevent() take a
const *
On Wed, Nov 23, 2022 at 06:01:47PM +0100, Greg Kroah-Hartman wrote:
> On Wed, Nov 23, 2022 at 12:25:32PM -0400, Jason Gunthorpe wrote:
> > On Wed, Nov 23, 2022 at 04:37:59PM +0100, Greg Kroah-Hartman wrote:
> > > static inline struct device *__kobj_to_dev(struct kobject *kobj)
> > > {
> > > return container_of(kobj, struct device, kobj);
> > > }
> > >
> > > static inline const struct device *__kobj_to_dev_const(const struct kobject *kobj)
> > > {
> > > return container_of(kobj, const struct device, kobj);
> > > }
> > >
> > > /*
> > > * container_of() will happily take a const * and spit back a non-const * as it
> > > * is just doing pointer math. But we want to be a bit more careful in the
> > > * driver code, so manually force any const * of a kobject to also be a const *
> > > * to a device.
> > > */
> > > #define kobj_to_dev(kobj) \
> > > _Generic((kobj), \
> > > const struct kobject *: __kobj_to_dev_const, \
> > > struct kobject *: __kobj_to_dev)(kobj)
> > >
> > >
> > > Want me to do the same thing here as well?
> >
> > It would be nice to have a shared macro code gen all of the above
> > instead of copy and pasting it. Then maybe other cases beyond struct
> > device could adopt const too..
>
> I think I tried to create such a beast, but failed, so ended up
> open-coding it in a few places in the USB headers already. I can try it
> again, but the redirection gets tricky (defines creating defines...)
This seems OK:
#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)) \
)
#define kobj_to_dev(__kobj) \
generic_container_of(struct kobject, __kobj, struct device, kobj)
Jason
Powered by blists - more mailing lists