diff options
author | Ryder Lee <ryder.lee@mediatek.com> | 2018-01-22 06:33:05 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-01-22 07:18:36 -0500 |
commit | dc2a17f4f074c434757e2cef5026d4747fe22955 (patch) | |
tree | 738c6a27db2ebe5030b3a791248fb11597ef77ee | |
parent | 11aa2d9613c9523f8f78863bdfc7d79b37afcbbe (diff) |
ASoC: mediatek: fix double free in mt2701_afe_pcm_dev_probe()
The commit dfa3cbb8(ASoC: mediatek: modify MT2701 AFE driver to adapt mfd device)
leads to the following static checker warning:
sound/soc/mediatek/mt2701/mt2701-afe-pcm.c:1535 mt2701_afe_pcm_dev_probe()
error: double free of 'component'
This patch fixes that and adds a helper mt2701_afe_add_component() to setup
component.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c index 5bc4e00a4a29..d68b53f7cefe 100644 --- a/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c +++ b/sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | |||
@@ -1405,9 +1405,24 @@ static int mt2701_afe_runtime_resume(struct device *dev) | |||
1405 | return mt2701_afe_enable_clock(afe); | 1405 | return mt2701_afe_enable_clock(afe); |
1406 | } | 1406 | } |
1407 | 1407 | ||
1408 | static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) | 1408 | static int mt2701_afe_add_component(struct mtk_base_afe *afe) |
1409 | { | 1409 | { |
1410 | struct snd_soc_component *component; | 1410 | struct snd_soc_component *component; |
1411 | |||
1412 | component = kzalloc(sizeof(*component), GFP_KERNEL); | ||
1413 | if (!component) | ||
1414 | return -ENOMEM; | ||
1415 | |||
1416 | component->regmap = afe->regmap; | ||
1417 | |||
1418 | return snd_soc_add_component(afe->dev, component, | ||
1419 | &mt2701_afe_pcm_dai_component, | ||
1420 | mt2701_afe_pcm_dais, | ||
1421 | ARRAY_SIZE(mt2701_afe_pcm_dais)); | ||
1422 | } | ||
1423 | |||
1424 | static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) | ||
1425 | { | ||
1411 | struct mtk_base_afe *afe; | 1426 | struct mtk_base_afe *afe; |
1412 | struct mt2701_afe_private *afe_priv; | 1427 | struct mt2701_afe_private *afe_priv; |
1413 | struct device *dev; | 1428 | struct device *dev; |
@@ -1477,12 +1492,6 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) | |||
1477 | = &mt2701_i2s_data[i][I2S_IN]; | 1492 | = &mt2701_i2s_data[i][I2S_IN]; |
1478 | } | 1493 | } |
1479 | 1494 | ||
1480 | component = kzalloc(sizeof(*component), GFP_KERNEL); | ||
1481 | if (!component) | ||
1482 | return -ENOMEM; | ||
1483 | |||
1484 | component->regmap = afe->regmap; | ||
1485 | |||
1486 | afe->mtk_afe_hardware = &mt2701_afe_hardware; | 1495 | afe->mtk_afe_hardware = &mt2701_afe_hardware; |
1487 | afe->memif_fs = mt2701_memif_fs; | 1496 | afe->memif_fs = mt2701_memif_fs; |
1488 | afe->irq_fs = mt2701_irq_fs; | 1497 | afe->irq_fs = mt2701_irq_fs; |
@@ -1495,7 +1504,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) | |||
1495 | ret = mt2701_init_clock(afe); | 1504 | ret = mt2701_init_clock(afe); |
1496 | if (ret) { | 1505 | if (ret) { |
1497 | dev_err(dev, "init clock error\n"); | 1506 | dev_err(dev, "init clock error\n"); |
1498 | goto err_init_clock; | 1507 | return ret; |
1499 | } | 1508 | } |
1500 | 1509 | ||
1501 | platform_set_drvdata(pdev, afe); | 1510 | platform_set_drvdata(pdev, afe); |
@@ -1514,10 +1523,7 @@ static int mt2701_afe_pcm_dev_probe(struct platform_device *pdev) | |||
1514 | goto err_platform; | 1523 | goto err_platform; |
1515 | } | 1524 | } |
1516 | 1525 | ||
1517 | ret = snd_soc_add_component(dev, component, | 1526 | ret = mt2701_afe_add_component(afe); |
1518 | &mt2701_afe_pcm_dai_component, | ||
1519 | mt2701_afe_pcm_dais, | ||
1520 | ARRAY_SIZE(mt2701_afe_pcm_dais)); | ||
1521 | if (ret) { | 1527 | if (ret) { |
1522 | dev_warn(dev, "err_dai_component\n"); | 1528 | dev_warn(dev, "err_dai_component\n"); |
1523 | goto err_dai_component; | 1529 | goto err_dai_component; |
@@ -1531,8 +1537,6 @@ err_platform: | |||
1531 | pm_runtime_put_sync(dev); | 1537 | pm_runtime_put_sync(dev); |
1532 | err_pm_disable: | 1538 | err_pm_disable: |
1533 | pm_runtime_disable(dev); | 1539 | pm_runtime_disable(dev); |
1534 | err_init_clock: | ||
1535 | kfree(component); | ||
1536 | 1540 | ||
1537 | return ret; | 1541 | return ret; |
1538 | } | 1542 | } |