Skip to content

Commit

Permalink
ASoC: codecs: wcd938x: fix resource leaks on bind errors
Browse files Browse the repository at this point in the history
Add the missing code to release resources on bind errors, including the
references taken by wcd938x_sdw_device_get() which also need to be
dropped on unbind().

Fixes: 1657252 ("ASoC: codecs: wcd938x-sdw: add SoundWire driver")
Cc: stable@vger.kernel.org      # 5.14
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Link: https://lore.kernel.org/r/20231003155558.27079-4-johan+linaro@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Johan Hovold authored and Mark Brown committed Oct 9, 2023
1 parent fa2f8a9 commit da29b94
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions sound/soc/codecs/wcd938x.c
Original file line number Diff line number Diff line change
Expand Up @@ -3435,15 +3435,17 @@ static int wcd938x_bind(struct device *dev)
wcd938x->rxdev = wcd938x_sdw_device_get(wcd938x->rxnode);
if (!wcd938x->rxdev) {
dev_err(dev, "could not find slave with matching of node\n");
return -EINVAL;
ret = -EINVAL;
goto err_unbind;
}
wcd938x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd938x->rxdev);
wcd938x->sdw_priv[AIF1_PB]->wcd938x = wcd938x;

wcd938x->txdev = wcd938x_sdw_device_get(wcd938x->txnode);
if (!wcd938x->txdev) {
dev_err(dev, "could not find txslave with matching of node\n");
return -EINVAL;
ret = -EINVAL;
goto err_put_rxdev;
}
wcd938x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd938x->txdev);
wcd938x->sdw_priv[AIF1_CAP]->wcd938x = wcd938x;
Expand All @@ -3454,31 +3456,35 @@ static int wcd938x_bind(struct device *dev)
if (!device_link_add(wcd938x->rxdev, wcd938x->txdev, DL_FLAG_STATELESS |
DL_FLAG_PM_RUNTIME)) {
dev_err(dev, "could not devlink tx and rx\n");
return -EINVAL;
ret = -EINVAL;
goto err_put_txdev;
}

if (!device_link_add(dev, wcd938x->txdev, DL_FLAG_STATELESS |
DL_FLAG_PM_RUNTIME)) {
dev_err(dev, "could not devlink wcd and tx\n");
return -EINVAL;
ret = -EINVAL;
goto err_remove_rxtx_link;
}

if (!device_link_add(dev, wcd938x->rxdev, DL_FLAG_STATELESS |
DL_FLAG_PM_RUNTIME)) {
dev_err(dev, "could not devlink wcd and rx\n");
return -EINVAL;
ret = -EINVAL;
goto err_remove_tx_link;
}

wcd938x->regmap = dev_get_regmap(&wcd938x->tx_sdw_dev->dev, NULL);
if (!wcd938x->regmap) {
dev_err(dev, "could not get TX device regmap\n");
return -EINVAL;
ret = -EINVAL;
goto err_remove_rx_link;
}

ret = wcd938x_irq_init(wcd938x, dev);
if (ret) {
dev_err(dev, "%s: IRQ init failed: %d\n", __func__, ret);
return ret;
goto err_remove_rx_link;
}

wcd938x->sdw_priv[AIF1_PB]->slave_irq = wcd938x->virq;
Expand All @@ -3487,17 +3493,33 @@ static int wcd938x_bind(struct device *dev)
ret = wcd938x_set_micbias_data(wcd938x);
if (ret < 0) {
dev_err(dev, "%s: bad micbias pdata\n", __func__);
return ret;
goto err_remove_rx_link;
}

ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
wcd938x_dais, ARRAY_SIZE(wcd938x_dais));
if (ret)
if (ret) {
dev_err(dev, "%s: Codec registration failed\n",
__func__);
goto err_remove_rx_link;
}

return ret;
return 0;

err_remove_rx_link:
device_link_remove(dev, wcd938x->rxdev);
err_remove_tx_link:
device_link_remove(dev, wcd938x->txdev);
err_remove_rxtx_link:
device_link_remove(wcd938x->rxdev, wcd938x->txdev);
err_put_txdev:
put_device(wcd938x->txdev);
err_put_rxdev:
put_device(wcd938x->rxdev);
err_unbind:
component_unbind_all(dev, wcd938x);

return ret;
}

static void wcd938x_unbind(struct device *dev)
Expand All @@ -3508,6 +3530,8 @@ static void wcd938x_unbind(struct device *dev)
device_link_remove(dev, wcd938x->txdev);
device_link_remove(dev, wcd938x->rxdev);
device_link_remove(wcd938x->rxdev, wcd938x->txdev);
put_device(wcd938x->txdev);
put_device(wcd938x->rxdev);
component_unbind_all(dev, wcd938x);
}

Expand Down

0 comments on commit da29b94

Please sign in to comment.