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 19fe6b24c9a34062b8d85c8f56216d323df86ad2..d6a75772f3f80e19c94d7a4cccd2661a14d01347 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 84ecd56c64709d722988008dba531e929ead1027..12d9cf4caba22ddfdc719d59aa146a7683d5a1fa 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 3d9229e22b25cf2598f6f326750d66f9309e9695..031f7195ce0dca39f72b60193b83bc7fbafe7cb1 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 6eeeee25523c5d53322257adfd9537bad561e9f6..2e7df66a84b95acbbc489164ca7304641b6e158f 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 644a7fd4701ae9961669a74311bbdb8f264bbf8f..3f7e446d688a7d930011026c10993a3adfaf4bad 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 b866c73c97db17d738cf1a6be61f71dbab06e3d3..c02beb6c1e9345e504b9830840e2a0aa37fee873 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 0fb534210a2c7f4bfe25ba3ca3737df7314feae1..45f4bc6ffc4aaac4b4426d899c6ae07a3985c506 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 0c786e00ebcf39e758bb60f29f73f82f826fadc4..21d82bab0c2ed34e6fedc972cf1d53724180523e 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 2fffe203bed876fdcaf4713ffe32edabd4b5d39f..38a68591ce48be033244590ce5a5bf9859bf5e7b 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 d02aa5c8472ad81d5b92b6fb0d510f0a64ba1d9b..0a043719f765feb786ce788a0e086271f170a1c1 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);