Commit 8cb9b001 authored by Charles Keepax's avatar Charles Keepax Committed by Mark Brown

ASoC: cs35l34: 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-5-ckeepax@opensource.cirrus.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 77908dbe
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <sound/cs35l34.h> #include <sound/cs35l34.h>
#include "cs35l34.h" #include "cs35l34.h"
#include "cirrus_legacy.h"
#define PDN_DONE_ATTEMPTS 10 #define PDN_DONE_ATTEMPTS 10
#define CS35L34_START_DELAY 50 #define CS35L34_START_DELAY 50
...@@ -996,9 +997,8 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client, ...@@ -996,9 +997,8 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client,
struct cs35l34_private *cs35l34; struct cs35l34_private *cs35l34;
struct cs35l34_platform_data *pdata = struct cs35l34_platform_data *pdata =
dev_get_platdata(&i2c_client->dev); dev_get_platdata(&i2c_client->dev);
int i; int i, devid;
int ret; int ret;
unsigned int devid = 0;
unsigned int reg; unsigned int reg;
cs35l34 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l34), GFP_KERNEL); cs35l34 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l34), GFP_KERNEL);
...@@ -1039,13 +1039,15 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client, ...@@ -1039,13 +1039,15 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client,
} else { } else {
pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata),
GFP_KERNEL); GFP_KERNEL);
if (!pdata) if (!pdata) {
return -ENOMEM; ret = -ENOMEM;
goto err_regulator;
}
if (i2c_client->dev.of_node) { if (i2c_client->dev.of_node) {
ret = cs35l34_handle_of_data(i2c_client, pdata); ret = cs35l34_handle_of_data(i2c_client, pdata);
if (ret != 0) if (ret != 0)
return ret; goto err_regulator;
} }
cs35l34->pdata = *pdata; cs35l34->pdata = *pdata;
...@@ -1059,33 +1061,34 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client, ...@@ -1059,33 +1061,34 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client,
cs35l34->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, cs35l34->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
"reset-gpios", GPIOD_OUT_LOW); "reset-gpios", GPIOD_OUT_LOW);
if (IS_ERR(cs35l34->reset_gpio)) if (IS_ERR(cs35l34->reset_gpio)) {
return PTR_ERR(cs35l34->reset_gpio); ret = PTR_ERR(cs35l34->reset_gpio);
goto err_regulator;
}
gpiod_set_value_cansleep(cs35l34->reset_gpio, 1); gpiod_set_value_cansleep(cs35l34->reset_gpio, 1);
msleep(CS35L34_START_DELAY); msleep(CS35L34_START_DELAY);
ret = regmap_read(cs35l34->regmap, CS35L34_DEVID_AB, &reg); devid = cirrus_read_device_id(cs35l34->regmap, CS35L34_DEVID_AB);
if (devid < 0) {
devid = (reg & 0xFF) << 12; ret = devid;
ret = regmap_read(cs35l34->regmap, CS35L34_DEVID_CD, &reg); dev_err(&i2c_client->dev, "Failed to read device ID: %d\n", ret);
devid |= (reg & 0xFF) << 4; goto err_reset;
ret = regmap_read(cs35l34->regmap, CS35L34_DEVID_E, &reg); }
devid |= (reg & 0xF0) >> 4;
if (devid != CS35L34_CHIP_ID) { if (devid != CS35L34_CHIP_ID) {
dev_err(&i2c_client->dev, dev_err(&i2c_client->dev,
"CS35l34 Device ID (%X). Expected ID %X\n", "CS35l34 Device ID (%X). Expected ID %X\n",
devid, CS35L34_CHIP_ID); devid, CS35L34_CHIP_ID);
ret = -ENODEV; ret = -ENODEV;
goto err_regulator; goto err_reset;
} }
ret = regmap_read(cs35l34->regmap, CS35L34_REV_ID, &reg); ret = regmap_read(cs35l34->regmap, CS35L34_REV_ID, &reg);
if (ret < 0) { if (ret < 0) {
dev_err(&i2c_client->dev, "Get Revision ID failed\n"); dev_err(&i2c_client->dev, "Get Revision ID failed\n");
goto err_regulator; goto err_reset;
} }
dev_info(&i2c_client->dev, dev_info(&i2c_client->dev,
...@@ -1110,11 +1113,13 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client, ...@@ -1110,11 +1113,13 @@ static int cs35l34_i2c_probe(struct i2c_client *i2c_client,
if (ret < 0) { if (ret < 0) {
dev_err(&i2c_client->dev, dev_err(&i2c_client->dev,
"%s: Register component failed\n", __func__); "%s: Register component failed\n", __func__);
goto err_regulator; goto err_reset;
} }
return 0; return 0;
err_reset:
gpiod_set_value_cansleep(cs35l34->reset_gpio, 0);
err_regulator: err_regulator:
regulator_bulk_disable(cs35l34->num_core_supplies, regulator_bulk_disable(cs35l34->num_core_supplies,
cs35l34->core_supplies); cs35l34->core_supplies);
......
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