Commit e2bb1077 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

ASoC: cs43130: Minor error paths fixups

Correct some unchecked re-allocations of ret whilst reading the device
ID and ensure the hardware state is returned to off on the error
paths.
Reported-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20210510131357.17170-10-ckeepax@opensource.cirrus.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 26495252
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <sound/jack.h> #include <sound/jack.h>
#include "cs43130.h" #include "cs43130.h"
#include "cirrus_legacy.h"
static const struct reg_default cs43130_reg_defaults[] = { static const struct reg_default cs43130_reg_defaults[] = {
{CS43130_SYS_CLK_CTL_1, 0x06}, {CS43130_SYS_CLK_CTL_1, 0x06},
...@@ -2424,9 +2425,8 @@ static int cs43130_i2c_probe(struct i2c_client *client, ...@@ -2424,9 +2425,8 @@ static int cs43130_i2c_probe(struct i2c_client *client,
{ {
struct cs43130_private *cs43130; struct cs43130_private *cs43130;
int ret; int ret;
unsigned int devid = 0;
unsigned int reg; unsigned int reg;
int i; int i, devid;
cs43130 = devm_kzalloc(&client->dev, sizeof(*cs43130), GFP_KERNEL); cs43130 = devm_kzalloc(&client->dev, sizeof(*cs43130), GFP_KERNEL);
if (!cs43130) if (!cs43130)
...@@ -2464,20 +2464,21 @@ static int cs43130_i2c_probe(struct i2c_client *client, ...@@ -2464,20 +2464,21 @@ static int cs43130_i2c_probe(struct i2c_client *client,
cs43130->reset_gpio = devm_gpiod_get_optional(&client->dev, cs43130->reset_gpio = devm_gpiod_get_optional(&client->dev,
"reset", GPIOD_OUT_LOW); "reset", GPIOD_OUT_LOW);
if (IS_ERR(cs43130->reset_gpio)) if (IS_ERR(cs43130->reset_gpio)) {
return PTR_ERR(cs43130->reset_gpio); ret = PTR_ERR(cs43130->reset_gpio);
goto err_supplies;
}
gpiod_set_value_cansleep(cs43130->reset_gpio, 1); gpiod_set_value_cansleep(cs43130->reset_gpio, 1);
usleep_range(2000, 2050); usleep_range(2000, 2050);
ret = regmap_read(cs43130->regmap, CS43130_DEVID_AB, &reg); devid = cirrus_read_device_id(cs43130->regmap, CS43130_DEVID_AB);
if (devid < 0) {
devid = (reg & 0xFF) << 12; ret = devid;
ret = regmap_read(cs43130->regmap, CS43130_DEVID_CD, &reg); dev_err(&client->dev, "Failed to read device ID: %d\n", ret);
devid |= (reg & 0xFF) << 4; goto err;
ret = regmap_read(cs43130->regmap, CS43130_DEVID_E, &reg); }
devid |= (reg & 0xF0) >> 4;
switch (devid) { switch (devid) {
case CS43130_CHIP_ID: case CS43130_CHIP_ID:
...@@ -2517,7 +2518,7 @@ static int cs43130_i2c_probe(struct i2c_client *client, ...@@ -2517,7 +2518,7 @@ static int cs43130_i2c_probe(struct i2c_client *client,
"cs43130", cs43130); "cs43130", cs43130);
if (ret != 0) { if (ret != 0) {
dev_err(&client->dev, "Failed to request IRQ: %d\n", ret); dev_err(&client->dev, "Failed to request IRQ: %d\n", ret);
return ret; goto err;
} }
cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO; cs43130->mclk_int_src = CS43130_MCLK_SRC_RCO;
...@@ -2576,7 +2577,13 @@ static int cs43130_i2c_probe(struct i2c_client *client, ...@@ -2576,7 +2577,13 @@ static int cs43130_i2c_probe(struct i2c_client *client,
CS43130_XSP_3ST_MASK, 0); CS43130_XSP_3ST_MASK, 0);
return 0; return 0;
err: err:
gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
err_supplies:
regulator_bulk_disable(ARRAY_SIZE(cs43130->supplies),
cs43130->supplies);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment