Commit 0187294d authored by Dinghao Liu's avatar Dinghao Liu Committed by Jonathan Cameron

iio: magnetometer: ak8974: Fix runtime PM imbalance on error

When devm_regmap_init_i2c() returns an error code, a pairing
runtime PM usage counter decrement is needed to keep the
counter balanced. For error paths after ak8974_set_power(),
ak8974_detect() and ak8974_reset(), things are the same.

However, When iio_triggered_buffer_setup() returns an error
code, there will be two PM usgae counter decrements.
Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
Fixes: 7c94a8b2 ("iio: magn: add a driver for AK8974")
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Cc: <Stable@vger.kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d7369ae1
...@@ -862,19 +862,21 @@ static int ak8974_probe(struct i2c_client *i2c, ...@@ -862,19 +862,21 @@ static int ak8974_probe(struct i2c_client *i2c,
ak8974->map = devm_regmap_init_i2c(i2c, &ak8974_regmap_config); ak8974->map = devm_regmap_init_i2c(i2c, &ak8974_regmap_config);
if (IS_ERR(ak8974->map)) { if (IS_ERR(ak8974->map)) {
dev_err(&i2c->dev, "failed to allocate register map\n"); dev_err(&i2c->dev, "failed to allocate register map\n");
pm_runtime_put_noidle(&i2c->dev);
pm_runtime_disable(&i2c->dev);
return PTR_ERR(ak8974->map); return PTR_ERR(ak8974->map);
} }
ret = ak8974_set_power(ak8974, AK8974_PWR_ON); ret = ak8974_set_power(ak8974, AK8974_PWR_ON);
if (ret) { if (ret) {
dev_err(&i2c->dev, "could not power on\n"); dev_err(&i2c->dev, "could not power on\n");
goto power_off; goto disable_pm;
} }
ret = ak8974_detect(ak8974); ret = ak8974_detect(ak8974);
if (ret) { if (ret) {
dev_err(&i2c->dev, "neither AK8974 nor AMI30x found\n"); dev_err(&i2c->dev, "neither AK8974 nor AMI30x found\n");
goto power_off; goto disable_pm;
} }
ret = ak8974_selftest(ak8974); ret = ak8974_selftest(ak8974);
...@@ -884,14 +886,9 @@ static int ak8974_probe(struct i2c_client *i2c, ...@@ -884,14 +886,9 @@ static int ak8974_probe(struct i2c_client *i2c,
ret = ak8974_reset(ak8974); ret = ak8974_reset(ak8974);
if (ret) { if (ret) {
dev_err(&i2c->dev, "AK8974 reset failed\n"); dev_err(&i2c->dev, "AK8974 reset failed\n");
goto power_off; goto disable_pm;
} }
pm_runtime_set_autosuspend_delay(&i2c->dev,
AK8974_AUTOSUSPEND_DELAY);
pm_runtime_use_autosuspend(&i2c->dev);
pm_runtime_put(&i2c->dev);
indio_dev->dev.parent = &i2c->dev; indio_dev->dev.parent = &i2c->dev;
switch (ak8974->variant) { switch (ak8974->variant) {
case AK8974_WHOAMI_VALUE_AMI306: case AK8974_WHOAMI_VALUE_AMI306:
...@@ -957,6 +954,11 @@ static int ak8974_probe(struct i2c_client *i2c, ...@@ -957,6 +954,11 @@ static int ak8974_probe(struct i2c_client *i2c,
goto cleanup_buffer; goto cleanup_buffer;
} }
pm_runtime_set_autosuspend_delay(&i2c->dev,
AK8974_AUTOSUSPEND_DELAY);
pm_runtime_use_autosuspend(&i2c->dev);
pm_runtime_put(&i2c->dev);
return 0; return 0;
cleanup_buffer: cleanup_buffer:
...@@ -965,7 +967,6 @@ static int ak8974_probe(struct i2c_client *i2c, ...@@ -965,7 +967,6 @@ static int ak8974_probe(struct i2c_client *i2c,
pm_runtime_put_noidle(&i2c->dev); pm_runtime_put_noidle(&i2c->dev);
pm_runtime_disable(&i2c->dev); pm_runtime_disable(&i2c->dev);
ak8974_set_power(ak8974, AK8974_PWR_OFF); ak8974_set_power(ak8974, AK8974_PWR_OFF);
power_off:
regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs); regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
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