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>
This commit is contained in:
parent
89a73d281f
commit
dff3565b8e
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user