[GIT PATCHES FOR 2.6.38] Fix memory leak in __video_register_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The __video_register_device function memset()s the embedded struct device.

It is common practice for drivers to call video_set_drvdata() before the
video device node is registered. But video_set_drvdata() calls dev_set_drvdata()
in turn, and dev_set_drvdata allocates memory to store the void pointer.

The __video_register_device function makes a copy of the driver data by
calling video_get_drvdata and before memsetting the struct device to 0.
It restores it afterwards.

Unfortunately, due to the memset the memory allocated in struct device is
never freed.

This patch series fixes this situation by no longer doing the memset. This
requires that all drivers always memset the struct video_device before use.

I analyzed *all* v4l drivers and found two that do not do this properly. The
zoran driver uses kmalloc to allocate video_device (although it copies a
video_device template later, so it is actually safe. But it really should
call video_device_alloc). The w9966 driver would likely fail since after the
device is disconnected the old struct may be reused after a reconnect.

But since nobody has this parallel port webcam anymore it is unlikely anyone
would ever notice.

Note that this still does not fix the case if video_register_device bails out
before device_register is called: the memory is still leaked in that case.

But let's tackle the majority of the leaks first.

Regards,

	Hans

The following changes since commit 187134a5875df20356f4dca075db29f294115a47:
  David Henningsson (1):
        [media] DVB: IR support for TechnoTrend CT-3650

are available in the git repository at:

  ssh://linuxtv.org/git/hverkuil/media_tree.git vdev-fix

Hans Verkuil (3):
      w9966: zero device state after a detach
      zoran: use video_device_alloc instead of kmalloc.
      v4l2-dev: don't memset video_device.dev.

 drivers/media/video/v4l2-dev.c         |    9 ++++-----
 drivers/media/video/w9966.c            |    1 +
 drivers/media/video/zoran/zoran_card.c |    2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

-- 
Hans Verkuil - video4linux developer - sponsored by Cisco
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux