[media] ds3000: bail out early on i2c failures during firmware load
authorRémi Cardona <remi.cardona@smartjog.com>
Fri, 28 Sep 2012 11:59:29 +0000 (08:59 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Thu, 27 Dec 2012 21:43:46 +0000 (19:43 -0200)
- if kmalloc() returns NULL, we can return immediately without trying
   to kfree() a NULL pointer.
 - if i2c_transfer() fails, error out immediately instead of trying to
   upload the remaining bytes of the firmware.
 - the error code is then properly propagated down to ds3000_initfe().

Signed-off-by: Rémi Cardona <remi.cardona@smartjog.com>
Reviewed-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/dvb-frontends/ds3000.c

index bc17e29b54d14de1982d7c5f9bf4fe586bb83c17..fded9b67456c83a2677df612b49d2e60c00134e4 100644 (file)
@@ -272,15 +272,14 @@ static int ds3000_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
 static int ds3000_writeFW(struct ds3000_state *state, int reg,
                                const u8 *data, u16 len)
 {
-       int i, ret = -EREMOTEIO;
+       int i, ret = 0;
        struct i2c_msg msg;
        u8 *buf;
 
        buf = kmalloc(33, GFP_KERNEL);
        if (buf == NULL) {
                printk(KERN_ERR "Unable to kmalloc\n");
-               ret = -ENOMEM;
-               goto error;
+               return -ENOMEM;
        }
 
        *(buf) = reg;
@@ -300,8 +299,10 @@ static int ds3000_writeFW(struct ds3000_state *state, int reg,
                        printk(KERN_ERR "%s: write error(err == %i, "
                                "reg == 0x%02x\n", __func__, ret, reg);
                        ret = -EREMOTEIO;
+                       goto error;
                }
        }
+       ret = 0;
 
 error:
        kfree(buf);
@@ -384,6 +385,7 @@ static int ds3000_load_firmware(struct dvb_frontend *fe,
                                        const struct firmware *fw)
 {
        struct ds3000_state *state = fe->demodulator_priv;
+       int ret = 0;
 
        dprintk("%s\n", __func__);
        dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n",
@@ -396,10 +398,10 @@ static int ds3000_load_firmware(struct dvb_frontend *fe,
        /* Begin the firmware load process */
        ds3000_writereg(state, 0xb2, 0x01);
        /* write the entire firmware */
-       ds3000_writeFW(state, 0xb0, fw->data, fw->size);
+       ret = ds3000_writeFW(state, 0xb0, fw->data, fw->size);
        ds3000_writereg(state, 0xb2, 0x00);
 
-       return 0;
+       return ret;
 }
 
 static int ds3000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
This page took 0.026323 seconds and 5 git commands to generate.