diff mbox series

[v1,1/1] usbip: Use platform_device_register_full()

Message ID 20230817121300.501637-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/1] usbip: Use platform_device_register_full() | expand

Commit Message

Andy Shevchenko Aug. 17, 2023, 12:13 p.m. UTC
The code to create the child platform device is essentially the same as
what platform_device_register_full() does, so change over to use
that same function to reduce duplication.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/usb/usbip/vhci_hcd.c | 42 +++++++++++-------------------------
 1 file changed, 13 insertions(+), 29 deletions(-)

Comments

Shuah Khan Aug. 22, 2023, 2:11 p.m. UTC | #1
On 8/17/23 06:13, Andy Shevchenko wrote:
> The code to create the child platform device is essentially the same as
> what platform_device_register_full() does, so change over to use
> that same function to reduce duplication.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>   drivers/usb/usbip/vhci_hcd.c | 42 +++++++++++-------------------------
>   1 file changed, 13 insertions(+), 29 deletions(-)
> 

Please address the following problem and send v2.

kernel test robot noticed "BUG:kernel_NULL_pointer_dereference,address" on:

thanks,
-- Shuah
Andy Shevchenko Aug. 22, 2023, 2:30 p.m. UTC | #2
On Tue, Aug 22, 2023 at 08:11:19AM -0600, Shuah Khan wrote:
> On 8/17/23 06:13, Andy Shevchenko wrote:

...

> Please address the following problem and send v2.
> 
> kernel test robot noticed "BUG:kernel_NULL_pointer_dereference,address" on:

Yep, I am aware of this, just haven't had time to look into.
diff mbox series

Patch

diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 37d1fc34e8a5..101700c89461 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1493,13 +1493,10 @@  static struct platform_driver vhci_driver = {
 
 static void del_platform_devices(void)
 {
-	struct platform_device *pdev;
 	int i;
 
 	for (i = 0; i < vhci_num_controllers; i++) {
-		pdev = vhcis[i].pdev;
-		if (pdev != NULL)
-			platform_device_unregister(pdev);
+		platform_device_unregister(vhcis[i].pdev);
 		vhcis[i].pdev = NULL;
 	}
 	sysfs_remove_link(&platform_bus.kobj, driver_name);
@@ -1519,45 +1516,32 @@  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 = platform_device_add(vhcis[i].pdev);
+		struct platform_device_info pdevinfo = {
+			.name = driver_name,
+			.id = i,
+			.data = &vhcis[i],
+			.size_data = sizeof(void *),
+		};
+
+		vhcis[i].pdev = platform_device_register_full(&pdevinfo);
+		ret = PTR_ERR_OR_ZERO(vhcis[i].pdev);
 		if (ret < 0) {
-			i--;
-			while (i >= 0)
-				platform_device_del(vhcis[i--].pdev);
+			while (i--)
+				platform_device_unregister(vhcis[i].pdev);
 			goto err_add_hcd;
 		}
 	}
 
-	return ret;
+	return 0;
 
 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;
 }