greybus: gb-audio: Ensure i2c adapter struct exists before using

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>
This commit is contained in:
Mark Greer 2015-06-26 16:38:46 -07:00 committed by Greg Kroah-Hartman
parent 86f918ee7f
commit f4706b848e

View 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;