media: vivid: fix smatch warnings
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Fri, 23 Nov 2018 12:07:33 +0000 (07:07 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 3 Dec 2018 19:30:27 +0000 (14:30 -0500)
Reorganize code to fix two smatch warnings:

drivers/media/platform/vivid/vivid-core.c: drivers/media/platform/vivid/vivid-core.c:889 vivid_create_instance() warn: potentially one past the end of array
'dev->query_dv_timings_qmenu[dev->query_dv_timings_size]'
drivers/media/platform/vivid/vivid-core.c: drivers/media/platform/vivid/vivid-core.c:889 vivid_create_instance() warn: potentially one past the end of array
'dev->query_dv_timings_qmenu[dev->query_dv_timings_size]'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/vivid/vivid-core.c
drivers/media/platform/vivid/vivid-core.h

index c1b5976af3e6ee57a1c944ad97b8e60b1f8fdbb2..a6fa9edd4c7ea2aca090034b08b809c13af5b2d2 100644 (file)
@@ -625,6 +625,7 @@ static void vivid_dev_release(struct v4l2_device *v4l2_dev)
        vfree(dev->bitmap_out);
        tpg_free(&dev->tpg);
        kfree(dev->query_dv_timings_qmenu);
+       kfree(dev->query_dv_timings_qmenu_strings);
        kfree(dev);
 }
 
@@ -876,20 +877,31 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
        if (!dev->edid)
                goto free_dev;
 
-       /* create a string array containing the names of all the preset timings */
        while (v4l2_dv_timings_presets[dev->query_dv_timings_size].bt.width)
                dev->query_dv_timings_size++;
+
+       /*
+        * Create a char pointer array that points to the names of all the
+        * preset timings
+        */
        dev->query_dv_timings_qmenu = kmalloc_array(dev->query_dv_timings_size,
-                                                   (sizeof(void *) + 32),
-                                                   GFP_KERNEL);
-       if (dev->query_dv_timings_qmenu == NULL)
+                                                   sizeof(char *), GFP_KERNEL);
+       /*
+        * Create a string array containing the names of all the preset
+        * timings. Each name is max 31 chars long (+ terminating 0).
+        */
+       dev->query_dv_timings_qmenu_strings =
+               kmalloc_array(dev->query_dv_timings_size, 32, GFP_KERNEL);
+
+       if (!dev->query_dv_timings_qmenu ||
+           !dev->query_dv_timings_qmenu_strings)
                goto free_dev;
+
        for (i = 0; i < dev->query_dv_timings_size; i++) {
                const struct v4l2_bt_timings *bt = &v4l2_dv_timings_presets[i].bt;
-               char *p = (char *)&dev->query_dv_timings_qmenu[dev->query_dv_timings_size];
+               char *p = dev->query_dv_timings_qmenu_strings + i * 32;
                u32 htot, vtot;
 
-               p += i * 32;
                dev->query_dv_timings_qmenu[i] = p;
 
                htot = V4L2_DV_BT_FRAME_WIDTH(bt);
index 1891254c8f0b22dee4565a579ad32a4da62c00d7..0bec2c3401d29165cd7dc83ca43e9b183b9e54eb 100644 (file)
@@ -305,6 +305,7 @@ struct vivid_dev {
 
        enum vivid_signal_mode          dv_timings_signal_mode;
        char                            **query_dv_timings_qmenu;
+       char                            *query_dv_timings_qmenu_strings;
        unsigned                        query_dv_timings_size;
        unsigned                        query_dv_timings_last;
        unsigned                        query_dv_timings;