[media] vpif_capture.c: v4l2_device_register() is called too late in vpif_probe()
authorHans Verkuil <hverkuil@xs4all.nl>
Tue, 13 Dec 2011 08:44:42 +0000 (05:44 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Fri, 6 Jan 2012 13:48:22 +0000 (11:48 -0200)
The function v4l2_device_register() is called too late in vpif_probe().
This meant that vpif_obj.v4l2_dev is accessed before it is initialized
which caused a crash.

This used to work in the past, but video_register_device() is now actually
using the v4l2_dev pointer.

Note that vpif_display.c doesn't have this bug, there v4l2_device_register()
is called at the beginning of vpif_probe.

Signed-off-by: Georgios Plakaris <gplakari@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Manjunath Hadli <Manjunath.hadli@ti.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/davinci/vpif_capture.c

index 49e4deb500430faf3be60475b5062cf7e5141921..6504e40a31dd2fb27277253ae7166ff3da64decb 100644 (file)
@@ -2177,6 +2177,12 @@ static __init int vpif_probe(struct platform_device *pdev)
                return err;
        }
 
+       err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
+       if (err) {
+               v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
+               return err;
+       }
+
        k = 0;
        while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, k))) {
                for (i = res->start; i <= res->end; i++) {
@@ -2246,12 +2252,6 @@ static __init int vpif_probe(struct platform_device *pdev)
                goto probe_out;
        }
 
-       err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
-       if (err) {
-               v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
-               goto probe_subdev_out;
-       }
-
        for (i = 0; i < subdev_count; i++) {
                subdevdata = &config->subdev_info[i];
                vpif_obj.sd[i] =
@@ -2281,7 +2281,6 @@ probe_subdev_out:
 
        j = VPIF_CAPTURE_MAX_DEVICES;
 probe_out:
-       v4l2_device_unregister(&vpif_obj.v4l2_dev);
        for (k = 0; k < j; k++) {
                /* Get the pointer to the channel object */
                ch = vpif_obj.dev[k];
@@ -2303,6 +2302,7 @@ vpif_int_err:
                if (res)
                        i = res->end;
        }
+       v4l2_device_unregister(&vpif_obj.v4l2_dev);
        return err;
 }