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>hifive-unleashed-5.1
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)
|
static void del_platform_devices(void)
|
||||||
{
|
{
|
||||||
struct platform_device *pdev;
|
struct platform_device *pdev;
|
||||||
|
@ -1224,23 +1206,46 @@ static int __init vhci_hcd_init(void)
|
||||||
if (vhcis == NULL)
|
if (vhcis == NULL)
|
||||||
return -ENOMEM;
|
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);
|
ret = platform_driver_register(&vhci_driver);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_driver_register;
|
goto err_driver_register;
|
||||||
|
|
||||||
for (i = 0; i < vhci_num_controllers; i++) {
|
for (i = 0; i < vhci_num_controllers; i++) {
|
||||||
ret = add_platform_device(i);
|
ret = platform_device_add(vhcis[i].pdev);
|
||||||
if (ret)
|
if (ret < 0) {
|
||||||
goto err_platform_device_register;
|
i--;
|
||||||
|
while (i >= 0)
|
||||||
|
platform_device_del(vhcis[i--].pdev);
|
||||||
|
goto err_add_hcd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
|
pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
err_platform_device_register:
|
err_add_hcd:
|
||||||
del_platform_devices();
|
|
||||||
platform_driver_unregister(&vhci_driver);
|
platform_driver_unregister(&vhci_driver);
|
||||||
err_driver_register:
|
err_driver_register:
|
||||||
|
for (i = 0; i < vhci_num_controllers; i++)
|
||||||
|
platform_device_put(vhcis[i].pdev);
|
||||||
|
err_device_alloc:
|
||||||
kfree(vhcis);
|
kfree(vhcis);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ int usbip_vhci_driver_open(void)
|
||||||
vhci_driver->hc_device =
|
vhci_driver->hc_device =
|
||||||
udev_device_new_from_subsystem_sysname(udev_context,
|
udev_device_new_from_subsystem_sysname(udev_context,
|
||||||
USBIP_VHCI_BUS_TYPE,
|
USBIP_VHCI_BUS_TYPE,
|
||||||
USBIP_VHCI_DRV_NAME);
|
USBIP_VHCI_DEVICE_NAME);
|
||||||
if (!vhci_driver->hc_device) {
|
if (!vhci_driver->hc_device) {
|
||||||
err("udev_device_new_from_subsystem_sysname failed");
|
err("udev_device_new_from_subsystem_sysname failed");
|
||||||
goto err;
|
goto err;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "usbip_common.h"
|
#include "usbip_common.h"
|
||||||
|
|
||||||
#define USBIP_VHCI_BUS_TYPE "platform"
|
#define USBIP_VHCI_BUS_TYPE "platform"
|
||||||
|
#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0"
|
||||||
#define MAXNPORT 128
|
#define MAXNPORT 128
|
||||||
|
|
||||||
struct usbip_imported_device {
|
struct usbip_imported_device {
|
||||||
|
|
Loading…
Reference in New Issue