diff mbox series

[2/3] ASoC: stm32: dfsdm: add pm_runtime support for audio

Message ID 20211118090035.5331-3-olivier.moysan@foss.st.com (mailing list archive)
State New, archived
Headers show
Series ASoC: stm32: add pm runtime support | expand

Commit Message

Olivier Moysan Nov. 18, 2021, 9 a.m. UTC
Enable support of pm_runtime on STM32 DFSDM audio driver
to allow power state monitoring.

Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
---
 sound/soc/stm/stm32_adfsdm.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Mark Brown Nov. 18, 2021, 1:56 p.m. UTC | #1
On Thu, Nov 18, 2021 at 10:00:34AM +0100, Olivier Moysan wrote:

>  	ret = snd_soc_add_component(component, NULL, 0);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(&pdev->dev, "%s: Failed to register PCM platform\n",
>  			__func__);
> +		return ret;
> +	}
>  
> -	return ret;
> +	pm_runtime_enable(&pdev->dev);

Enabling runtime PM after registering the component may potentially lead
to a race where something manages to go in and starts using the device
including what should be runtime PM stuff.  That'd lead to a reference
not being taken that should be.  It's unlikely to actually happen but
it's better to be safe.
diff mbox series

Patch

diff --git a/sound/soc/stm/stm32_adfsdm.c b/sound/soc/stm/stm32_adfsdm.c
index e6078f50e508..534f96af97c5 100644
--- a/sound/soc/stm/stm32_adfsdm.c
+++ b/sound/soc/stm/stm32_adfsdm.c
@@ -12,7 +12,7 @@ 
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
-
+#include <linux/pm_runtime.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/consumer.h>
 #include <linux/iio/adc/stm32-dfsdm-adc.h>
@@ -363,15 +363,20 @@  static int stm32_adfsdm_probe(struct platform_device *pdev)
 #endif
 
 	ret = snd_soc_add_component(component, NULL, 0);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&pdev->dev, "%s: Failed to register PCM platform\n",
 			__func__);
+		return ret;
+	}
 
-	return ret;
+	pm_runtime_enable(&pdev->dev);
+
+	return 0;
 }
 
 static int stm32_adfsdm_remove(struct platform_device *pdev)
 {
+	pm_runtime_disable(&pdev->dev);
 	snd_soc_unregister_component(&pdev->dev);
 
 	return 0;