Skip to content

Commit dff3565

Browse files
ydu19gregkh
authored andcommitted
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>
1 parent 89a73d2 commit dff3565

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎drivers/usb/usbip/vhci_hcd.c‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,24 +1178,6 @@ static struct platform_driver vhci_driver = {
11781178
},
11791179
};
11801180

1181-
static int add_platform_device(int id)
1182-
{
1183-
struct platform_device *pdev;
1184-
int dev_nr;
1185-
1186-
if (id == 0)
1187-
dev_nr = -1;
1188-
else
1189-
dev_nr = id;
1190-
1191-
pdev = platform_device_register_simple(driver_name, dev_nr, NULL, 0);
1192-
if (IS_ERR(pdev))
1193-
return PTR_ERR(pdev);
1194-
1195-
vhcis[id].pdev = pdev;
1196-
return 0;
1197-
}
1198-
11991181
static void del_platform_devices(void)
12001182
{
12011183
struct platform_device *pdev;
@@ -1224,23 +1206,46 @@ static int __init vhci_hcd_init(void)
12241206
if (vhcis == NULL)
12251207
return -ENOMEM;
12261208

1209+
for (i = 0; i < vhci_num_controllers; i++) {
1210+
vhcis[i].pdev = platform_device_alloc(driver_name, i);
1211+
if (!vhcis[i].pdev) {
1212+
i--;
1213+
while (i >= 0)
1214+
platform_device_put(vhcis[i--].pdev);
1215+
ret = -ENOMEM;
1216+
goto err_device_alloc;
1217+
}
1218+
}
1219+
for (i = 0; i < vhci_num_controllers; i++) {
1220+
void *vhci = &vhcis[i];
1221+
ret = platform_device_add_data(vhcis[i].pdev, &vhci, sizeof(void *));
1222+
if (ret)
1223+
goto err_driver_register;
1224+
}
1225+
12271226
ret = platform_driver_register(&vhci_driver);
12281227
if (ret)
12291228
goto err_driver_register;
12301229

12311230
for (i = 0; i < vhci_num_controllers; i++) {
1232-
ret = add_platform_device(i);
1233-
if (ret)
1234-
goto err_platform_device_register;
1231+
ret = platform_device_add(vhcis[i].pdev);
1232+
if (ret < 0) {
1233+
i--;
1234+
while (i >= 0)
1235+
platform_device_del(vhcis[i--].pdev);
1236+
goto err_add_hcd;
1237+
}
12351238
}
12361239

12371240
pr_info(DRIVER_DESC " v" USBIP_VERSION "\n");
12381241
return ret;
12391242

1240-
err_platform_device_register:
1241-
del_platform_devices();
1243+
err_add_hcd:
12421244
platform_driver_unregister(&vhci_driver);
12431245
err_driver_register:
1246+
for (i = 0; i < vhci_num_controllers; i++)
1247+
platform_device_put(vhcis[i].pdev);
1248+
err_device_alloc:
12441249
kfree(vhcis);
12451250
return ret;
12461251
}

‎tools/usb/usbip/libsrc/vhci_driver.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ int usbip_vhci_driver_open(void)
248248
vhci_driver->hc_device =
249249
udev_device_new_from_subsystem_sysname(udev_context,
250250
USBIP_VHCI_BUS_TYPE,
251-
USBIP_VHCI_DRV_NAME);
251+
USBIP_VHCI_DEVICE_NAME);
252252
if (!vhci_driver->hc_device) {
253253
err("udev_device_new_from_subsystem_sysname failed");
254254
goto err;

‎tools/usb/usbip/libsrc/vhci_driver.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "usbip_common.h"
1212

1313
#define USBIP_VHCI_BUS_TYPE "platform"
14+
#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0"
1415
#define MAXNPORT 128
1516

1617
struct usbip_imported_device {

0 commit comments

Comments
 (0)