V4L/DVB: gspca - JPEG subdrivers: Don't allocate the JPEG header
authorJean-François Moine <moinejf@free.fr>
Fri, 4 Jun 2010 08:26:42 +0000 (05:26 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 2 Aug 2010 17:06:08 +0000 (14:06 -0300)
The JPEG header is now included in the subdriver structure instead
of being allocated and freed at capture start and stop.

Signed-off-by: Jean-François Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/gspca/conex.c
drivers/media/video/gspca/jeilinj.c
drivers/media/video/gspca/mars.c
drivers/media/video/gspca/ov519.c
drivers/media/video/gspca/sn9c20x.c
drivers/media/video/gspca/spca500.c
drivers/media/video/gspca/stk014.c
drivers/media/video/gspca/sunplus.c
drivers/media/video/gspca/w996Xcf.c
drivers/media/video/gspca/zc3xx.c

index 19fe6b2..d6a7577 100644 (file)
@@ -41,7 +41,7 @@ struct sd {
 #define QUALITY_MAX 60
 #define QUALITY_DEF 40
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -845,9 +845,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        struct sd *sd = (struct sd *) gspca_dev;
 
        /* create the JPEG header */
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -862,11 +859,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
 /* called on streamoff with alt 0 and on disconnect */
 static void sd_stop0(struct gspca_dev *gspca_dev)
 {
-       struct sd *sd = (struct sd *) gspca_dev;
        int retry = 50;
 
-       kfree(sd->jpeg_hdr);
-
        if (!gspca_dev->present)
                return;
        reg_w_val(gspca_dev, 0x0000, 0x00);
index 84ecd56..12d9cf4 100644 (file)
@@ -50,7 +50,7 @@ struct sd {
        struct workqueue_struct *work_thread;
        u8 quality;                              /* image quality */
        u8 jpegqual;                            /* webcam quality */
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
        struct jlj_command {
@@ -282,7 +282,6 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
        destroy_workqueue(dev->work_thread);
        dev->work_thread = NULL;
        mutex_lock(&gspca_dev->usb_lock);
-       kfree(dev->jpeg_hdr);
 }
 
 /* this function is called at probe and resume time */
@@ -298,9 +297,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int ret;
 
        /* create the JPEG header */
-       dev->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (dev->jpeg_hdr == NULL)
-               return -ENOMEM;
        jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x21);          /* JPEG 422 */
        jpeg_set_qual(dev->jpeg_hdr, dev->quality);
index 3d9229e..031f719 100644 (file)
@@ -41,7 +41,7 @@ struct sd {
 #define QUALITY_MAX 70
 #define QUALITY_DEF 50
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -200,9 +200,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int i;
 
        /* create the JPEG header */
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x21);          /* JPEG 422 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -317,13 +314,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
                PDEBUG(D_ERR, "Camera Stop failed");
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       kfree(sd->jpeg_hdr);
-}
-
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
                        u8 *data,                       /* isoc packet */
                        int len)                        /* iso packet length */
@@ -486,7 +476,6 @@ static const struct sd_desc sd_desc = {
        .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
        .get_jcomp = sd_get_jcomp,
        .set_jcomp = sd_set_jcomp,
index 6eeeee2..2e7df66 100644 (file)
 #include <linux/input.h>
 #include "gspca.h"
 
+/* The jpeg_hdr is used by w996Xcf only */
+/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
+#define CONEX_CAM
+#include "jpeg.h"
+
 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("OV519 USB Camera Driver");
 MODULE_LICENSE("GPL");
@@ -116,7 +121,7 @@ struct sd {
        int sensor_height;
        int sensor_reg_cache[256];
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* Note this is a bit of a hack, but the w9968cf driver needs the code for all
index 644a7fd..3f7e446 100644 (file)
@@ -89,7 +89,7 @@ struct sd {
        u8 hstart;
        u8 vstart;
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
        u8 quality;
 
        u8 flags;
@@ -2162,10 +2162,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int height = gspca_dev->height;
        u8 fmt, scale = 0;
 
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (sd->jpeg_hdr == NULL)
-               return -ENOMEM;
-
        jpeg_define(sd->jpeg_hdr, height, width,
                        0x21);
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -2197,8 +2193,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
        }
 
        configure_sensor_output(gspca_dev, mode);
-       reg_w(gspca_dev, 0x1100, sd->jpeg_hdr + JPEG_QT0_OFFSET, 64);
-       reg_w(gspca_dev, 0x1140, sd->jpeg_hdr + JPEG_QT1_OFFSET, 64);
+       reg_w(gspca_dev, 0x1100, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
+       reg_w(gspca_dev, 0x1140, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
        reg_w(gspca_dev, 0x10fb, CLR_WIN(width, height), 5);
        reg_w(gspca_dev, 0x1180, HW_WIN(mode, sd->hstart, sd->vstart), 6);
        reg_w1(gspca_dev, 0x1189, scale);
@@ -2226,12 +2222,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] & ~0x02);
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-       kfree(sd->jpeg_hdr);
-}
-
 static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
 {
        struct sd *sd = (struct sd *) gspca_dev;
@@ -2397,7 +2387,6 @@ static const struct sd_desc sd_desc = {
        .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
 #ifdef CONFIG_INPUT
        .int_pkt_scan = sd_int_pkt_scan,
index b866c73..c02beb6 100644 (file)
@@ -57,7 +57,7 @@ struct sd {
 #define PalmPixDC85 13
 #define ToptroIndus 14
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -669,9 +669,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        __u8 xmult, ymult;
 
        /* create the JPEG header */
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -891,13 +888,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
                gspca_dev->usb_buf[0]);
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       kfree(sd->jpeg_hdr);
-}
-
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
                        u8 *data,                       /* isoc packet */
                        int len)                        /* iso packet length */
@@ -1055,7 +1045,6 @@ static const struct sd_desc sd_desc = {
        .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
        .get_jcomp = sd_get_jcomp,
        .set_jcomp = sd_set_jcomp,
index 0fb5342..45f4bc6 100644 (file)
@@ -40,7 +40,7 @@ struct sd {
 #define QUALITY_MAX 95
 #define QUALITY_DEF 80
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -337,9 +337,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int ret, value;
 
        /* create the JPEG header */
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -412,13 +409,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        PDEBUG(D_STREAM, "camera stopped");
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       kfree(sd->jpeg_hdr);
-}
-
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
                        u8 *data,                       /* isoc packet */
                        int len)                        /* iso packet length */
@@ -578,7 +568,6 @@ static const struct sd_desc sd_desc = {
        .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
        .querymenu = sd_querymenu,
        .get_jcomp = sd_get_jcomp,
index 0c786e0..21d82ba 100644 (file)
@@ -54,7 +54,7 @@ struct sd {
 #define MegapixV4 4
 #define MegaImageVI 5
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -842,9 +842,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        int enable;
 
        /* create the JPEG header */
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x22);          /* JPEG 411 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -954,13 +951,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        }
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       kfree(sd->jpeg_hdr);
-}
-
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
                        u8 *data,                       /* isoc packet */
                        int len)                        /* iso packet length */
@@ -1162,7 +1152,6 @@ static const struct sd_desc sd_desc = {
        .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
        .get_jcomp = sd_get_jcomp,
        .set_jcomp = sd_set_jcomp,
index 2fffe20..38a6859 100644 (file)
    the sensor drivers to v4l2 sub drivers, and properly split of this
    driver from ov519.c */
 
-/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
-#define CONEX_CAM
-#include "jpeg.h"
-
 #define W9968CF_I2C_BUS_DELAY    4 /* delay in us for I2C bit r/w operations */
 
-#define Y_QUANTABLE (sd->jpeg_hdr + JPEG_QT0_OFFSET)
-#define UV_QUANTABLE (sd->jpeg_hdr + JPEG_QT1_OFFSET)
+#define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET])
+#define UV_QUANTABLE (&sd->jpeg_hdr[JPEG_QT1_OFFSET])
 
 static const struct v4l2_pix_format w9968cf_vga_mode[] = {
        {160, 120, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE,
@@ -509,11 +505,6 @@ static int w9968cf_mode_init_regs(struct sd *sd)
        if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
            V4L2_PIX_FMT_JPEG) {
                /* We may get called multiple times (usb isoc bw negotiat.) */
-               if (!sd->jpeg_hdr)
-                       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-               if (!sd->jpeg_hdr)
-                       return -ENOMEM;
-
                jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height,
                            sd->gspca_dev.width, 0x22); /* JPEG 420 */
                jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -562,9 +553,6 @@ static void w9968cf_stop0(struct sd *sd)
                reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */
                reg_w(sd, 0x16, 0x0000); /* stop video capture */
        }
-
-       kfree(sd->jpeg_hdr);
-       sd->jpeg_hdr = NULL;
 }
 
 /* The w9968cf docs say that a 0 sized packet means EOF (and also SOF
index d02aa5c..0a04371 100644 (file)
@@ -75,7 +75,7 @@ struct sd {
 #define SENSOR_MAX 19
        unsigned short chip_revision;
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -6798,9 +6798,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        };
 
        /* create the JPEG header */
-       sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x21);          /* JPEG 422 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -6931,7 +6928,6 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
-       kfree(sd->jpeg_hdr);
        if (!gspca_dev->present)
                return;
        send_unknown(gspca_dev->dev, sd->sensor);