Skip to content

Commit da29b94

Browse files
jhovoldbroonie
authored andcommitted
ASoC: codecs: wcd938x: fix resource leaks on bind errors
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: [email protected] # 5.14 Cc: Srinivas Kandagatla <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent fa2f8a9 commit da29b94

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

sound/soc/codecs/wcd938x.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,15 +3435,17 @@ static int wcd938x_bind(struct device *dev)
34353435
wcd938x->rxdev = wcd938x_sdw_device_get(wcd938x->rxnode);
34363436
if (!wcd938x->rxdev) {
34373437
dev_err(dev, "could not find slave with matching of node\n");
3438-
return -EINVAL;
3438+
ret = -EINVAL;
3439+
goto err_unbind;
34393440
}
34403441
wcd938x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd938x->rxdev);
34413442
wcd938x->sdw_priv[AIF1_PB]->wcd938x = wcd938x;
34423443

34433444
wcd938x->txdev = wcd938x_sdw_device_get(wcd938x->txnode);
34443445
if (!wcd938x->txdev) {
34453446
dev_err(dev, "could not find txslave with matching of node\n");
3446-
return -EINVAL;
3447+
ret = -EINVAL;
3448+
goto err_put_rxdev;
34473449
}
34483450
wcd938x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd938x->txdev);
34493451
wcd938x->sdw_priv[AIF1_CAP]->wcd938x = wcd938x;
@@ -3454,31 +3456,35 @@ static int wcd938x_bind(struct device *dev)
34543456
if (!device_link_add(wcd938x->rxdev, wcd938x->txdev, DL_FLAG_STATELESS |
34553457
DL_FLAG_PM_RUNTIME)) {
34563458
dev_err(dev, "could not devlink tx and rx\n");
3457-
return -EINVAL;
3459+
ret = -EINVAL;
3460+
goto err_put_txdev;
34583461
}
34593462

34603463
if (!device_link_add(dev, wcd938x->txdev, DL_FLAG_STATELESS |
34613464
DL_FLAG_PM_RUNTIME)) {
34623465
dev_err(dev, "could not devlink wcd and tx\n");
3463-
return -EINVAL;
3466+
ret = -EINVAL;
3467+
goto err_remove_rxtx_link;
34643468
}
34653469

34663470
if (!device_link_add(dev, wcd938x->rxdev, DL_FLAG_STATELESS |
34673471
DL_FLAG_PM_RUNTIME)) {
34683472
dev_err(dev, "could not devlink wcd and rx\n");
3469-
return -EINVAL;
3473+
ret = -EINVAL;
3474+
goto err_remove_tx_link;
34703475
}
34713476

34723477
wcd938x->regmap = dev_get_regmap(&wcd938x->tx_sdw_dev->dev, NULL);
34733478
if (!wcd938x->regmap) {
34743479
dev_err(dev, "could not get TX device regmap\n");
3475-
return -EINVAL;
3480+
ret = -EINVAL;
3481+
goto err_remove_rx_link;
34763482
}
34773483

34783484
ret = wcd938x_irq_init(wcd938x, dev);
34793485
if (ret) {
34803486
dev_err(dev, "%s: IRQ init failed: %d\n", __func__, ret);
3481-
return ret;
3487+
goto err_remove_rx_link;
34823488
}
34833489

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

34933499
ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
34943500
wcd938x_dais, ARRAY_SIZE(wcd938x_dais));
3495-
if (ret)
3501+
if (ret) {
34963502
dev_err(dev, "%s: Codec registration failed\n",
34973503
__func__);
3504+
goto err_remove_rx_link;
3505+
}
34983506

3499-
return ret;
3507+
return 0;
35003508

3509+
err_remove_rx_link:
3510+
device_link_remove(dev, wcd938x->rxdev);
3511+
err_remove_tx_link:
3512+
device_link_remove(dev, wcd938x->txdev);
3513+
err_remove_rxtx_link:
3514+
device_link_remove(wcd938x->rxdev, wcd938x->txdev);
3515+
err_put_txdev:
3516+
put_device(wcd938x->txdev);
3517+
err_put_rxdev:
3518+
put_device(wcd938x->rxdev);
3519+
err_unbind:
3520+
component_unbind_all(dev, wcd938x);
3521+
3522+
return ret;
35013523
}
35023524

35033525
static void wcd938x_unbind(struct device *dev)
@@ -3508,6 +3530,8 @@ static void wcd938x_unbind(struct device *dev)
35083530
device_link_remove(dev, wcd938x->txdev);
35093531
device_link_remove(dev, wcd938x->rxdev);
35103532
device_link_remove(wcd938x->rxdev, wcd938x->txdev);
3533+
put_device(wcd938x->txdev);
3534+
put_device(wcd938x->rxdev);
35113535
component_unbind_all(dev, wcd938x);
35123536
}
35133537

0 commit comments

Comments
 (0)