From 3f16a01e6be51974fb8f7ecd6703a332bf5f4f60 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Mon, 8 Jan 2018 22:09:36 +0000 Subject: [PATCH] ASoC: tegra-alt: Fix error path for rt565x machine driver The error path of the Tegra210 rt565x machine driver does not unregister the headset switch on failure. Failure to unregister the headset switch on failure prevents causes subsequent calls to register a switch to fail because one is already registered. Hence, if the probe of the rt565x machine driver is deferred, for example because the codec is not register yet, this will cause subsequent probe attempts to fail because a switch is already registered. Fix the above issues by unregistering the switch in the error path of the Tegra210 rt565x machine driver probe. Finally ensure the switch is unregistered in the removal of the rt565x machine driver. Bug 2044665 Change-Id: Iaeb6f7ae30b6fdff46b0a8679003674804399a99 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/1634166 (cherry picked from commit 1a9cea0e8e97c5b042088d5988184c81db85ea6a) Reviewed-on: https://git-master.nvidia.com/r/1642330 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../tegra_machine_driver_mobile.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c b/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c index 2cc1ae1e..d3e11481 100644 --- a/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c +++ b/sound/soc/tegra-alt/machine_drivers/tegra_machine_driver_mobile.c @@ -1,7 +1,7 @@ /* * tegra_machine_driver_mobile.c - Tegra ASoC Machine driver for mobile * - * Copyright (c) 2017 NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2018 NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -1229,7 +1229,8 @@ static int tegra_machine_driver_probe(struct platform_device *pdev) if (!pdata) { dev_err(&pdev->dev, "Can't allocate tegra_asoc_platform_data struct\n"); - return -ENOMEM; + ret = -ENOMEM; + goto err_switch_unregister; } pdata->gpio_codec1 = pdata->gpio_codec2 = pdata->gpio_codec3 = @@ -1243,13 +1244,13 @@ static int tegra_machine_driver_probe(struct platform_device *pdev) &pdev->dev, card); if (ret) - goto err_alloc_dai_link; + goto err_switch_unregister; ret = snd_soc_register_card(card); if (ret) { dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); - goto err_alloc_dai_link; + goto err_switch_unregister; } rtd = snd_soc_get_pcm_runtime(card, "rt565x-playback"); @@ -1274,6 +1275,10 @@ static int tegra_machine_driver_probe(struct platform_device *pdev) return 0; +err_switch_unregister: +#ifdef CONFIG_SWITCH + tegra_alt_asoc_switch_unregister(&tegra_machine_headset_switch); +#endif err_alloc_dai_link: tegra_machine_remove_dai_link(); tegra_machine_remove_codec_conf(); @@ -1287,6 +1292,9 @@ static int tegra_machine_driver_remove(struct platform_device *pdev) snd_soc_unregister_card(card); +#ifdef CONFIG_SWITCH + tegra_alt_asoc_switch_unregister(&tegra_machine_headset_switch); +#endif tegra_machine_remove_dai_link(); tegra_machine_remove_codec_conf();