V4L/DVB (8937): em28xx: Fix and add some validations
authorDouglas Schilling Landgraf <dougsland@linuxtv.org>
Mon, 8 Sep 2008 06:27:20 +0000 (03:27 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 12 Oct 2008 11:37:00 +0000 (09:37 -0200)
Fixed and Added some validations

Signed-off-by: Douglas Schilling Landgraf <dougsland@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/em28xx/em28xx-i2c.c
drivers/media/video/em28xx/em28xx-video.c

index 2989a65..3bab56b 100644 (file)
@@ -336,8 +336,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
 
        /* Check if board has eeprom */
        err = i2c_master_recv(&dev->i2c_client, &buf, 0);
-       if (err < 0)
-               return -1;
+       if (err < 0) {
+               em28xx_errdev("%s: i2c_master_recv failed! err [%d]\n",
+                       __func__, err);
+               return err;
+       }
 
        buf = 0;
 
@@ -345,7 +348,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
        if (err != 1) {
                printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
                       dev->name, err);
-               return -1;
+               return err;
        }
        while (size > 0) {
                if (size > 16)
@@ -358,7 +361,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
                        printk(KERN_WARNING
                               "%s: i2c eeprom read error (err=%d)\n",
                               dev->name, err);
-                       return -1;
+                       return err;
                }
                size -= block;
                p += block;
@@ -586,18 +589,31 @@ void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
  */
 int em28xx_i2c_register(struct em28xx *dev)
 {
+       int retval;
+
        BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
        BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
        dev->i2c_adap = em28xx_adap_template;
        dev->i2c_adap.dev.parent = &dev->udev->dev;
        strcpy(dev->i2c_adap.name, dev->name);
        dev->i2c_adap.algo_data = dev;
-       i2c_add_adapter(&dev->i2c_adap);
+
+       retval = i2c_add_adapter(&dev->i2c_adap);
+       if (retval < 0) {
+               em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
+                       __func__, retval);
+               return retval;
+       }
 
        dev->i2c_client = em28xx_client_template;
        dev->i2c_client.adapter = &dev->i2c_adap;
 
-       em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
+       retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
+       if (retval < 0) {
+               em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
+                       __func__, retval);
+               return retval;
+       }
 
        if (i2c_scan)
                em28xx_do_i2c_scan(dev);
index 600b340..50d2c7a 100644 (file)
@@ -513,10 +513,17 @@ static struct videobuf_queue_ops em28xx_video_qops = {
  */
 static int em28xx_config(struct em28xx *dev)
 {
+       int retval;
 
        /* Sets I2C speed to 100 KHz */
-       if (!dev->is_em2800)
-               em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
+       if (!dev->is_em2800) {
+               retval = em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
+               if (retval < 0) {
+                       em28xx_errdev("%s: em28xx_write_regs_req failed! retval [%d]\n",
+                               __func__, retval);
+                       return retval;
+               }
+       }
 
        /* enable vbi capturing */
 
@@ -1953,13 +1960,23 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        }
 
        /* register i2c bus */
-       em28xx_i2c_register(dev);
+       errCode = em28xx_i2c_register(dev);
+       if (errCode < 0) {
+               em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
+                       __func__, errCode);
+               return errCode;
+       }
 
        /* Do board specific init and eeprom reading */
        em28xx_card_setup(dev);
 
        /* Configure audio */
-       em28xx_audio_analog_set(dev);
+       errCode = em28xx_audio_analog_set(dev);
+       if (errCode < 0) {
+               em28xx_errdev("%s: em28xx_audio_analog_set - errCode [%d]!\n",
+                       __func__, errCode);
+               return errCode;
+       }
 
        /* configure the device */
        em28xx_config_i2c(dev);
@@ -1979,6 +1996,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        dev->ctl_input = 2;
 
        errCode = em28xx_config(dev);
+       if (errCode < 0) {
+               em28xx_errdev("%s: em28xx_config - errCode [%d]!\n",
+                       __func__, errCode);
+               return errCode;
+       }
 
        list_add_tail(&dev->devlist, &em28xx_devlist);
 
@@ -2031,9 +2053,20 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
 
        if (dev->has_msp34xx) {
                /* Send a reset to other chips via gpio */
-               em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
+               errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
+               if (errCode < 0) {
+                       em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(1) failed! errCode [%d]\n",
+                               __func__, errCode);
+                       return errCode;
+               }
                msleep(3);
-               em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
+
+               errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
+               if (errCode < 0) {
+                       em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(2) failed! errCode [%d]\n",
+                               __func__, errCode);
+                       return errCode;
+               }
                msleep(3);
        }