]> git.baikalelectronics.ru Git - kernel.git/commit
V4L/DVB: v4l2-dev: fix memory leak
authorAnatolij Gustschin <agust@denx.de>
Thu, 1 Jul 2010 17:21:39 +0000 (14:21 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 2 Aug 2010 18:36:02 +0000 (15:36 -0300)
commit5e628ee40105edec76131d9bec4180c252b97e1d
tree56d9feec496430d29a450480d3908ea380daed92
parent7ec835c0ec5d87920c869f7afdb6203b9bb93910
V4L/DVB: v4l2-dev: fix memory leak

Since commit 4034f2284c4ef9fc3d7e1b91f7a5fa94ccb61f3f
the 'driver_data' field resides in device's struct device_private
which may be allocated by dev_set_drvdata() if device_private
struct was not allocated previously.

dev_set_drvdata() is used in video_set_drvdata() to set
the driver's private data pointer in v4l2 drivers. Setting
the private data _before_ registering the v4l2 device results
in a memory leak since __video_register_device() also calls
video_set_drvdata(), but after zeroing the device structure.
Thus, the reference to the previously allocated device_private
struct goes lost and a new device_private will be allocated.

All v4l drivers which call video_set_drvdata() _before_
calling video_register_device() are affected. The patch fixes
__video_register_device() to preserve previously allocated
device_private reference.

Caught by kmemleak.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/v4l2-dev.c