OSDN Git Service

greybus: gb-audio: Ensure i2c adapter struct exists before using
authorMark Greer <mgreer@animalcreek.com>
Fri, 26 Jun 2015 23:38:46 +0000 (16:38 -0700)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 30 Jun 2015 01:04:38 +0000 (18:04 -0700)
The current audio code uses i2c_get_adapter() without checking
that a non-NULL pointer is returned (i.e., that the i2c device
actually exists).  When that happens, the system panics.
Fix the potential panic by erroring out with -ENODEV when
i2c_get_adapter() returns NULL.

CC: John Stultz <john.stultz@linaro.com>
Signed-off-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/audio.c

index a077c2b..9f5f959 100644 (file)
@@ -167,6 +167,7 @@ static int gb_i2s_transmitter_connection_init(struct gb_connection *connection)
        struct asoc_simple_card_info *simple_card;
 #if USE_RT5645
        struct i2c_board_info rt5647_info;
+       struct i2c_adapter *i2c_adap;
 #endif
        unsigned long flags;
        int ret;
@@ -234,8 +235,14 @@ static int gb_i2s_transmitter_connection_init(struct gb_connection *connection)
        rt5647_info.addr = RT5647_I2C_ADDR;
        strlcpy(rt5647_info.type, "rt5647", I2C_NAME_SIZE);
 
-       snd_dev->rt5647 = i2c_new_device(i2c_get_adapter(RT5647_I2C_ADAPTER_NR),
-                                        &rt5647_info);
+       i2c_adap = i2c_get_adapter(RT5647_I2C_ADAPTER_NR);
+       if (!i2c_adap) {
+               pr_err("codec unavailable\n");
+               ret = -ENODEV;
+               goto out_get_ver;
+       }
+
+       snd_dev->rt5647 = i2c_new_device(i2c_adap, &rt5647_info);
        if (!snd_dev->rt5647) {
                pr_err("can't create rt5647 i2c device\n");
                goto out_get_ver;