archive mirror
 help / color / mirror / Atom feed
From: Zhenzhong Duan <>
	Zhenzhong Duan <>
Subject: [PATCH v3 2/2] PCI: avoid duplicate IDs in dynamic IDs list
Date: Tue, 17 Nov 2020 13:44:09 +0800	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

When a device ID data is writen to /sys/bus/pci/drivers/.../new_id,
only static ID table is checked for duplicate and multiple dynamic ID
entries of same kind are allowed to exist in a dynamic IDs list.

This doesn't cause user-visible broken behavior, but not user friendly.
remove_id_store() only remove one of the duplicate IDs, so if we add an
ID several times, we would have to remove it the same number of times
before it's completely gone.

Fix it by calling pci_match_device() which checks both dynamic and static
IDs to avoid inserting duplicate IDs in dynamic IDs list.

After fix, it shows below result which is expected:

echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id
-bash: echo: write error: File exists

Signed-off-by: Zhenzhong Duan <>
 drivers/pci/pci-driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e928cfa..c4678d8 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -197,7 +197,7 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf,
 		pdev->subsystem_device = subdevice;
 		pdev->class = class;
-		if (pci_match_id(pdrv->id_table, pdev))
+		if (pci_match_device(pdrv, pdev))
 			retval = -EEXIST;

  parent reply	other threads:[~2020-11-17  5:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17  5:44 [PATCH v3 0/2] avoid inserting duplicate IDs in dynids list Zhenzhong Duan
2020-11-17  5:44 ` [PATCH v3 1/2] PCI: move pci_match_device() ahead of new_id_store() Zhenzhong Duan
2020-11-17  5:44 ` Zhenzhong Duan [this message]
2020-11-20 21:57 ` [PATCH v3 0/2] avoid inserting duplicate IDs in dynids list Bjorn Helgaas

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \

* 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;
as well as URLs for NNTP newsgroup(s).