Skip to content

Commit

Permalink
PCI: Avoid duplicate IDs in driver dynamic IDs list
Browse files Browse the repository at this point in the history
When a device ID is written to /sys/bus/pci/drivers/.../new_id, we
previously only checked the driver's static ID table for duplicates.
Writing the same ID several times added it to the dynamic IDs list several
times.

This doesn't cause user-visible broken behavior, but remove_id_store() only
removes 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, attempts to add an ID more than once cause an error:

  # 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

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Zhenzhong Duan <[email protected]>
Signed-off-by: Bjorn Helgaas <[email protected]>
  • Loading branch information
Zhenzhong Duan authored and bjorn-helgaas committed Nov 20, 2020
1 parent 1f40704 commit 3853f91
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/pci/pci-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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;

kfree(pdev);
Expand Down

0 comments on commit 3853f91

Please sign in to comment.