All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling
@ 2018-02-22 19:02 Fabio Estevam
  2018-02-22 19:02 ` [PATCH 2/2] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Fabio Estevam @ 2018-02-22 19:02 UTC (permalink / raw)
  To: broonie; +Cc: Fabio Estevam, alsa-devel, lars

From: Fabio Estevam <fabio.estevam@nxp.com>

When dmaengine_pcm_request_chan_of() fails it should release
the previously acquired resources, which in this case is to
call kfree(pcm), so jump to the correct point in the error
path.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 sound/soc/soc-generic-dmaengine-pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 768247f..32ea16d 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -450,7 +450,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
 
 	ret = dmaengine_pcm_request_chan_of(pcm, dev, config);
 	if (ret)
-		goto err_free_dma;
+		goto err_free_pcm;
 
 	ret = snd_soc_add_component(dev, &pcm->component,
 				    &dmaengine_pcm_component, NULL, 0);
@@ -461,6 +461,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
 
 err_free_dma:
 	dmaengine_pcm_release_chan(pcm);
+err_free_pcm:
 	kfree(pcm);
 	return ret;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings
  2018-02-22 19:02 [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Fabio Estevam
@ 2018-02-22 19:02 ` Fabio Estevam
  2018-02-26 11:17   ` Applied "ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings" to the asoc tree Mark Brown
  2018-02-26 11:17 ` Applied "ASoC: soc-generic-dmaengine-pcm: Fix error handling" " Mark Brown
  2018-02-26 14:25 ` [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Lars-Peter Clausen
  2 siblings, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2018-02-22 19:02 UTC (permalink / raw)
  To: broonie; +Cc: Fabio Estevam, alsa-devel, lars

From: Fabio Estevam <fabio.estevam@nxp.com>

Currently the following sparse warnings are observed:

sound/soc/soc-generic-dmaengine-pcm.c:185:34: warning: restricted snd_pcm_format_t degrades to integer
sound/soc/soc-generic-dmaengine-pcm.c:186:66: warning: incorrect type in argument 1 (different base types)
sound/soc/soc-generic-dmaengine-pcm.c:186:66:    expected restricted snd_pcm_format_t [usertype] format
sound/soc/soc-generic-dmaengine-pcm.c:186:66:    got int [signed] [assigned] i

Fix it by changing the loop variable to be of 'snd_pcm_format_t'.

Also introduce a SNDRV_PCM_FORMAT_FIRST label, which corresponds to the
first member (index 0) of the snd_pcm_format_t formats.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 include/uapi/sound/asound.h           | 1 +
 sound/soc/soc-generic-dmaengine-pcm.c | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 07d6158..ed0a120 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -242,6 +242,7 @@ typedef int __bitwise snd_pcm_format_t;
 #define	SNDRV_PCM_FORMAT_DSD_U16_BE	((__force snd_pcm_format_t) 51) /* DSD, 2-byte samples DSD (x16), big endian */
 #define	SNDRV_PCM_FORMAT_DSD_U32_BE	((__force snd_pcm_format_t) 52) /* DSD, 4-byte samples DSD (x32), big endian */
 #define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_DSD_U32_BE
+#define	SNDRV_PCM_FORMAT_FIRST		SNDRV_PCM_FORMAT_S8
 
 #ifdef SNDRV_LITTLE_ENDIAN
 #define	SNDRV_PCM_FORMAT_S16		SNDRV_PCM_FORMAT_S16_LE
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 32ea16d..785f25e 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -132,7 +132,8 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
 	u32 addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
 			  BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
 			  BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
-	int i, ret;
+	snd_pcm_format_t i;
+	int ret;
 
 	if (pcm->config && pcm->config->pcm_hardware)
 		return snd_soc_set_runtime_hwparams(substream,
@@ -182,7 +183,7 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
 		 * default assumption is that it supports 1, 2 and 4 bytes
 		 * widths.
 		 */
-		for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) {
+		for (i = SNDRV_PCM_FORMAT_FIRST; i <= SNDRV_PCM_FORMAT_LAST; i++) {
 			int bits = snd_pcm_format_physical_width(i);
 
 			/*
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Applied "ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings" to the asoc tree
  2018-02-22 19:02 ` [PATCH 2/2] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings Fabio Estevam
@ 2018-02-26 11:17   ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2018-02-26 11:17 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: alsa-devel, broonie, lars

The patch

   ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 7ed310bd51bec0b440a551fc4da1993c7f6cd231 Mon Sep 17 00:00:00 2001
From: Fabio Estevam <fabio.estevam@nxp.com>
Date: Thu, 22 Feb 2018 16:02:22 -0300
Subject: [PATCH] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings

Currently the following sparse warnings are observed:

sound/soc/soc-generic-dmaengine-pcm.c:185:34: warning: restricted snd_pcm_format_t degrades to integer
sound/soc/soc-generic-dmaengine-pcm.c:186:66: warning: incorrect type in argument 1 (different base types)
sound/soc/soc-generic-dmaengine-pcm.c:186:66:    expected restricted snd_pcm_format_t [usertype] format
sound/soc/soc-generic-dmaengine-pcm.c:186:66:    got int [signed] [assigned] i

Fix it by changing the loop variable to be of 'snd_pcm_format_t'.

Also introduce a SNDRV_PCM_FORMAT_FIRST label, which corresponds to the
first member (index 0) of the snd_pcm_format_t formats.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 include/uapi/sound/asound.h           | 1 +
 sound/soc/soc-generic-dmaengine-pcm.c | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 07d61583fd02..ed0a120d4f08 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -242,6 +242,7 @@ typedef int __bitwise snd_pcm_format_t;
 #define	SNDRV_PCM_FORMAT_DSD_U16_BE	((__force snd_pcm_format_t) 51) /* DSD, 2-byte samples DSD (x16), big endian */
 #define	SNDRV_PCM_FORMAT_DSD_U32_BE	((__force snd_pcm_format_t) 52) /* DSD, 4-byte samples DSD (x32), big endian */
 #define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_DSD_U32_BE
+#define	SNDRV_PCM_FORMAT_FIRST		SNDRV_PCM_FORMAT_S8
 
 #ifdef SNDRV_LITTLE_ENDIAN
 #define	SNDRV_PCM_FORMAT_S16		SNDRV_PCM_FORMAT_S16_LE
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 32ea16d062b1..785f25ede3e5 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -132,7 +132,8 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
 	u32 addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
 			  BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
 			  BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
-	int i, ret;
+	snd_pcm_format_t i;
+	int ret;
 
 	if (pcm->config && pcm->config->pcm_hardware)
 		return snd_soc_set_runtime_hwparams(substream,
@@ -182,7 +183,7 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
 		 * default assumption is that it supports 1, 2 and 4 bytes
 		 * widths.
 		 */
-		for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) {
+		for (i = SNDRV_PCM_FORMAT_FIRST; i <= SNDRV_PCM_FORMAT_LAST; i++) {
 			int bits = snd_pcm_format_physical_width(i);
 
 			/*
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Applied "ASoC: soc-generic-dmaengine-pcm: Fix error handling" to the asoc tree
  2018-02-22 19:02 [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Fabio Estevam
  2018-02-22 19:02 ` [PATCH 2/2] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings Fabio Estevam
@ 2018-02-26 11:17 ` Mark Brown
  2018-02-26 14:25 ` [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Lars-Peter Clausen
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2018-02-26 11:17 UTC (permalink / raw)
  To: Fabio Estevam; +Cc: alsa-devel, broonie, lars

The patch

   ASoC: soc-generic-dmaengine-pcm: Fix error handling

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From f91b1e73ccde71d4bc69ae10d475196df38844ab Mon Sep 17 00:00:00 2001
From: Fabio Estevam <fabio.estevam@nxp.com>
Date: Thu, 22 Feb 2018 16:02:21 -0300
Subject: [PATCH] ASoC: soc-generic-dmaengine-pcm: Fix error handling

When dmaengine_pcm_request_chan_of() fails it should release
the previously acquired resources, which in this case is to
call kfree(pcm), so jump to the correct point in the error
path.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-generic-dmaengine-pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 768247fd92c5..32ea16d062b1 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -450,7 +450,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
 
 	ret = dmaengine_pcm_request_chan_of(pcm, dev, config);
 	if (ret)
-		goto err_free_dma;
+		goto err_free_pcm;
 
 	ret = snd_soc_add_component(dev, &pcm->component,
 				    &dmaengine_pcm_component, NULL, 0);
@@ -461,6 +461,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
 
 err_free_dma:
 	dmaengine_pcm_release_chan(pcm);
+err_free_pcm:
 	kfree(pcm);
 	return ret;
 }
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling
  2018-02-22 19:02 [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Fabio Estevam
  2018-02-22 19:02 ` [PATCH 2/2] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings Fabio Estevam
  2018-02-26 11:17 ` Applied "ASoC: soc-generic-dmaengine-pcm: Fix error handling" " Mark Brown
@ 2018-02-26 14:25 ` Lars-Peter Clausen
  2018-02-26 14:35   ` Fabio Estevam
  2 siblings, 1 reply; 6+ messages in thread
From: Lars-Peter Clausen @ 2018-02-26 14:25 UTC (permalink / raw)
  To: Fabio Estevam, broonie; +Cc: Fabio Estevam, alsa-devel

On 02/22/2018 08:02 PM, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@nxp.com>
> 
> When dmaengine_pcm_request_chan_of() fails it should release
> the previously acquired resources, which in this case is to
> call kfree(pcm), so jump to the correct point in the error
> path.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>

This creates a resource leak. dmaengine_pcm_request_chan_of() requests both
transmit and receive channels. It might return with an error if one of them
fails, but the other one succeeded. In this case we need to call
dmaengine_pcm_release_chan() to free the requested channel.

> ---
>  sound/soc/soc-generic-dmaengine-pcm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
> index 768247f..32ea16d 100644
> --- a/sound/soc/soc-generic-dmaengine-pcm.c
> +++ b/sound/soc/soc-generic-dmaengine-pcm.c
> @@ -450,7 +450,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
>  
>  	ret = dmaengine_pcm_request_chan_of(pcm, dev, config);
>  	if (ret)
> -		goto err_free_dma;
> +		goto err_free_pcm;
>  
>  	ret = snd_soc_add_component(dev, &pcm->component,
>  				    &dmaengine_pcm_component, NULL, 0);
> @@ -461,6 +461,7 @@ int snd_dmaengine_pcm_register(struct device *dev,
>  
>  err_free_dma:
>  	dmaengine_pcm_release_chan(pcm);
> +err_free_pcm:
>  	kfree(pcm);
>  	return ret;
>  }
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling
  2018-02-26 14:25 ` [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Lars-Peter Clausen
@ 2018-02-26 14:35   ` Fabio Estevam
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2018-02-26 14:35 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Fabio Estevam, alsa-devel, Mark Brown

On Mon, Feb 26, 2018 at 11:25 AM, Lars-Peter Clausen <lars@metafoo.de> wrote:

> This creates a resource leak. dmaengine_pcm_request_chan_of() requests both
> transmit and receive channels. It might return with an error if one of them
> fails, but the other one succeeded. In this case we need to call
> dmaengine_pcm_release_chan() to free the requested channel.

Ok, I will send a revert.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-02-26 14:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-22 19:02 [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Fabio Estevam
2018-02-22 19:02 ` [PATCH 2/2] ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings Fabio Estevam
2018-02-26 11:17   ` Applied "ASoC: soc-generic-dmaengine-pcm: Fix sparse warnings" to the asoc tree Mark Brown
2018-02-26 11:17 ` Applied "ASoC: soc-generic-dmaengine-pcm: Fix error handling" " Mark Brown
2018-02-26 14:25 ` [PATCH 1/2] ASoC: soc-generic-dmaengine-pcm: Fix error handling Lars-Peter Clausen
2018-02-26 14:35   ` Fabio Estevam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.