[media] mb86a20s: don't use state before initializing it
authorMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 23 Jan 2013 15:22:22 +0000 (13:22 -0200)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 23 Jan 2013 15:22:22 +0000 (13:22 -0200)
As reported by Feng's kbuild test:
From: kbuild test robot <fengguang.wu@intel.com>
Subject: drivers/media/dvb-frontends/mb86a20s.c:706 mb86a20s_attach() error: potential null dereference 'state'.  (kzalloc returns null)
Date: Wed, 23 Jan 2013 19:30:43 +0800

commit: f66d81b54dac26d4e601d4d7faca53f3bdc98427 [media] mb86a20s: convert it to use dev_info/dev_err/dev_dbg

drivers/media/dvb-frontends/mb86a20s.c:706 mb86a20s_attach() error: potential null dereference 'state'.  (kzalloc returns null)
drivers/media/dvb-frontends/mb86a20s.c:706 mb86a20s_attach() error: we previously assumed 'state' could be null (see line 705)

As, at mb86a20s_attach(), we have an i2c pointer, use it for all printk
messages there, instead of state->i2c.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/dvb-frontends/mb86a20s.c

index c52ae2ea0bf9e6ae3ebd89a1aec67006e1dc91eb..4b3ffc418294acb8270b8edbc1d385e06eda06b5 100644 (file)
@@ -698,12 +698,12 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
        struct mb86a20s_state *state;
        u8      rev;
 
+       dev_dbg(&i2c->dev, "%s called.\n", __func__);
+
        /* allocate memory for the internal state */
        state = kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
-
-       dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
        if (state == NULL) {
-               dev_err(&state->i2c->dev,
+               dev_err(&i2c->dev,
                        "%s: unable to allocate memory for state\n", __func__);
                goto error;
        }
@@ -721,10 +721,10 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
        rev = mb86a20s_readreg(state, 0);
 
        if (rev == 0x13) {
-               dev_info(&state->i2c->dev,
+               dev_info(&i2c->dev,
                         "Detected a Fujitsu mb86a20s frontend\n");
        } else {
-               dev_dbg(&state->i2c->dev,
+               dev_dbg(&i2c->dev,
                        "Frontend revision %d is unknown - aborting.\n",
                       rev);
                goto error;