diff mbox series

media: v4l: get_device() when no errors are possible anymore

Message ID 13860e023a920cd472cf5acecee88794c815b9c4.1743199603.git.mirq-linux@rere.qmqm.pl
State New
Headers show
Series media: v4l: get_device() when no errors are possible anymore | expand

Commit Message

Michał Mirosław March 28, 2025, 10:07 p.m. UTC
Avoid leaking reference from get_device() in the error path.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/media/v4l2-core/v4l2-device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Hans Verkuil April 25, 2025, 11:18 a.m. UTC | #1
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@rere.qmqm.pl>
> ---
>  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",
diff mbox series

Patch

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",