Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'pci-v5.16-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci

Pull PCI fixes from Bjorn Helgaas:
"Revert conversion to struct device.driver instead of struct
pci_dev.driver.

The device.driver is set earlier, and using it caused the PCI core to
call driver PM entry points before .probe() and after .remove(), when
the driver isn't prepared.

This caused NULL pointer dereferences in i2c_designware_pci and
probably other driver issues"

* tag 'pci-v5.16-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci:
Revert "PCI: Use to_pci_driver() instead of pci_dev->driver"
Revert "PCI: Remove struct pci_dev->driver"

+42 -45
+9 -15
drivers/pci/iov.c
··· 164 164 char *buf) 165 165 { 166 166 struct pci_dev *pdev = to_pci_dev(dev); 167 - struct pci_driver *pdrv; 168 167 u32 vf_total_msix = 0; 169 168 170 169 device_lock(dev); 171 - pdrv = to_pci_driver(dev->driver); 172 - if (!pdrv || !pdrv->sriov_get_vf_total_msix) 170 + if (!pdev->driver || !pdev->driver->sriov_get_vf_total_msix) 173 171 goto unlock; 174 172 175 - vf_total_msix = pdrv->sriov_get_vf_total_msix(pdev); 173 + vf_total_msix = pdev->driver->sriov_get_vf_total_msix(pdev); 176 174 unlock: 177 175 device_unlock(dev); 178 176 return sysfs_emit(buf, "%u\n", vf_total_msix); ··· 183 185 { 184 186 struct pci_dev *vf_dev = to_pci_dev(dev); 185 187 struct pci_dev *pdev = pci_physfn(vf_dev); 186 - struct pci_driver *pdrv; 187 188 int val, ret = 0; 188 189 189 190 if (kstrtoint(buf, 0, &val) < 0) ··· 192 195 return -EINVAL; 193 196 194 197 device_lock(&pdev->dev); 195 - pdrv = to_pci_driver(dev->driver); 196 - if (!pdrv || !pdrv->sriov_set_msix_vec_count) { 198 + if (!pdev->driver || !pdev->driver->sriov_set_msix_vec_count) { 197 199 ret = -EOPNOTSUPP; 198 200 goto err_pdev; 199 201 } 200 202 201 203 device_lock(&vf_dev->dev); 202 - if (to_pci_driver(vf_dev->dev.driver)) { 204 + if (vf_dev->driver) { 203 205 /* 204 206 * A driver is already attached to this VF and has configured 205 207 * itself based on the current MSI-X vector count. Changing ··· 208 212 goto err_dev; 209 213 } 210 214 211 - ret = pdrv->sriov_set_msix_vec_count(vf_dev, val); 215 + ret = pdev->driver->sriov_set_msix_vec_count(vf_dev, val); 212 216 213 217 err_dev: 214 218 device_unlock(&vf_dev->dev); ··· 375 379 const char *buf, size_t count) 376 380 { 377 381 struct pci_dev *pdev = to_pci_dev(dev); 378 - struct pci_driver *pdrv; 379 382 int ret = 0; 380 383 u16 num_vfs; 381 384 ··· 390 395 goto exit; 391 396 392 397 /* is PF driver loaded */ 393 - pdrv = to_pci_driver(dev->driver); 394 - if (!pdrv) { 398 + if (!pdev->driver) { 395 399 pci_info(pdev, "no driver bound to device; cannot configure SR-IOV\n"); 396 400 ret = -ENOENT; 397 401 goto exit; 398 402 } 399 403 400 404 /* is PF driver loaded w/callback */ 401 - if (!pdrv->sriov_configure) { 405 + if (!pdev->driver->sriov_configure) { 402 406 pci_info(pdev, "driver does not support SR-IOV configuration via sysfs\n"); 403 407 ret = -ENOENT; 404 408 goto exit; ··· 405 411 406 412 if (num_vfs == 0) { 407 413 /* disable VFs */ 408 - ret = pdrv->sriov_configure(pdev, 0); 414 + ret = pdev->driver->sriov_configure(pdev, 0); 409 415 goto exit; 410 416 } 411 417 ··· 417 423 goto exit; 418 424 } 419 425 420 - ret = pdrv->sriov_configure(pdev, num_vfs); 426 + ret = pdev->driver->sriov_configure(pdev, num_vfs); 421 427 if (ret < 0) 422 428 goto exit; 423 429
+20 -17
drivers/pci/pci-driver.c
··· 319 319 * its remove routine. 320 320 */ 321 321 pm_runtime_get_sync(dev); 322 + pci_dev->driver = pci_drv; 322 323 rc = pci_drv->probe(pci_dev, ddi->id); 323 324 if (!rc) 324 325 return rc; 325 326 if (rc < 0) { 327 + pci_dev->driver = NULL; 326 328 pm_runtime_put_sync(dev); 327 329 return rc; 328 330 } ··· 390 388 * @pci_dev: PCI device being probed 391 389 * 392 390 * returns 0 on success, else error. 391 + * side-effect: pci_dev->driver is set to drv when drv claims pci_dev. 393 392 */ 394 393 static int __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) 395 394 { ··· 457 454 static void pci_device_remove(struct device *dev) 458 455 { 459 456 struct pci_dev *pci_dev = to_pci_dev(dev); 460 - struct pci_driver *drv = to_pci_driver(dev->driver); 457 + struct pci_driver *drv = pci_dev->driver; 461 458 462 459 if (drv->remove) { 463 460 pm_runtime_get_sync(dev); ··· 465 462 pm_runtime_put_noidle(dev); 466 463 } 467 464 pcibios_free_irq(pci_dev); 465 + pci_dev->driver = NULL; 468 466 pci_iov_remove(pci_dev); 469 467 470 468 /* Undo the runtime PM settings in local_pci_probe() */ ··· 493 489 static void pci_device_shutdown(struct device *dev) 494 490 { 495 491 struct pci_dev *pci_dev = to_pci_dev(dev); 496 - struct pci_driver *drv = to_pci_driver(dev->driver); 492 + struct pci_driver *drv = pci_dev->driver; 497 493 498 494 pm_runtime_resume(dev); 499 495 ··· 589 585 static int pci_legacy_suspend(struct device *dev, pm_message_t state) 590 586 { 591 587 struct pci_dev *pci_dev = to_pci_dev(dev); 592 - struct pci_driver *drv = to_pci_driver(dev->driver); 588 + struct pci_driver *drv = pci_dev->driver; 593 589 594 590 if (drv && drv->suspend) { 595 591 pci_power_t prev = pci_dev->current_state; ··· 630 626 static int pci_legacy_resume(struct device *dev) 631 627 { 632 628 struct pci_dev *pci_dev = to_pci_dev(dev); 633 - struct pci_driver *drv = to_pci_driver(dev->driver); 629 + struct pci_driver *drv = pci_dev->driver; 634 630 635 631 pci_fixup_device(pci_fixup_resume, pci_dev); 636 632 ··· 649 645 650 646 static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) 651 647 { 652 - struct pci_driver *drv = to_pci_driver(pci_dev->dev.driver); 648 + struct pci_driver *drv = pci_dev->driver; 653 649 bool ret = drv && (drv->suspend || drv->resume); 654 650 655 651 /* ··· 1242 1238 int error; 1243 1239 1244 1240 /* 1245 - * If the device has no driver, we leave it in D0, but it may go to 1246 - * D3cold when the bridge above it runtime suspends. Save its 1247 - * config space in case that happens. 1241 + * If pci_dev->driver is not set (unbound), we leave the device in D0, 1242 + * but it may go to D3cold when the bridge above it runtime suspends. 1243 + * Save its config space in case that happens. 1248 1244 */ 1249 - if (!to_pci_driver(dev->driver)) { 1245 + if (!pci_dev->driver) { 1250 1246 pci_save_state(pci_dev); 1251 1247 return 0; 1252 1248 } ··· 1303 1299 */ 1304 1300 pci_restore_standard_config(pci_dev); 1305 1301 1306 - if (!to_pci_driver(dev->driver)) 1302 + if (!pci_dev->driver) 1307 1303 return 0; 1308 1304 1309 1305 pci_fixup_device(pci_fixup_resume_early, pci_dev); ··· 1322 1318 1323 1319 static int pci_pm_runtime_idle(struct device *dev) 1324 1320 { 1321 + struct pci_dev *pci_dev = to_pci_dev(dev); 1325 1322 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 1326 1323 1327 1324 /* 1328 - * If the device has no driver, it should always remain in D0 1329 - * regardless of the runtime PM status 1325 + * If pci_dev->driver is not set (unbound), the device should 1326 + * always remain in D0 regardless of the runtime PM status 1330 1327 */ 1331 - if (!to_pci_driver(dev->driver)) 1328 + if (!pci_dev->driver) 1332 1329 return 0; 1333 1330 1334 1331 if (!pm) ··· 1436 1431 */ 1437 1432 struct pci_driver *pci_dev_driver(const struct pci_dev *dev) 1438 1433 { 1439 - struct pci_driver *drv = to_pci_driver(dev->dev.driver); 1440 - 1441 - if (drv) 1442 - return drv; 1434 + if (dev->driver) 1435 + return dev->driver; 1443 1436 else { 1444 1437 int i; 1445 1438 for (i = 0; i <= PCI_ROM_RESOURCE; i++)
+8 -9
drivers/pci/pci.c
··· 5135 5135 5136 5136 static void pci_dev_save_and_disable(struct pci_dev *dev) 5137 5137 { 5138 - struct pci_driver *drv = to_pci_driver(dev->dev.driver); 5139 5138 const struct pci_error_handlers *err_handler = 5140 - drv ? drv->err_handler : NULL; 5139 + dev->driver ? dev->driver->err_handler : NULL; 5141 5140 5142 5141 /* 5143 - * drv->err_handler->reset_prepare() is protected against races 5144 - * with ->remove() by the device lock, which must be held by the 5145 - * caller. 5142 + * dev->driver->err_handler->reset_prepare() is protected against 5143 + * races with ->remove() by the device lock, which must be held by 5144 + * the caller. 5146 5145 */ 5147 5146 if (err_handler && err_handler->reset_prepare) 5148 5147 err_handler->reset_prepare(dev); ··· 5166 5167 5167 5168 static void pci_dev_restore(struct pci_dev *dev) 5168 5169 { 5169 - struct pci_driver *drv = to_pci_driver(dev->dev.driver); 5170 5170 const struct pci_error_handlers *err_handler = 5171 - drv ? drv->err_handler : NULL; 5171 + dev->driver ? dev->driver->err_handler : NULL; 5172 5172 5173 5173 pci_restore_state(dev); 5174 5174 5175 5175 /* 5176 - * drv->err_handler->reset_done() is protected against races with 5177 - * ->remove() by the device lock, which must be held by the caller. 5176 + * dev->driver->err_handler->reset_done() is protected against 5177 + * races with ->remove() by the device lock, which must be held by 5178 + * the caller. 5178 5179 */ 5179 5180 if (err_handler && err_handler->reset_done) 5180 5181 err_handler->reset_done(dev);
+4 -4
drivers/pci/pcie/err.c
··· 54 54 const struct pci_error_handlers *err_handler; 55 55 56 56 device_lock(&dev->dev); 57 - pdrv = to_pci_driver(dev->dev.driver); 57 + pdrv = dev->driver; 58 58 if (!pci_dev_set_io_state(dev, state) || 59 59 !pdrv || 60 60 !pdrv->err_handler || ··· 98 98 const struct pci_error_handlers *err_handler; 99 99 100 100 device_lock(&dev->dev); 101 - pdrv = to_pci_driver(dev->dev.driver); 101 + pdrv = dev->driver; 102 102 if (!pdrv || 103 103 !pdrv->err_handler || 104 104 !pdrv->err_handler->mmio_enabled) ··· 119 119 const struct pci_error_handlers *err_handler; 120 120 121 121 device_lock(&dev->dev); 122 - pdrv = to_pci_driver(dev->dev.driver); 122 + pdrv = dev->driver; 123 123 if (!pdrv || 124 124 !pdrv->err_handler || 125 125 !pdrv->err_handler->slot_reset) ··· 139 139 const struct pci_error_handlers *err_handler; 140 140 141 141 device_lock(&dev->dev); 142 - pdrv = to_pci_driver(dev->dev.driver); 142 + pdrv = dev->driver; 143 143 if (!pci_dev_set_io_state(dev, pci_channel_io_normal) || 144 144 !pdrv || 145 145 !pdrv->err_handler ||
+1
include/linux/pci.h
··· 342 342 u16 pcie_flags_reg; /* Cached PCIe Capabilities Register */ 343 343 unsigned long *dma_alias_mask;/* Mask of enabled devfn aliases */ 344 344 345 + struct pci_driver *driver; /* Driver bound to this device */ 345 346 u64 dma_mask; /* Mask of the bits of bus address this 346 347 device implements. Normally this is 347 348 0xffffffff. You only need to change