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

usb: hci: add hc_driver as argument for usb_hcd_pci_probe

usb_hcd_pci_probe expects users to call this with driver_data set as
hc_driver, that limits the possibility of using the driver_data for
driver data.

Add hc_driver as argument to usb_hcd_pci_probe and modify the callers
ehci/ohci/xhci/uhci to pass hc_driver as argument and freeup the
driver_data used

Tested xhci driver on Dragon-board RB3, compile tested ehci, ohci and
uhci.

[For all but the xHCI parts]
[For the xhci part]

Suggested-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Link: https://lore.kernel.org/r/20200514122039.300417-2-vkoul@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Vinod Koul and committed by
Greg Kroah-Hartman
ff4c65ca c33f4f24

+25 -22
+4 -3
drivers/usb/core/hcd-pci.c
··· 159 159 * usb_hcd_pci_probe - initialize PCI-based HCDs 160 160 * @dev: USB Host Controller being probed 161 161 * @id: pci hotplug id connecting controller to HCD framework 162 + * @driver: USB HC driver handle 162 163 * Context: !in_interrupt() 163 164 * 164 165 * Allocates basic PCI resources for this USB host controller, and ··· 170 169 * 171 170 * Return: 0 if successful. 172 171 */ 173 - int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 172 + int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id, 173 + const struct hc_driver *driver) 174 174 { 175 - struct hc_driver *driver; 176 175 struct usb_hcd *hcd; 177 176 int retval; 178 177 int hcd_irq = 0; ··· 182 181 183 182 if (!id) 184 183 return -EINVAL; 185 - driver = (struct hc_driver *)id->driver_data; 184 + 186 185 if (!driver) 187 186 return -EINVAL; 188 187
+2 -4
drivers/usb/host/ehci-pci.c
··· 360 360 { 361 361 if (is_bypassed_id(pdev)) 362 362 return -ENODEV; 363 - return usb_hcd_pci_probe(pdev, id); 363 + return usb_hcd_pci_probe(pdev, id, &ehci_pci_hc_driver); 364 364 } 365 365 366 366 static void ehci_pci_remove(struct pci_dev *pdev) 367 367 { 368 368 pci_clear_mwi(pdev); 369 - usb_hcd_pci_remove(pdev); 369 + usb_hcd_pci_remove(pdev); 370 370 } 371 371 372 372 /* PCI driver selection metadata; PCI hotplugging uses this */ 373 373 static const struct pci_device_id pci_ids [] = { { 374 374 /* handle any USB 2.0 EHCI controller */ 375 375 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0), 376 - .driver_data = (unsigned long) &ehci_pci_hc_driver, 377 376 }, { 378 377 PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_HOST), 379 - .driver_data = (unsigned long) &ehci_pci_hc_driver, 380 378 }, 381 379 { /* end: all zeroes */ } 382 380 };
+6 -3
drivers/usb/host/ohci-pci.c
··· 277 277 static const struct pci_device_id pci_ids[] = { { 278 278 /* handle any USB OHCI controller */ 279 279 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0), 280 - .driver_data = (unsigned long) &ohci_pci_hc_driver, 281 280 }, { 282 281 /* The device in the ConneXT I/O hub has no class reg */ 283 282 PCI_VDEVICE(STMICRO, PCI_DEVICE_ID_STMICRO_USB_OHCI), 284 - .driver_data = (unsigned long) &ohci_pci_hc_driver, 285 283 }, { /* end: all zeroes */ } 286 284 }; 287 285 MODULE_DEVICE_TABLE (pci, pci_ids); 286 + 287 + static int ohci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 288 + { 289 + return usb_hcd_pci_probe(dev, id, &ohci_pci_hc_driver); 290 + } 288 291 289 292 /* pci driver glue; this is a "new style" PCI driver module */ 290 293 static struct pci_driver ohci_pci_driver = { 291 294 .name = hcd_name, 292 295 .id_table = pci_ids, 293 296 294 - .probe = usb_hcd_pci_probe, 297 + .probe = ohci_pci_probe, 295 298 .remove = usb_hcd_pci_remove, 296 299 .shutdown = usb_hcd_pci_shutdown, 297 300
+6 -2
drivers/usb/host/uhci-pci.c
··· 287 287 static const struct pci_device_id uhci_pci_ids[] = { { 288 288 /* handle any USB UHCI controller */ 289 289 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0), 290 - .driver_data = (unsigned long) &uhci_driver, 291 290 }, { /* end: all zeroes */ } 292 291 }; 293 292 294 293 MODULE_DEVICE_TABLE(pci, uhci_pci_ids); 295 294 295 + static int uhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 296 + { 297 + return usb_hcd_pci_probe(dev, id, &uhci_driver); 298 + } 299 + 296 300 static struct pci_driver uhci_pci_driver = { 297 301 .name = hcd_name, 298 302 .id_table = uhci_pci_ids, 299 303 300 - .probe = usb_hcd_pci_probe, 304 + .probe = uhci_pci_probe, 301 305 .remove = usb_hcd_pci_remove, 302 306 .shutdown = uhci_shutdown, 303 307
+5 -9
drivers/usb/host/xhci-pci.c
··· 327 327 { 328 328 int retval; 329 329 struct xhci_hcd *xhci; 330 - struct hc_driver *driver; 331 330 struct usb_hcd *hcd; 332 - 333 - driver = (struct hc_driver *)id->driver_data; 334 331 335 332 /* Prevent runtime suspending between USB-2 and USB-3 initialization */ 336 333 pm_runtime_get_noresume(&dev->dev); ··· 338 341 * to say USB 2.0, but I'm not sure what the implications would be in 339 342 * the other parts of the HCD code. 340 343 */ 341 - retval = usb_hcd_pci_probe(dev, id); 344 + retval = usb_hcd_pci_probe(dev, id, &xhci_pci_hc_driver); 342 345 343 346 if (retval) 344 347 goto put_runtime_pm; ··· 346 349 /* USB 2.0 roothub is stored in the PCI device now. */ 347 350 hcd = dev_get_drvdata(&dev->dev); 348 351 xhci = hcd_to_xhci(hcd); 349 - xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev, 350 - pci_name(dev), hcd); 352 + xhci->shared_hcd = usb_create_shared_hcd(&xhci_pci_hc_driver, &dev->dev, 353 + pci_name(dev), hcd); 351 354 if (!xhci->shared_hcd) { 352 355 retval = -ENOMEM; 353 356 goto dealloc_usb2_hcd; ··· 541 544 /*-------------------------------------------------------------------------*/ 542 545 543 546 /* PCI driver selection metadata; PCI hotplugging uses this */ 544 - static const struct pci_device_id pci_ids[] = { { 547 + static const struct pci_device_id pci_ids[] = { 545 548 /* handle any USB 3.0 xHCI controller */ 546 - PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), 547 - .driver_data = (unsigned long) &xhci_pci_hc_driver, 549 + { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), 548 550 }, 549 551 { /* end: all zeroes */ } 550 552 };
+2 -1
include/linux/usb/hcd.h
··· 479 479 struct pci_dev; 480 480 struct pci_device_id; 481 481 extern int usb_hcd_pci_probe(struct pci_dev *dev, 482 - const struct pci_device_id *id); 482 + const struct pci_device_id *id, 483 + const struct hc_driver *driver); 483 484 extern void usb_hcd_pci_remove(struct pci_dev *dev); 484 485 extern void usb_hcd_pci_shutdown(struct pci_dev *dev); 485 486