Skip to content

Commit

Permalink
Fixes a problem when module probes before i2c module is available
Browse files Browse the repository at this point in the history
The driver crashed while a NULL pointer returned by i2c_get_adapter()
has been used to access the i2c bus functions.
The headphone probing function hb_hp_probe() now returns -EPROBE_DEFER
in case the i2c module has not been loaded yet.

Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
  • Loading branch information
Joerg Schambacher authored and pelwell committed Oct 16, 2020
1 parent a30b062 commit 7c449ff
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sound/soc/bcm/hifiberry_dacplus.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,14 @@ static int hb_hp_detect(void)
{
struct i2c_adapter *adap = i2c_get_adapter(1);
int ret;

struct i2c_client tpa_i2c_client = {
.addr = 0x60,
.adapter = adap,
};

if (!adap)
return -EPROBE_DEFER; /* I2C module not yet available */

ret = i2c_smbus_read_byte(&tpa_i2c_client) >= 0;
i2c_put_adapter(adap);
return ret;
Expand All @@ -342,7 +344,10 @@ static int snd_rpi_hifiberry_dacplus_probe(struct platform_device *pdev)
struct of_changeset ocs;

/* probe for head phone amp */
if (hb_hp_detect()) {
ret = hb_hp_detect();
if (ret < 0)
return ret;
if (ret) {
card->aux_dev = hifiberry_dacplus_aux_devs;
card->num_aux_devs =
ARRAY_SIZE(hifiberry_dacplus_aux_devs);
Expand Down

0 comments on commit 7c449ff

Please sign in to comment.