summaryrefslogtreecommitdiffstats
path: root/drivers/usb/usbip/vhci_hcd.c
diff options
context:
space:
mode:
authorYuyang Du <yuyang.du@intel.com>2017-06-08 13:04:08 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-06-13 10:51:10 +0200
commitdff3565b8e1c0be6fc83ba47dcab45c149dcab5b (patch)
treeeecdc8e61cba37461c7711a55b7725620ec1a38e /drivers/usb/usbip/vhci_hcd.c
parent89a73d281fa4f58942474ada19d34d7ea39af2f4 (diff)
downloadtalos-op-linux-dff3565b8e1c0be6fc83ba47dcab45c149dcab5b.tar.gz
talos-op-linux-dff3565b8e1c0be6fc83ba47dcab45c149dcab5b.zip
usbip: vhci-hcd: Rework vhci_hcd_init
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@intel.com> Acked-by: Shuah Khan <shuahkh@osg.samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/usbip/vhci_hcd.c')
-rw-r--r--drivers/usb/usbip/vhci_hcd.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index a445d237b0c3..893a5dedd0e5 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1178,24 +1178,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;
@@ -1224,23 +1206,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;
}
OpenPOWER on IntegriCloud