Skip to contentSkip to conversation

ALSA: Fix remaining NULL device with memory allocations

PATCH In review Takashi Iwai 3 participants 9 messages Feb 4, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ALSA: Fix remaining NULL device with memory allocations

Hi,

this patchset covers the still remaining drivers calling the memory allocation with NULL device pointer. Simply card->dev is passed there.

Mark, two of them are trivial fixes for ASoC, and I'd like to merge them through my tree, since the last patch adds an explicit WARN_ON(). Give me Ack's if they are OK.

thanks,

Takashi

===

Takashi Iwai (5):
ALSA: x86: Avoid passing NULL to memory allocators
ALSA: arm: Avoid passing NULL to memory allocators
ASoC: amd: Avoid passing NULL to memory allocators
ASoC: sh: Avoid passing NULL to memory allocators
ALSA: core: Don't allow NULL device for memory allocation

 sound/arm/aaci.c                    | 3 ++-
 sound/core/memalloc.c               | 2 ++
 sound/soc/amd/raven/acp3x-pcm-dma.c | 3 ++-
 sound/soc/sh/siu_pcm.c              | 2 +-
 sound/x86/intel_hdmi_audio.c        | 3 ++-
 5 files changed, 9 insertions(+), 4 deletions(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/5 ALSA: x86: Avoid passing NULL to memory allocators

We should pass a proper non-NULL device object to memory allocators
although it was accepted in the past. The card->dev points to the most appropriate device object in such a case, so let's put it.

---
 sound/x86/intel_hdmi_audio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/x86/intel_hdmi_audio.c +2 -1
index 16ca91f57e7f..80f79ecffc71 100644
@@ -1812,7 +1812,8 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
 		 * try to allocate 600k buffer as default which is large enough
 		 */
 		snd_pcm_lib_preallocate_pages_for_all(pcm,
-						      SNDRV_DMA_TYPE_DEV_UC, NULL,
+						      SNDRV_DMA_TYPE_DEV_UC,
+						      card->dev,
 						      HAD_DEFAULT_BUFFER, HAD_MAX_BUFFER);
 
 		/* create controls */
Signature · 1 line
2.16.4
#2 lore raw

PATCH 2/5 ALSA: arm: Avoid passing NULL to memory allocators

In reply to Takashi Iwai

We should pass a proper non-NULL device object to memory allocators
although it was accepted in the past. The card->dev points to the most appropriate device object in such a case, so let's put it.

---
 sound/arm/aaci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/arm/aaci.c +2 -1
index 0c3f073e2600..a2d4b41096e0 100644
@@ -941,7 +941,8 @@ static int aaci_init_pcm(struct aaci *aaci)
 		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &aaci_playback_ops);
 		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &aaci_capture_ops);
 		snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
-						      NULL, 0, 64 * 1024);
+						      aaci->card->dev,
+						      0, 64 * 1024);
 	}
 
 	return ret;
Signature · 1 line
2.16.4
#3 lore raw

PATCH 3/5 ASoC: amd: Avoid passing NULL to memory allocators

In reply to Takashi Iwai

We should pass a proper non-NULL device object to memory allocators although it was accepted in the past. The card->dev points to the most appropriate device object in such a case, so let's put it.

---
 sound/soc/amd/raven/acp3x-pcm-dma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/amd/raven/acp3x-pcm-dma.c +2 -1
index 3d58338fa3cf..3e7d4099364c 100644
@@ -369,7 +369,8 @@ static int acp3x_dma_new(struct snd_soc_pcm_runtime *rtd)
 {
 	return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
 						     SNDRV_DMA_TYPE_DEV,
-						     NULL, MIN_BUFFER,
+						     rtd->pcm->card->dev,
+						     MIN_BUFFER,
 						     MAX_BUFFER);
 }
 
Signature · 1 line
2.16.4
maintainer Acked-by on v1 3/5
#4 lore raw

Re: [PATCH 3/5] ASoC: amd: Avoid passing NULL to memory allocators

Quoted 3 lines · Takashi Iwai

We should pass a proper non-NULL device object to memory allocators although it was accepted in the past. The card->dev points to the most appropriate device object in such a case, so let's put it.

#5 lore raw

PATCH 4/5 ASoC: sh: Avoid passing NULL to memory allocators

In reply to Takashi Iwai

We should pass a proper non-NULL device object to memory allocators
although it was accepted in the past. The card->dev points to the most appropriate device object in such a case, so let's put it.

---
 sound/soc/sh/siu_pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sh/siu_pcm.c +1 -1
index e263757e4a69..23384c477740 100644
@@ -542,7 +542,7 @@ static int siu_pcm_new(struct snd_soc_pcm_runtime *rtd)
 			return ret;
 
 		ret = snd_pcm_lib_preallocate_pages_for_all(pcm,
-				SNDRV_DMA_TYPE_DEV, NULL,
+				SNDRV_DMA_TYPE_DEV, card->dev,
 				SIU_BUFFER_BYTES_MAX, SIU_BUFFER_BYTES_MAX);
 		if (ret < 0) {
 			dev_err(card->dev,
Signature · 1 line
2.16.4
maintainer Acked-by on v1 4/5
#6 lore raw

Re: [PATCH 4/5] ASoC: sh: Avoid passing NULL to memory allocators

Quoted 3 lines · Takashi Iwai

We should pass a proper non-NULL device object to memory allocators
although it was accepted in the past. The card->dev points to the most appropriate device object in such a case, so let's put it.

#7 lore raw

PATCH 5/5 ALSA: core: Don't allow NULL device for memory allocation

In reply to Takashi Iwai

Since we covered all callers with NULL device pointer, let's catch the remaining calls with NULL and warn explicitly.

---
 sound/core/memalloc.c | 2 ++
 1 file changed, 2 insertions(+)
sound/core/memalloc.c +2 -0
index 59a4adc286ed..eb974235c92b 100644
@@ -182,6 +182,8 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
 		return -ENXIO;
 	if (WARN_ON(!dmab))
 		return -ENXIO;
+	if (WARN_ON(!device))
+		return -EINVAL;
 
 	dmab->dev.type = type;
 	dmab->dev.dev = device;
Signature · 1 line
2.16.4
Acked-by on the v1 series
#8 lore raw
In reply to Takashi Iwai
Quoted 10 lines · Takashi Iwai

Hi,

this patchset covers the still remaining drivers calling the memory allocation with NULL device pointer. Simply card->dev is passed there.

Mark, two of them are trivial fixes for ASoC, and I'd like to merge them through my tree, since the last patch adds an explicit WARN_ON(). Give me Ack's if they are OK.

Thanks a lot for doing this work!