On 05/18/2017 04:08 AM, Yuyang Du wrote: > From: Yuyang Du <yuyang.du@xxxxxxxxx> > > A vhci struct is added as the platform-specific data to the vhci > platform device, in order to get the vhci by its platform device. > This is done in vhci_hcd_init(). > > Signed-off-by: Yuyang Du <yuyang.du@xxxxxxxxx> Acked-by: Shuah Khan <shuahkh@xxxxxxxxxxxxxxx> thanks, -- Shuah > --- > drivers/usb/usbip/vhci_hcd.c | 51 ++++++++++++++++++++---------------- > tools/usb/usbip/libsrc/vhci_driver.c | 2 +- > tools/usb/usbip/libsrc/vhci_driver.h | 1 + > 3 files changed, 30 insertions(+), 24 deletions(-) > > diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c > index 7a04497..2bc77ee 100644 > --- a/drivers/usb/usbip/vhci_hcd.c > +++ b/drivers/usb/usbip/vhci_hcd.c > @@ -1173,24 +1173,6 @@ static struct platform_driver vhci_driver = { > }, > }; > > -static int add_platform_device(int id) > -{ > - struct platform_device *pdev; > - int dev_nr; > - > - if (id == 0) > - dev_nr = -1; > - else > - dev_nr = id; > - > - pdev = platform_device_register_simple(driver_name, dev_nr, NULL, 0); > - if (IS_ERR(pdev)) > - return PTR_ERR(pdev); > - > - vhcis[id].pdev = pdev; > - return 0; > -} > - > static void del_platform_devices(void) > { > struct platform_device *pdev; > @@ -1219,23 +1201,46 @@ static int __init vhci_hcd_init(void) > if (vhcis == NULL) > return -ENOMEM; > > + for (i = 0; i < vhci_num_controllers; i++) { > + vhcis[i].pdev = platform_device_alloc(driver_name, i); > + if (!vhcis[i].pdev) { > + i--; > + while (i >= 0) > + platform_device_put(vhcis[i--].pdev); > + ret = -ENOMEM; > + goto err_device_alloc; > + } > + } > + for (i = 0; i < vhci_num_controllers; i++) { > + void *vhci = &vhcis[i]; > + ret = platform_device_add_data(vhcis[i].pdev, &vhci, sizeof(void *)); > + if (ret) > + goto err_driver_register; > + } > + > ret = platform_driver_register(&vhci_driver); > if (ret) > goto err_driver_register; > > for (i = 0; i < vhci_num_controllers; i++) { > - ret = add_platform_device(i); > - if (ret) > - goto err_platform_device_register; > + ret = platform_device_add(vhcis[i].pdev); > + if (ret < 0) { > + i--; > + while (i >= 0) > + platform_device_del(vhcis[i--].pdev); > + goto err_add_hcd; > + } > } > > pr_info(DRIVER_DESC " v" USBIP_VERSION "\n"); > return ret; > > -err_platform_device_register: > - del_platform_devices(); > +err_add_hcd: > platform_driver_unregister(&vhci_driver); > err_driver_register: > + for (i = 0; i < vhci_num_controllers; i++) > + platform_device_put(vhcis[i].pdev); > +err_device_alloc: > kfree(vhcis); > return ret; > } > diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c > index af88447..5b19a32 100644 > --- a/tools/usb/usbip/libsrc/vhci_driver.c > +++ b/tools/usb/usbip/libsrc/vhci_driver.c > @@ -248,7 +248,7 @@ int usbip_vhci_driver_open(void) > vhci_driver->hc_device = > udev_device_new_from_subsystem_sysname(udev_context, > USBIP_VHCI_BUS_TYPE, > - USBIP_VHCI_DRV_NAME); > + USBIP_VHCI_DEVICE_NAME); > if (!vhci_driver->hc_device) { > err("udev_device_new_from_subsystem_sysname failed"); > goto err; > diff --git a/tools/usb/usbip/libsrc/vhci_driver.h b/tools/usb/usbip/libsrc/vhci_driver.h > index 33add14..dfe19c1 100644 > --- a/tools/usb/usbip/libsrc/vhci_driver.h > +++ b/tools/usb/usbip/libsrc/vhci_driver.h > @@ -11,6 +11,7 @@ > #include "usbip_common.h" > > #define USBIP_VHCI_BUS_TYPE "platform" > +#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0" > #define MAXNPORT 128 > > struct usbip_imported_device { > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html