usbip: Use platform_device_register_full()
Subsystems (2)
PATCH 1/1 usbip: Use platform_device_register_full()
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.
--- drivers/usb/usbip/vhci_hcd.c | 42 +++++++++++------------------------- 1 file changed, 13 insertions(+), 29 deletions(-)
drivers/usb/usbip/vhci_hcd.c +13 -29
@@ -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; }
Signature · 1 line
2.40.0.1.gaa8946217a0b
kernel test robot
build botkernel test robot noticed "BUG:kernel_NULL_pointer_dereference,address" on:
Hello,
kernel test robot noticed "BUG:kernel_NULL_pointer_dereference,address" on:
commit: 86a50b56c5a09f33c75fdd6c1275188b0de61eb3 ("[PATCH v1 1/1] usbip: Use platform_device_register_full()")
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/usbip-Use-platform_device_register_full/20230817-201652
base: https://git.kernel.org/cgit/linux/kernel/git/gregkh/usb.git usb-testing
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH v1 1/1] usbip: Use platform_device_register_full()
in testcase: boot
compiler: clang-16
test machine: qemu-system-i386 -enable-kvm -cpu SandyBridge -smp 2 -m 4G
(please refer to attached dmesg/kmsg for entire log/backtrace)
+---------------------------------------------+------------+------------+ | | bbb9e06d2c | 86a50b56c5 | +---------------------------------------------+------------+------------+ | boot_successes | 20 | 0 | | boot_failures | 0 | 12 | | BUG:kernel_NULL_pointer_dereference,address | 0 | 12 | | Oops:#[##] | 0 | 12 | | EIP:vhci_setup | 0 | 12 | | Kernel_panic-not_syncing:Fatal_exception | 0 | 12 | +---------------------------------------------+------------+------------+
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]
[ 8.098949][ T1] vhci_hcd: vhci_hcd_probe:1345: name vhci_hcd id 0 [ 8.100593][ T1] vhci_hcd vhci_hcd.0: USB/IP Virtual Host Controller [ 8.102740][ T1] vhci_hcd vhci_hcd.0: new USB bus registered, assigned bus number 1 [ 8.104945][ T1] BUG: kernel NULL pointer dereference, address: 00000028 [ 8.106630][ T1] #PF: supervisor write access in kernel mode [ 8.108111][ T1] #PF: error_code(0x0002) - not-present page [ 8.109638][ T1] *pde = 00000000 [ 8.110567][ T1] Oops: 0002 [#1] PREEMPT [ 8.111655][ T1] CPU: 0 PID: 1 Comm: swapper Tainted: G S 6.5.0-rc6-00120-g86a50b56c5a0 #5 [ 8.114034][ T1] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 [ 8.114778][ T1] EIP: vhci_setup+0x22/0x60 [ 8.114778][ T1] Code: 90 90 90 90 90 90 90 90 55 89 e5 57 56 89 c6 8b 00 8b 40 3c 8b 38 89 f0 e8 8b d8 f5 ff 31 c9 85 c0 0f 94 c1 8d 86 18 02 00 00 <89> 44 8f 28 89 be 18 02 00 00 8d 04 09 83 c0 03 c1 e1 05 83 c1 20 [ 8.114778][ T1] EAX: ebb42218 EBX: ffffffea ECX: 00000000 EDX: 00000000 [ 8.114778][ T1] ESI: ebb42000 EDI: 00000000 EBP: c55f1a90 ESP: c55f1a88 [ 8.114778][ T1] DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068 EFLAGS: 00010202 [ 8.114778][ T1] CR0: 80050033 CR2: 00000028 CR3: 04782000 CR4: 00040690 [ 8.114778][ T1] DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000 [ 8.114778][ T1] DR6: fffe0ff0 DR7: 00000400 [ 8.114778][ T1] Call Trace: [ 8.114778][ T1] ? __die_body+0x64/0xb0 [ 8.114778][ T1] ? __die+0x6b/0x80 [ 8.114778][ T1] ? page_fault_oops+0x2bd/0x2f0 [ 8.114778][ T1] ? kernelmode_fixup_or_oops+0xab/0xc0 [ 8.114778][ T1] ? __bad_area_nosemaphore+0x40/0x1b0 [ 8.114778][ T1] ? bad_area_nosemaphore+0xd/0x20 [ 8.114778][ T1] ? do_user_addr_fault+0x382/0x410 [ 8.114778][ T1] ? exc_page_fault+0x4f/0xe0 [ 8.114778][ T1] ? pvclock_clocksource_read_nowd+0x170/0x170 [ 8.114778][ T1] ? handle_exception+0x14c/0x14c [ 8.114778][ T1] ? pvclock_clocksource_read_nowd+0x170/0x170 [ 8.114778][ T1] ? vhci_setup+0x22/0x60 [ 8.114778][ T1] ? pvclock_clocksource_read_nowd+0x170/0x170 [ 8.114778][ T1] ? vhci_setup+0x22/0x60 [ 8.114778][ T1] usb_add_hcd+0x240/0x490 [ 8.114778][ T1] vhci_hcd_probe+0x79/0x1b0 [ 8.114778][ T1] platform_probe+0x5a/0x80 [ 8.114778][ T1] really_probe+0x14d/0x3b0 [ 8.114778][ T1] __driver_probe_device+0x78/0x180 [ 8.114778][ T1] driver_probe_device+0x19/0xf0 [ 8.114778][ T1] __device_attach_driver+0xb5/0x110 [ 8.114778][ T1] bus_for_each_drv+0xe0/0x120 [ 8.114778][ T1] ? __pm_runtime_resume+0x66/0x80 [ 8.114778][ T1] __device_attach+0xae/0x170 [ 8.114778][ T1] ? coredump_store+0x40/0x40 [ 8.114778][ T1] device_initial_probe+0xf/0x20 [ 8.114778][ T1] bus_probe_device+0x7b/0xd0 [ 8.114778][ T1] device_add+0x2a5/0x4b0 [ 8.114778][ T1] ? dev_set_name+0x15/0x20 [ 8.114778][ T1] platform_device_add+0x7b/0x230 [ 8.114778][ T1] platform_device_register_full+0x1a8/0x1f0 [ 8.114778][ T1] vhci_hcd_init+0xce/0x150 [ 8.114778][ T1] do_one_initcall+0x193/0x310 [ 8.114778][ T1] ? usbip_core_init+0x10/0x10 [ 8.114778][ T1] do_initcall_level+0x93/0xc0 [ 8.114778][ T1] ? rest_init+0x170/0x170 [ 8.114778][ T1] do_initcalls+0x36/0x70 [ 8.114778][ T1] ? rest_init+0x170/0x170 [ 8.114778][ T1] do_basic_setup+0x12/0x20 [ 8.114778][ T1] kernel_init_freeable+0x63/0xb0 [ 8.114778][ T1] kernel_init+0x12/0x190 [ 8.114778][ T1] ret_from_fork+0x2c/0x40 [ 8.114778][ T1] ret_from_fork_asm+0x12/0x20 [ 8.114778][ T1] entry_INT80_32+0x10c/0x10c [ 8.114778][ T1] Modules linked in: [ 8.114778][ T1] CR2: 0000000000000028 [ 8.114778][ T1] ---[ end trace 0000000000000000 ]--- [ 8.114778][ T1] EIP: vhci_setup+0x22/0x60 [ 8.114778][ T1] Code: 90 90 90 90 90 90 90 90 55 89 e5 57 56 89 c6 8b 00 8b 40 3c 8b 38 89 f0 e8 8b d8 f5 ff 31 c9 85 c0 0f 94 c1 8d 86 18 02 00 00 <89> 44 8f 28 89 be 18 02 00 00 8d 04 09 83 c0 03 c1 e1 05 83 c1 20 [ 8.114778][ T1] EAX: ebb42218 EBX: ffffffea ECX: 00000000 EDX: 00000000 [ 8.114778][ T1] ESI: ebb42000 EDI: 00000000 EBP: c55f1a90 ESP: c55f1a88 [ 8.114778][ T1] DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068 EFLAGS: 00010202 [ 8.114778][ T1] CR0: 80050033 CR2: 00000028 CR3: 04782000 CR4: 00040690 [ 8.114778][ T1] DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000 [ 8.114778][ T1] DR6: fffe0ff0 DR7: 00000400 [ 8.114778][ T1] Kernel panic - not syncing: Fatal exception [ 8.114778][ T1] Kernel Offset: disabled
The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20230818/[email protected]
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Shuah Khan
maintainerQuoted 9 lines · Andy Shevchenko
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 <[email protected]>--- 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
Quoted 1 line · Shuah Khan
On 8/17/23 06:13, Andy Shevchenko wrote:
...
Quoted 3 lines
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko