]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
media: v4l2-dev: fix error handling in __video_register_device()
authorMa Ke <make24@iscas.ac.cn>
Wed, 19 Mar 2025 08:02:48 +0000 (16:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:07:27 +0000 (11:07 +0100)
commitb6be1f5633eae200af2527e9eeb7f51be5739b0f
tree24d3f7fdac13a14038b1e0641226158f52b77ab2
parentb003a9aab9376dbf129d5ac7077943a589948564
media: v4l2-dev: fix error handling in __video_register_device()

commit 2a934fdb01db6458288fc9386d3d8ceba6dd551a upstream.

Once device_register() failed, we should call put_device() to
decrement reference count for cleanup. Or it could cause memory leak.
And move callback function v4l2_device_release() and v4l2_device_get()
before put_device().

As comment of device_register() says, 'NOTE: _Never_ directly free
@dev after calling this function, even if it returned an error! Always
use put_device() to give up the reference initialized in this function
instead.'

Found by code review.

Cc: stable@vger.kernel.org
Fixes: dc93a70cc7f9 ("V4L/DVB (9973): v4l2-dev: use the release callback from device instead of cdev")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/v4l2-core/v4l2-dev.c