Skip to contentSkip to conversation

au0828_v4l2_device_register()

PATCH Shuah Khan 2 participants 2 messages Mar 28, 2016 Media (V4L/DVB)

lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

Hi Mauro/Javier,

I can't figure out when au0828_v4l2_device_register() was added. Must be in Linux 4.5 as I can't find this change in Linux 4.4 This used to be a call to v4l2_device_register() from au0828_usb_probe(). When the code was moved, locking bugs are introduced.

Notice that au0828_v4l2_device_register() does the following in error legs:

                mutex_unlock(&dev->lock);
                kfree(dev);

And au0828_usb_probe() also does the same cleanup when au0828_v4l2_device_register() returns error:

        retval = au0828_v4l2_device_register(interface, dev);
        if (retval) {
                au0828_usb_v4l2_media_release(dev);
                mutex_unlock(&dev->lock);
                kfree(dev);
                return retval;
        }

We could be seeing some problems if this fails.

Please let me know if you would like a patch to fix this.

The following is the right fix:

drivers/media/usb/au0828/au0828-video.c +0 -4
index 32d7db9..7d0ec4c 100644
@@ -679,8 +679,6 @@ int au0828_v4l2_device_register(struct usb_interface *interface,
        if (retval) {
                pr_err("%s() v4l2_device_register failed\n",
                       __func__);
-               mutex_unlock(&dev->lock);
-               kfree(dev);
                return retval;
        }
 
@@ -691,8 +689,6 @@ int au0828_v4l2_device_register(struct usb_interface *interface,
        if (retval) {
                pr_err("%s() v4l2_ctrl_handler_init failed\n",
                       __func__);
-               mutex_unlock(&dev->lock);
-               kfree(dev);
                return retval;
        }
        dev->v4l2_dev.ctrl_handler = &dev->v4l2_ctrl_hdl;

thanks,
-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected]
#1 lore raw

Hi Shuah,

Em Mon, 28 Mar 2016 11:08:09 -0600
Shuah Khan <[email protected]> escreveu:

Quoted 6 lines

Hi Mauro/Javier,

I can't figure out when au0828_v4l2_device_register() was added. Must be in Linux 4.5 as I can't find this change in Linux 4.4 This used to be a call to v4l2_device_register() from au0828_usb_probe(). When the code was moved, locking bugs are introduced.

I guess this was introduced before 4.5

Quoted 18 lines

Notice that au0828_v4l2_device_register() does the following in error legs:

                mutex_unlock(&dev->lock);
                kfree(dev);

And au0828_usb_probe() also does the same cleanup when au0828_v4l2_device_register() returns error:

        retval = au0828_v4l2_device_register(interface, dev);
        if (retval) {
                au0828_usb_v4l2_media_release(dev);
                mutex_unlock(&dev->lock);
                kfree(dev);
                return retval;
        }
Quoted 3 lines

We could be seeing some problems if this fails.

Please let me know if you would like a patch to fix this.

Yes, sure!

Regards,
Mauro

Quoted 30 lines

The following is the right fix:

drivers/media/usb/au0828/au0828-video.c +0 -4
index 32d7db9..7d0ec4c 100644
@@ -679,8 +679,6 @@ int au0828_v4l2_device_register(struct usb_interface *interface,
        if (retval) {
                pr_err("%s() v4l2_device_register failed\n",
                       __func__);
-               mutex_unlock(&dev->lock);
-               kfree(dev);
                return retval;
        }
 
@@ -691,8 +689,6 @@ int au0828_v4l2_device_register(struct usb_interface *interface,
        if (retval) {
                pr_err("%s() v4l2_ctrl_handler_init failed\n",
                       __func__);
-               mutex_unlock(&dev->lock);
-               kfree(dev);
                return retval;
        }
        dev->v4l2_dev.ctrl_handler = &dev->v4l2_ctrl_hdl;

thanks,
-- Shuah

Signature · 2 lines
Thanks,
Mauro