e9397727e9fe9fe936257aade08653e2b7bb7b59
[openwrt/staging/wigyori.git] /
1 From bc55eb17b46668e70dfbd1a091159935d8f95eb9 Mon Sep 17 00:00:00 2001
2 From: Joerg Schambacher <joerg@i2audio.com>
3 Date: Fri, 16 Oct 2020 15:17:07 +0200
4 Subject: [PATCH] Fixes a problem when module probes before i2c
5 module is available
6
7 The driver crashed while a NULL pointer returned by i2c_get_adapter()
8 has been used to access the i2c bus functions.
9 The headphone probing function hb_hp_probe() now returns -EPROBE_DEFER
10 in case the i2c module has not been loaded yet.
11
12 Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
13 ---
14 sound/soc/bcm/hifiberry_dacplus.c | 9 +++++++--
15 1 file changed, 7 insertions(+), 2 deletions(-)
16
17 --- a/sound/soc/bcm/hifiberry_dacplus.c
18 +++ b/sound/soc/bcm/hifiberry_dacplus.c
19 @@ -315,12 +315,14 @@ static int hb_hp_detect(void)
20 {
21 struct i2c_adapter *adap = i2c_get_adapter(1);
22 int ret;
23 -
24 struct i2c_client tpa_i2c_client = {
25 .addr = 0x60,
26 .adapter = adap,
27 };
28
29 + if (!adap)
30 + return -EPROBE_DEFER; /* I2C module not yet available */
31 +
32 ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
33 i2c_put_adapter(adap);
34 return ret;
35 @@ -342,7 +344,10 @@ static int snd_rpi_hifiberry_dacplus_pro
36 struct of_changeset ocs;
37
38 /* probe for head phone amp */
39 - if (hb_hp_detect()) {
40 + ret = hb_hp_detect();
41 + if (ret < 0)
42 + return ret;
43 + if (ret) {
44 card->aux_dev = hifiberry_dacplus_aux_devs;
45 card->num_aux_devs =
46 ARRAY_SIZE(hifiberry_dacplus_aux_devs);