mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Kai-Heng Feng <kai.heng.feng@canonical.com>,
	LKML <linux-kernel@vger.kernel.org>
Cc: jkosina@suse.cz, Jason Gunthorpe <jgg@ziepe.ca>,
	Bjorn Helgaas <bhelgaas@google.com>,
	mgurtovoy@nvidia.com, linux@weissschuh.net,
	Arnd Bergmann <arnd@arndb.de>,
	stephan@gerhold.net, "Rafael J. Wysocki" <rafael@kernel.org>
Subject: Re: Convert type of 'struct dmi_system_id -> driver_data' from 'void *' to kernel_ulong_t?
Date: Wed, 19 Jan 2022 11:20:36 +0100	[thread overview]
Message-ID: <fa51355f-9ab6-7bbf-d7f6-e2af2d68056c@redhat.com> (raw)
In-Reply-To: <CAAd53p5EiTXfAhCFPDaicksQOa5usOkS5v7moPgM2A7QZ6QCqg@mail.gmail.com>

Hi Kai-Heng,

On 1/19/22 02:22, Kai-Heng Feng wrote:
> Hi,
> 
> 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?

I don't know if there is a technical reason for this, nor
why this choice was originally made.

But I do believe that changing this now will just lead to a lot
of unnecessary churn.

You can easily use the current void * for flags by doing;

#define FLAG1	BIT(0)
#define FLAG2	BIT(1)

...
		.driver_data = (void *)(FLAG1 | FLAG20,

...

	long quirks = (long)dmi_id->driver_data;


It is already used this way in many places. Have you done a grep
to see in how many places dmi_system_id is used? DMI based quirks
are used all over the place, changing this will cause a really
large amount of churn and for what?

So I just did a quick check and dmi_system_id is used in
*204* files in the kernel.

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.

Just a random example from: drivers/mmc/host/sdhci-pci.h

#define SDHCI_PCI_DEVICE(vend, dev, cfg) { \
        .vendor = _PCI_VEND(vend), .device = _PCI_DEV(vend, dev), \
        .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
        .driver_data = (kernel_ulong_t)&(sdhci_##cfg) \
}

So here the unsigned long is actually not what we want and
we have to do a cast the other way around; and again the
kernel is full of these examples. So arguably if anything we
should change the other driver_data fields from
include/linux/mod_devicetable.h
to avoid the need for these kinda casts all over the kernel
(but again that would not be worth the churn IMHO).

TL;DR: lets just leave this all as it is please.

Regards,

Hans


  reply	other threads:[~2022-01-19 10:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19  1:22 Kai-Heng Feng
2022-01-19 10:20 ` Hans de Goede [this message]
2022-01-19 20:27   ` Bjorn Helgaas
2022-01-19 20:45     ` Hans de Goede
2022-01-20  1:14       ` Kai-Heng Feng

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=fa51355f-9ab6-7bbf-d7f6-e2af2d68056c@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jkosina@suse.cz \
    --cc=kai.heng.feng@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=mgurtovoy@nvidia.com \
    --cc=rafael@kernel.org \
    --cc=stephan@gerhold.net \
    /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

Powered by JetHome