Re: [PATCH] media: v4l: get_device() when no errors are possible anymore

From: Hans Verkuil
Date: Fri Apr 25 2025 - 07:23:07 EST


Hi Michał,

On 28/03/2025 23:07, Michał Mirosław wrote:
> Avoid leaking reference from get_device() in the error path.

It's not actually leaking anything. If dev == NULL, then get_device
does nothing.

I'll reject this patch.

Regards,

Hans

>
> Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
> ---
> drivers/media/v4l2-core/v4l2-device.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> index 5e537454f5cd..277ea2c241b8 100644
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
> @@ -23,7 +23,6 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
> spin_lock_init(&v4l2_dev->lock);
> v4l2_prio_init(&v4l2_dev->prio);
> kref_init(&v4l2_dev->ref);
> - get_device(dev);
> v4l2_dev->dev = dev;
> if (dev == NULL) {
> /* If dev == NULL, then name must be filled in by the caller */
> @@ -32,6 +31,8 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
> return 0;
> }
>
> + get_device(dev);
> +
> /* Set name to driver name + device name if it is empty. */
> if (!v4l2_dev->name[0])
> snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",