mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 14:42:24 +00:00
ASoC: fsl_mqs: Fix error handling in probe
There are several problems in the error handling in fsl_mqs_probe().
1) "ret" isn't initialized on some paths. GCC has a feature which
warns about uninitialized variables but the code initializes "ret"
to zero at the start of the function so the checking is turned off.
2) "gpr_np" is a pointer so initializing it to zero is confusing and
generates a Sparse warning.
3) of_parse_phandle() doesn't return error pointers on error, it returns
NULL.
4) If devm_snd_soc_register_component() fails then the function should
free the "gpr_np".
Fixes: 9e28f6532c
("ASoC: fsl_mqs: Add MQS component driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20191004102208.GB823@mwanda
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
e9e8fc9ed6
commit
a9d2736714
@ -178,10 +178,10 @@ static const struct regmap_config fsl_mqs_regmap_config = {
|
|||||||
static int fsl_mqs_probe(struct platform_device *pdev)
|
static int fsl_mqs_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device_node *np = pdev->dev.of_node;
|
struct device_node *np = pdev->dev.of_node;
|
||||||
struct device_node *gpr_np = 0;
|
struct device_node *gpr_np = NULL;
|
||||||
struct fsl_mqs *mqs_priv;
|
struct fsl_mqs *mqs_priv;
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
int ret = 0;
|
int ret;
|
||||||
|
|
||||||
mqs_priv = devm_kzalloc(&pdev->dev, sizeof(*mqs_priv), GFP_KERNEL);
|
mqs_priv = devm_kzalloc(&pdev->dev, sizeof(*mqs_priv), GFP_KERNEL);
|
||||||
if (!mqs_priv)
|
if (!mqs_priv)
|
||||||
@ -198,17 +198,16 @@ static int fsl_mqs_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
if (mqs_priv->use_gpr) {
|
if (mqs_priv->use_gpr) {
|
||||||
gpr_np = of_parse_phandle(np, "gpr", 0);
|
gpr_np = of_parse_phandle(np, "gpr", 0);
|
||||||
if (IS_ERR(gpr_np)) {
|
if (!gpr_np) {
|
||||||
dev_err(&pdev->dev, "failed to get gpr node by phandle\n");
|
dev_err(&pdev->dev, "failed to get gpr node by phandle\n");
|
||||||
ret = PTR_ERR(gpr_np);
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mqs_priv->regmap = syscon_node_to_regmap(gpr_np);
|
mqs_priv->regmap = syscon_node_to_regmap(gpr_np);
|
||||||
if (IS_ERR(mqs_priv->regmap)) {
|
if (IS_ERR(mqs_priv->regmap)) {
|
||||||
dev_err(&pdev->dev, "failed to get gpr regmap\n");
|
dev_err(&pdev->dev, "failed to get gpr regmap\n");
|
||||||
ret = PTR_ERR(mqs_priv->regmap);
|
ret = PTR_ERR(mqs_priv->regmap);
|
||||||
goto out;
|
goto err_free_gpr_np;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
regs = devm_platform_ioremap_resource(pdev, 0);
|
regs = devm_platform_ioremap_resource(pdev, 0);
|
||||||
@ -229,7 +228,7 @@ static int fsl_mqs_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(mqs_priv->ipg)) {
|
if (IS_ERR(mqs_priv->ipg)) {
|
||||||
dev_err(&pdev->dev, "failed to get the clock: %ld\n",
|
dev_err(&pdev->dev, "failed to get the clock: %ld\n",
|
||||||
PTR_ERR(mqs_priv->ipg));
|
PTR_ERR(mqs_priv->ipg));
|
||||||
goto out;
|
return PTR_ERR(mqs_priv->ipg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,17 +236,21 @@ static int fsl_mqs_probe(struct platform_device *pdev)
|
|||||||
if (IS_ERR(mqs_priv->mclk)) {
|
if (IS_ERR(mqs_priv->mclk)) {
|
||||||
dev_err(&pdev->dev, "failed to get the clock: %ld\n",
|
dev_err(&pdev->dev, "failed to get the clock: %ld\n",
|
||||||
PTR_ERR(mqs_priv->mclk));
|
PTR_ERR(mqs_priv->mclk));
|
||||||
goto out;
|
ret = PTR_ERR(mqs_priv->mclk);
|
||||||
|
goto err_free_gpr_np;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_set_drvdata(&pdev->dev, mqs_priv);
|
dev_set_drvdata(&pdev->dev, mqs_priv);
|
||||||
pm_runtime_enable(&pdev->dev);
|
pm_runtime_enable(&pdev->dev);
|
||||||
|
|
||||||
return devm_snd_soc_register_component(&pdev->dev, &soc_codec_fsl_mqs,
|
ret = devm_snd_soc_register_component(&pdev->dev, &soc_codec_fsl_mqs,
|
||||||
&fsl_mqs_dai, 1);
|
&fsl_mqs_dai, 1);
|
||||||
out:
|
if (ret)
|
||||||
if (!IS_ERR(gpr_np))
|
goto err_free_gpr_np;
|
||||||
of_node_put(gpr_np);
|
return 0;
|
||||||
|
|
||||||
|
err_free_gpr_np:
|
||||||
|
of_node_put(gpr_np);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user