]> git.baikalelectronics.ru Git - kernel.git/commit
PCI: Avoid duplicate IDs in driver dynamic IDs list
authorZhenzhong Duan <zhenzhong.duan@gmail.com>
Tue, 17 Nov 2020 05:44:09 +0000 (13:44 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 20 Nov 2020 23:23:35 +0000 (17:23 -0600)
commitd0dfbb6adf5c359009ce1ba578baa90e2e6e1ad0
tree8f0d75dbb850b947ff1fe13012c670e6aa0e8004
parentb1645eceae9f28bc5276ea6c4795ebaf0a6e2f11
PCI: Avoid duplicate IDs in driver dynamic IDs list

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/20201117054409.3428-3-zhenzhong.duan@gmail.com
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci-driver.c