[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220119202749.GA959272@bhelgaas>
Date: Wed, 19 Jan 2022 14:27:49 -0600
From: Bjorn Helgaas <helgaas@...nel.org>
To: Hans de Goede <hdegoede@...hat.com>
Cc: Kai-Heng Feng <kai.heng.feng@...onical.com>,
LKML <linux-kernel@...r.kernel.org>, jkosina@...e.cz,
Jason Gunthorpe <jgg@...pe.ca>,
Bjorn Helgaas <bhelgaas@...gle.com>, mgurtovoy@...dia.com,
linux@...ssschuh.net, Arnd Bergmann <arnd@...db.de>,
stephan@...hold.net, "Rafael J. Wysocki" <rafael@...nel.org>
Subject: Re: Convert type of 'struct dmi_system_id -> driver_data' from 'void
*' to kernel_ulong_t?
On Wed, Jan 19, 2022 at 11:20:36AM +0100, Hans de Goede wrote:
> On 1/19/22 02:22, Kai-Heng Feng wrote:
> > I wonder if there's any reason to use 'void *' instead of
> > kernel_ulong_t for 'driver_data' in 'struct dmi_system_id'?
> >
> > I'd like to use the driver_data for applying quirk flags, and I found
> > out unlike most other struct *_id, the dmi variant is using 'void *'
> > for driver_data. Is there any technical reason for this?
> > ...
> You are asking for a technical reason why "void *" was used,
> but lets turn that around, why do you believe that "unsigned long"
> is inherently a better type here ?
>
> driver_data in most places in the kernel (like data for
> all sort of callback functions) actually typically is a void *
> already, because often people want to pass more data then what
> fits in a single long and this also applies to driver-id attached
> data.
FWIW, "egrep "context;|data;|info;" include/linux/mod_devicetable.h"
says 4 of the ~40 instances use a void *; the others use
kernel_ulong_t.
f45d069a5628 ("PCI dynids - documentation fixes, id_table NULL check")
[1] (from the tglx history tree) added the original hint for
pci_device_id that:
Best practice for use of driver_data is to use it as an index into a
static list of equivalant device types, not to use it as a pointer.
I don't know the background of that, but I could imagine that using an
index rather than a pointer makes things like /sys/bus/pci/.../new_id
easier and safer.
Bjorn
[1] https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=f45d069a5628
Powered by blists - more mailing lists