forked from Minki/linux
[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>
This commit is contained in:
parent
6ce3ced4f7
commit
46b633779b
@ -419,6 +419,10 @@ static int get_index(struct video_device *vdev)
|
|||||||
* The registration code assigns minor numbers and device node numbers
|
* The registration code assigns minor numbers and device node numbers
|
||||||
* based on the requested type and registers the new device node with
|
* based on the requested type and registers the new device node with
|
||||||
* the kernel.
|
* the kernel.
|
||||||
|
*
|
||||||
|
* This function assumes that struct video_device was zeroed when it
|
||||||
|
* was allocated and does not contain any stale date.
|
||||||
|
*
|
||||||
* An error is returned if no free minor or device node number could be
|
* An error is returned if no free minor or device node number could be
|
||||||
* found, or if the registration of the device node failed.
|
* found, or if the registration of the device node failed.
|
||||||
*
|
*
|
||||||
@ -440,7 +444,6 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
|
|||||||
int minor_offset = 0;
|
int minor_offset = 0;
|
||||||
int minor_cnt = VIDEO_NUM_DEVICES;
|
int minor_cnt = VIDEO_NUM_DEVICES;
|
||||||
const char *name_base;
|
const char *name_base;
|
||||||
void *priv = vdev->dev.p;
|
|
||||||
|
|
||||||
/* A minor value of -1 marks this video device as never
|
/* A minor value of -1 marks this video device as never
|
||||||
having been registered */
|
having been registered */
|
||||||
@ -559,10 +562,6 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Part 4: register the device with sysfs */
|
/* Part 4: register the device with sysfs */
|
||||||
memset(&vdev->dev, 0, sizeof(vdev->dev));
|
|
||||||
/* The memset above cleared the device's device_private, so
|
|
||||||
put back the copy we made earlier. */
|
|
||||||
vdev->dev.p = priv;
|
|
||||||
vdev->dev.class = &video_class;
|
vdev->dev.class = &video_class;
|
||||||
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
|
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
|
||||||
if (vdev->parent)
|
if (vdev->parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user