aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/em28xx/em28xx-i2c.c
diff options
context:
space:
mode:
authorDouglas Schilling Landgraf <dougsland@linuxtv.org>2008-09-08 02:27:20 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-10-12 07:37:00 -0400
commitf2a01a0027b29f682c3833d582e2827a4690f661 (patch)
treeb16a459c19b4861b991e039b4d859d60e5110f6c /drivers/media/video/em28xx/em28xx-i2c.c
parenta50f4a444a14a116e2eb077e01c2eaf58ddb7c6a (diff)
V4L/DVB (8937): em28xx: Fix and add some validations
Fixed and Added some validations Signed-off-by: Douglas Schilling Landgraf <dougsland@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/em28xx/em28xx-i2c.c')
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 2989a65f6917..3bab56b997fc 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -336,8 +336,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
336 336
337 /* Check if board has eeprom */ 337 /* Check if board has eeprom */
338 err = i2c_master_recv(&dev->i2c_client, &buf, 0); 338 err = i2c_master_recv(&dev->i2c_client, &buf, 0);
339 if (err < 0) 339 if (err < 0) {
340 return -1; 340 em28xx_errdev("%s: i2c_master_recv failed! err [%d]\n",
341 __func__, err);
342 return err;
343 }
341 344
342 buf = 0; 345 buf = 0;
343 346
@@ -345,7 +348,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
345 if (err != 1) { 348 if (err != 1) {
346 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", 349 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
347 dev->name, err); 350 dev->name, err);
348 return -1; 351 return err;
349 } 352 }
350 while (size > 0) { 353 while (size > 0) {
351 if (size > 16) 354 if (size > 16)
@@ -358,7 +361,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
358 printk(KERN_WARNING 361 printk(KERN_WARNING
359 "%s: i2c eeprom read error (err=%d)\n", 362 "%s: i2c eeprom read error (err=%d)\n",
360 dev->name, err); 363 dev->name, err);
361 return -1; 364 return err;
362 } 365 }
363 size -= block; 366 size -= block;
364 p += block; 367 p += block;
@@ -586,18 +589,31 @@ void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
586 */ 589 */
587int em28xx_i2c_register(struct em28xx *dev) 590int em28xx_i2c_register(struct em28xx *dev)
588{ 591{
592 int retval;
593
589 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg); 594 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
590 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req); 595 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
591 dev->i2c_adap = em28xx_adap_template; 596 dev->i2c_adap = em28xx_adap_template;
592 dev->i2c_adap.dev.parent = &dev->udev->dev; 597 dev->i2c_adap.dev.parent = &dev->udev->dev;
593 strcpy(dev->i2c_adap.name, dev->name); 598 strcpy(dev->i2c_adap.name, dev->name);
594 dev->i2c_adap.algo_data = dev; 599 dev->i2c_adap.algo_data = dev;
595 i2c_add_adapter(&dev->i2c_adap); 600
601 retval = i2c_add_adapter(&dev->i2c_adap);
602 if (retval < 0) {
603 em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
604 __func__, retval);
605 return retval;
606 }
596 607
597 dev->i2c_client = em28xx_client_template; 608 dev->i2c_client = em28xx_client_template;
598 dev->i2c_client.adapter = &dev->i2c_adap; 609 dev->i2c_client.adapter = &dev->i2c_adap;
599 610
600 em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); 611 retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
612 if (retval < 0) {
613 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
614 __func__, retval);
615 return retval;
616 }
601 617
602 if (i2c_scan) 618 if (i2c_scan)
603 em28xx_do_i2c_scan(dev); 619 em28xx_do_i2c_scan(dev);