ALSA: memalloc: Try dma_alloc_noncontiguous() at first

The latest fix for the non-contiguous memalloc helper changed the
allocation method for a non-IOMMU system to use only the fallback
allocator. This should have worked, but it caused a problem sometimes
when too many non-contiguous pages are allocated that can't be treated
by HD-audio controller.

As a quirk workaround, go back to the original strategy: use
dma_alloc_noncontiguous() at first, and apply the fallback only when
it fails, but only for non-IOMMU case.

We'll need a better fix in the fallback code as well, but this
workaround should paper over most cases.

Fixes: 9736a325137b ("ALSA: memalloc: Don't fall back for SG-buffer with IOMMU")
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/CAHk-=wgSH5ubdvt76gNwa004ooZAEJL_1Q-Fyw5M2FDdqL==dg@mail.gmail.com
Link: https://lore.kernel.org/r/20221112084718.3305-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

Changed files
+3 -4
sound
core
+3 -4
sound/core/memalloc.c
··· 542 542 struct sg_table *sgt; 543 543 void *p; 544 544 545 + sgt = dma_alloc_noncontiguous(dmab->dev.dev, size, dmab->dev.dir, 546 + DEFAULT_GFP, 0); 545 547 #ifdef CONFIG_SND_DMA_SGBUF 546 - if (!get_dma_ops(dmab->dev.dev)) { 548 + if (!sgt && !get_dma_ops(dmab->dev.dev)) { 547 549 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG) 548 550 dmab->dev.type = SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK; 549 551 else ··· 553 551 return snd_dma_sg_fallback_alloc(dmab, size); 554 552 } 555 553 #endif 556 - 557 - sgt = dma_alloc_noncontiguous(dmab->dev.dev, size, dmab->dev.dir, 558 - DEFAULT_GFP, 0); 559 554 if (!sgt) 560 555 return NULL; 561 556