From: Samiullah Khawaja <skhawaja@google.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Gui-Dong Han <hanguidong02@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alex Williamson <alex@shazbot.org>,
"open list:PCI SUBSYSTEM" <linux-pci@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
dmatlack@google.com
Subject: Re: [PATCH] PCI: Init driver override spinlock in new_id_store()
Date: Mon, 27 Apr 2026 20:36:02 +0000 [thread overview]
Message-ID: <ae-_EmuuoQTqD6wg@google.com> (raw)
In-Reply-To: <DI472FJ8UOG4.1JGTQK7W1RAX@kernel.org>
On Mon, Apr 27, 2026 at 09:46:20PM +0200, Danilo Krummrich wrote:
>On Mon Apr 27, 2026 at 9:31 PM CEST, Samiullah Khawaja wrote:
>> Fixes: cb3d1049f4ea ("driver core: generalize driver_override in struct device")
>
>I don't think anything is wrong with this commit, and it seems unrelated.
I will remove this one.
>
>> Fixes: 10a4206a2401 ("PCI: use generic driver_override infrastructure")
>
>I'm also not sure that this one contains the root cause, despite revealing the
>actual issue, more below.
I see your point. I understand the actual issue is that the temporary
pci_dev struct was not init and that was added in 2014. I added this
since this is where the regression happened.
>
>> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
>> ---
>> drivers/pci/pci-driver.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
>> index d10ece0889f0..5f453213b8c5 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -215,6 +215,11 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,
>> pdev->subsystem_device = subdevice;
>> pdev->class = class;
>>
>> + /*
>> + * Initialize the embedded struct device driver_override lock to
>> + * avoid the lockdep errors.
>> + */
>> + spin_lock_init(&pdev->dev.driver_override.lock);
>
>Can't we just call device_initialize() and set pdev->dev.release to a new
>function that just calls kfree()?
>
>This way nothing of that kind can ever happen again; it is hard to predict that
>a device is used without ever being initialized.
Agreed.
yes we can set the release function and call device_initialize().
Should I send v2 with something like following:
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index d10ece0889f0..634b4311bf5d 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -179,6 +179,11 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
return NULL;
}
+static void _release_temp_device(struct device *dev)
+{
+ kfree(to_pci_dev(dev));
+}
+
/**
* new_id_store - sysfs frontend to pci_add_dynid()
* @driver: target device driver
@@ -214,11 +219,14 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,
pdev->subsystem_vendor = subvendor;
pdev->subsystem_device = subdevice;
pdev->class = class;
+ pdev->dev.release = _release_temp_device;
+ /* Initialize the embedded struct device. */
+ device_initialize(&pdev->dev);
if (pci_match_device(pdrv, pdev))
retval = -EEXIST;
- kfree(pdev);
+ put_device(&pdev->dev);
if (retval)
return retval;
>
>> if (pci_match_device(pdrv, pdev))
>> retval = -EEXIST;
>>
>>
>> base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
>> --
>> 2.54.0.545.g6539524ca2-goog
next prev parent reply other threads:[~2026-04-27 20:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 19:31 [PATCH] PCI: Init driver override spinlock in new_id_store() Samiullah Khawaja
2026-04-27 19:46 ` Danilo Krummrich
2026-04-27 20:36 ` Samiullah Khawaja [this message]
2026-04-27 21:11 ` Danilo Krummrich
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=ae-_EmuuoQTqD6wg@google.com \
--to=skhawaja@google.com \
--cc=alex@shazbot.org \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=dmatlack@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hanguidong02@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.