diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2010-12-31 09:47:23 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-01-19 08:52:13 -0500 |
commit | 46b633779b299c7fb3d78f153a5034055f99cd45 (patch) | |
tree | 45db9a1313d43a9438f105f3d257cc592cf050a6 /drivers | |
parent | 6ce3ced4f73e3f0c345f47dc99fd21f2248724a8 (diff) |
[media] v4l2-dev: don't memset video_device.dev
Zeroing video_device.dev causes a memory leak if video_set_drvdata
was called before video_register_device was called. video_set_drvdata
calls dev_set_drvdata which allocates video_device.dev.p.
memsetting this will prevent freeing of that memory.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/v4l2-dev.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 359e23290a7e..341764a3a990 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c | |||
@@ -419,6 +419,10 @@ static int get_index(struct video_device *vdev) | |||
419 | * The registration code assigns minor numbers and device node numbers | 419 | * The registration code assigns minor numbers and device node numbers |
420 | * based on the requested type and registers the new device node with | 420 | * based on the requested type and registers the new device node with |
421 | * the kernel. | 421 | * the kernel. |
422 | * | ||
423 | * This function assumes that struct video_device was zeroed when it | ||
424 | * was allocated and does not contain any stale date. | ||
425 | * | ||
422 | * An error is returned if no free minor or device node number could be | 426 | * An error is returned if no free minor or device node number could be |
423 | * found, or if the registration of the device node failed. | 427 | * found, or if the registration of the device node failed. |
424 | * | 428 | * |
@@ -440,7 +444,6 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, | |||
440 | int minor_offset = 0; | 444 | int minor_offset = 0; |
441 | int minor_cnt = VIDEO_NUM_DEVICES; | 445 | int minor_cnt = VIDEO_NUM_DEVICES; |
442 | const char *name_base; | 446 | const char *name_base; |
443 | void *priv = vdev->dev.p; | ||
444 | 447 | ||
445 | /* A minor value of -1 marks this video device as never | 448 | /* A minor value of -1 marks this video device as never |
446 | having been registered */ | 449 | having been registered */ |
@@ -559,10 +562,6 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, | |||
559 | } | 562 | } |
560 | 563 | ||
561 | /* Part 4: register the device with sysfs */ | 564 | /* Part 4: register the device with sysfs */ |
562 | memset(&vdev->dev, 0, sizeof(vdev->dev)); | ||
563 | /* The memset above cleared the device's device_private, so | ||
564 | put back the copy we made earlier. */ | ||
565 | vdev->dev.p = priv; | ||
566 | vdev->dev.class = &video_class; | 565 | vdev->dev.class = &video_class; |
567 | vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); | 566 | vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); |
568 | if (vdev->parent) | 567 | if (vdev->parent) |