From: Mark Greer Date: Fri, 26 Jun 2015 23:38:46 +0000 (-0700) Subject: greybus: gb-audio: Ensure i2c adapter struct exists before using X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1443 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=f4706b848ec6c58f797604112d30272db8d5e8dd;p=karo-tx-linux.git 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 Signed-off-by: Mark Greer Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/audio.c b/drivers/staging/greybus/audio.c index a077c2bbaad6..9f5f95913e8f 100644 --- a/drivers/staging/greybus/audio.c +++ b/drivers/staging/greybus/audio.c @@ -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;