From 9879843d51b342292c9726dc1d095cb2880c4e27 Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Date: Tue, 13 Aug 2013 11:04:06 -0300 Subject: [PATCH] upstream: [media] v4l2-dev: Fix race condition on __video_register_device When 2 devices are registered at the same time, in Part 2 both will get the same minor number, making Part6 crash, because it cannot create a create a device with a duplicated minor: [ 7.157648] ------------[ cut here ]------------ [ 7.157666] WARNING: at fs/sysfs/dir.c:530 sysfs_add_one+0xbd/0xe0() [ 7.157669] sysfs: cannot create duplicate filename '/dev/char/81:1' [ 7.157672] Modules linked in: qtec_xform(+) qt5023_video(+) videobuf2_vmalloc videobuf2_dma_sg videobuf2_memops videobuf2_core gpio_xilinx(+) qtec_white qtec_cmosis(+) qtec_pcie qt5023 [ 7.157694] CPU: 0 PID: 120 Comm: systemd-udevd Not tainted 3.10.0-qtec-standard #8 [ 7.157698] Hardware name: QTechnology QT5022/QT5022, BIOS PM_2.1.0.309 X64 05/23/2013 [ 7.157702] 0000000000000009 ffff8801788358e8 ffffffff8176c487 ffff880178835928 [ 7.157707] ffffffff8106f6f0 ffff880175759770 00000000ffffffef ffff880175759930 [ 7.157712] ffff8801788359e8 ffff880178bff000 ffff880175759930 ffff880178835988 [ 7.157718] Call Trace: [ 7.157728] [] dump_stack+0x19/0x1b [ 7.157735] [] warn_slowpath_common+0x70/0xa0 [ 7.157740] [] warn_slowpath_fmt+0x46/0x50 [ 7.157746] [] ? strlcat+0x65/0x90 [ 7.157750] [] sysfs_add_one+0xbd/0xe0 [ 7.157755] [] sysfs_do_create_link_sd+0xdb/0x200 [ 7.157760] [] sysfs_create_link+0x21/0x40 [ 7.157765] [] device_add+0x21b/0x6d0 [ 7.157772] [] ? pm_runtime_init+0xe5/0xf0 [ 7.157776] [] device_register+0x1e/0x30 [ 7.157782] [] __video_register_device+0x313/0x610 [ 7.157791] [] qtec_xform_probe+0x465/0x7a4 [qtec_xform] [ 7.157797] [] platform_drv_probe+0x43/0x80 [ 7.157802] [] ? driver_sysfs_add+0x7a/0xb0 [ 7.157807] [] driver_probe_device+0x8b/0x3a0 [ 7.157812] [] __driver_attach+0xab/0xb0 [ 7.157816] [] ? driver_probe_device+0x3a0/0x3a0 [ 7.157820] [] bus_for_each_dev+0x5d/0xa0 [ 7.157825] [] driver_attach+0x1e/0x20 [ 7.157829] [] bus_add_driver+0x10e/0x280 [ 7.157833] [] ? 0xffffffffa0098fff [ 7.157837] [] ? 0xffffffffa0098fff [ 7.157842] [] driver_register+0x77/0x170 [ 7.157848] [] ? __vunmap+0x9c/0x110 [ 7.157852] [] ? 0xffffffffa0098fff [ 7.157857] [] platform_driver_register+0x46/0x50 [ 7.157863] [] qtec_xform_plat_driver_init+0x10/0x12 [qtec_xform] [ 7.157869] [] do_one_initcall+0xea/0x1a0 [ 7.157875] [] load_module+0x1a91/0x2630 [ 7.157880] [] ? ddebug_proc_show+0xe0/0xe0 [ 7.157887] [] ? page_fault+0x22/0x30 [ 7.157892] [] SyS_init_module+0xea/0x140 [ 7.157898] [] tracesys+0xd0/0xd5 [ 7.157902] ---[ end trace 660cc3a65a4bf01b ]--- [ 7.157939] __video_register_device: device_register failed Signed-off-by: Ricardo Ribalda Delgado Acked-by: Sakari Ailus Acked-by: Hans Verkuil Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index 5ece887..f35f64a 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -871,6 +871,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr, /* Should not happen since we thought this minor was free */ WARN_ON(video_device[vdev->minor] != NULL); + video_device[vdev->minor] = vdev; vdev->index = get_index(vdev); video_device[vdev->minor] = vdev; mutex_unlock(&videodev_lock); -- 2.7.4