Hi Ma, Thanks for the patch. On Thu, Mar 13, 2025 at 03:43:18PM +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. > > 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: baa057e29b58 ("media: v4l2-dev: use pr_foo() for printing messages") > Signed-off-by: Ma Ke <make24@xxxxxxxxxxx> > --- > drivers/media/v4l2-core/v4l2-dev.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c > index 5bcaeeba4d09..1619614e96bf 100644 > --- a/drivers/media/v4l2-core/v4l2-dev.c > +++ b/drivers/media/v4l2-core/v4l2-dev.c > @@ -1060,6 +1060,7 @@ int __video_register_device(struct video_device *vdev, > if (ret < 0) { > mutex_unlock(&videodev_lock); > pr_err("%s: device_register failed\n", __func__); > + put_device(&vdev->dev); Fixing this isn't quite as simple. The release callback is actually set below so there's no release callback set for this device yet. > goto cleanup; > } > /* Register the release callback that will be called when the last -- Kind regards, Sakari Ailus