Re: [PATCH v3] media: v4l2-dev: fix error handling in __video_register_device()
From: Sakari Ailus
Date: Thu Mar 27 2025 - 06:50:36 EST
On Wed, Mar 19, 2025 at 04:02:48PM +0800, Ma Ke wrote:
> 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@xxxxxxxxxxxxxxx
> Fixes: dc93a70cc7f9 ("V4L/DVB (9973): v4l2-dev: use the release callback from device instead of cdev")
> Signed-off-by: Ma Ke <make24@xxxxxxxxxxx>
Reviewed-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
--
Sakari Ailus