Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 534dcd7e authored by Axel Lin's avatar Axel Lin Committed by Mark Brown
Browse files

ASoC: zx296702-i2s: Fix resource leak when unload module



Use devm_* API to fix leaks in current code.
1. Use devm_kzalloc to fix memory leak for zx_i2s when unload the module.
2. Use devm_snd_soc_register_component to ensure component is unregistered
   when unload the module.

Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Reviewed-by: default avatarJun Nie <jun.nie@linaro.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent bc0195aa
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -380,7 +380,7 @@ static int zx_i2s_probe(struct platform_device *pdev)
	struct zx_i2s_info *zx_i2s;
	struct zx_i2s_info *zx_i2s;
	int ret;
	int ret;


	zx_i2s =  kzalloc(sizeof(*zx_i2s), GFP_KERNEL);
	zx_i2s = devm_kzalloc(&pdev->dev, sizeof(*zx_i2s), GFP_KERNEL);
	if (!zx_i2s)
	if (!zx_i2s)
		return -ENOMEM;
		return -ENOMEM;


@@ -401,7 +401,7 @@ static int zx_i2s_probe(struct platform_device *pdev)
	writel_relaxed(0, zx_i2s->reg_base + ZX_I2S_FIFO_CTRL);
	writel_relaxed(0, zx_i2s->reg_base + ZX_I2S_FIFO_CTRL);
	platform_set_drvdata(pdev, zx_i2s);
	platform_set_drvdata(pdev, zx_i2s);


	ret = snd_soc_register_component(&pdev->dev, &zx_i2s_component,
	ret = devm_snd_soc_register_component(&pdev->dev, &zx_i2s_component,
					      &zx_i2s_dai, 1);
					      &zx_i2s_dai, 1);
	if (ret) {
	if (ret) {
		dev_err(&pdev->dev, "Register DAI failed: %d\n", ret);
		dev_err(&pdev->dev, "Register DAI failed: %d\n", ret);