Unverified Commit 746dca0a authored by Cheng-Yi Chiang's avatar Cheng-Yi Chiang Committed by Mark Brown
Browse files

ASoC: rt5663: Fix error handling of regulator_set_load



The default implementation of regulator_set_load returns
REGULATOR_MODE_NORMAL, which is positive.  [This was a bug which is
being fixed but the change is valid anyway -- bronie]

rt5663_i2c_probe should only do error handling when return value of
regulator_set_load is negative.
In this case, rt5663_i2c_probe should return error.

Also, consolidate err_irq into err_enable.

Fix the missing goto for temporary regmap and rt5663->regmap.

Signed-off-by: default avatarCheng-Yi Chiang <cychiang@chromium.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 00347e4e
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -3525,10 +3525,11 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
	for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) {
	for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) {
		ret = regulator_set_load(rt5663->supplies[i].consumer,
		ret = regulator_set_load(rt5663->supplies[i].consumer,
					 RT5663_SUPPLY_CURRENT_UA);
					 RT5663_SUPPLY_CURRENT_UA);
		if (ret) {
		if (ret < 0) {
			dev_err(&i2c->dev,
			dev_err(&i2c->dev,
				"Failed to set regulator %s, ret: %d\n",
				"Failed to set regulator load on %s, ret: %d\n",
				rt5663->supplies[i].supply, ret);
				rt5663->supplies[i].supply, ret);
			return ret;
		}
		}
	}
	}


@@ -3546,7 +3547,7 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
		ret = PTR_ERR(regmap);
		ret = PTR_ERR(regmap);
		dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n",
		dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n",
			ret);
			ret);
		return ret;
		goto err_enable;
	}
	}


	ret = regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
	ret = regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
@@ -3579,7 +3580,7 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
		ret = PTR_ERR(rt5663->regmap);
		ret = PTR_ERR(rt5663->regmap);
		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
			ret);
			ret);
		return ret;
		goto err_enable;
	}
	}


	/* reset and calibrate */
	/* reset and calibrate */
@@ -3689,17 +3690,19 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
			rt5663_dai, ARRAY_SIZE(rt5663_dai));
			rt5663_dai, ARRAY_SIZE(rt5663_dai));


	if (ret)
	if (ret)
		goto err_irq;
		goto err_enable;


	return 0;
	return 0;


err_irq:

	/*
	 * Error after enabling regulators should goto err_enable
	 * to disable regulators.
	 */
err_enable:
	if (i2c->irq)
	if (i2c->irq)
		free_irq(i2c->irq, rt5663);
		free_irq(i2c->irq, rt5663);


err_enable:
	dev_err(&i2c->dev,
		"%s: Disable regulator after probe error\n", __func__);
	regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
	regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
	return ret;
	return ret;
}
}