Commit 2880e1a1 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull sound fixes from Takashi Iwai:
 "Just handful changes at this time. The only major change is the
  regression fix about the x86 WC-page buffer allocation.

  The rest are trivial data-race fixes for ALSA sequencer core, the
  possible out-of-bounds access fixes in the new ALSA control hash code,
  and a few device-specific workarounds and fixes"

* tag 'sound-6.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound:
  ALSA: usb-audio: Add quirk for LH Labs Geek Out HD Audio 1V5
  ALSA: hda/realtek: Add speaker AMP init for Samsung laptops with ALC298
  ALSA: control: Re-order bounds checking in get_ctl_id_hash()
  ALSA: control: Fix an out-of-bounds bug in get_ctl_id_hash()
  ALSA: hda: intel-nhlt: Correct the handling of fmt_config flexible array
  ALSA: seq: Fix data-race at module auto-loading
  ALSA: seq: oss: Fix data-race for max_midi_devs access
  ALSA: memalloc: Revive x86-specific WC page allocations again
parents 2555283e 5f3d9e81
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -385,14 +385,14 @@ static bool elem_id_matches(const struct snd_kcontrol *kctl,
#define MULTIPLIER	37
static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id)
{
	int i;
	unsigned long h;
	const unsigned char *p;

	h = id->iface;
	h = MULTIPLIER * h + id->device;
	h = MULTIPLIER * h + id->subdevice;
	for (p = id->name; *p; p++)
		h = MULTIPLIER * h + *p;
	for (i = 0; i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN && id->name[i]; i++)
		h = MULTIPLIER * h + id->name[i];
	h = MULTIPLIER * h + id->index;
	h &= LONG_MAX;
	return h;
+71 −16
Original line number Diff line number Diff line
@@ -20,6 +20,13 @@

static const struct snd_malloc_ops *snd_dma_get_ops(struct snd_dma_buffer *dmab);

#ifdef CONFIG_SND_DMA_SGBUF
static void *do_alloc_fallback_pages(struct device *dev, size_t size,
				     dma_addr_t *addr, bool wc);
static void do_free_fallback_pages(void *p, size_t size, bool wc);
static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size);
#endif

/* a cast to gfp flag from the dev pointer; for CONTINUOUS and VMALLOC types */
static inline gfp_t snd_mem_get_gfp_flags(const struct snd_dma_buffer *dmab,
					  gfp_t default_gfp)
@@ -277,16 +284,21 @@ EXPORT_SYMBOL(snd_sgbuf_get_chunk_size);
/*
 * Continuous pages allocator
 */
static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size)
static void *do_alloc_pages(size_t size, dma_addr_t *addr, gfp_t gfp)
{
	gfp_t gfp = snd_mem_get_gfp_flags(dmab, GFP_KERNEL);
	void *p = alloc_pages_exact(size, gfp);

	if (p)
		dmab->addr = page_to_phys(virt_to_page(p));
		*addr = page_to_phys(virt_to_page(p));
	return p;
}

static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size)
{
	return do_alloc_pages(size, &dmab->addr,
			      snd_mem_get_gfp_flags(dmab, GFP_KERNEL));
}

static void snd_dma_continuous_free(struct snd_dma_buffer *dmab)
{
	free_pages_exact(dmab->area, dmab->bytes);
@@ -463,6 +475,25 @@ static const struct snd_malloc_ops snd_dma_dev_ops = {
/*
 * Write-combined pages
 */
/* x86-specific allocations */
#ifdef CONFIG_SND_DMA_SGBUF
static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size)
{
	return do_alloc_fallback_pages(dmab->dev.dev, size, &dmab->addr, true);
}

static void snd_dma_wc_free(struct snd_dma_buffer *dmab)
{
	do_free_fallback_pages(dmab->area, dmab->bytes, true);
}

static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab,
			   struct vm_area_struct *area)
{
	area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
	return snd_dma_continuous_mmap(dmab, area);
}
#else
static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size)
{
	return dma_alloc_wc(dmab->dev.dev, size, &dmab->addr, DEFAULT_GFP);
@@ -479,6 +510,7 @@ static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab,
	return dma_mmap_wc(dmab->dev.dev, area,
			   dmab->area, dmab->addr, dmab->bytes);
}
#endif /* CONFIG_SND_DMA_SGBUF */

static const struct snd_malloc_ops snd_dma_wc_ops = {
	.alloc = snd_dma_wc_alloc,
@@ -486,10 +518,6 @@ static const struct snd_malloc_ops snd_dma_wc_ops = {
	.mmap = snd_dma_wc_mmap,
};

#ifdef CONFIG_SND_DMA_SGBUF
static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size);
#endif

/*
 * Non-contiguous pages allocator
 */
@@ -669,6 +697,37 @@ static const struct snd_malloc_ops snd_dma_sg_wc_ops = {
	.get_chunk_size = snd_dma_noncontig_get_chunk_size,
};

/* manual page allocations with wc setup */
static void *do_alloc_fallback_pages(struct device *dev, size_t size,
				     dma_addr_t *addr, bool wc)
{
	gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
	void *p;

 again:
	p = do_alloc_pages(size, addr, gfp);
	if (!p || (*addr + size - 1) & ~dev->coherent_dma_mask) {
		if (IS_ENABLED(CONFIG_ZONE_DMA32) && !(gfp & GFP_DMA32)) {
			gfp |= GFP_DMA32;
			goto again;
		}
		if (IS_ENABLED(CONFIG_ZONE_DMA) && !(gfp & GFP_DMA)) {
			gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
			goto again;
		}
	}
	if (p && wc)
		set_memory_wc((unsigned long)(p), size >> PAGE_SHIFT);
	return p;
}

static void do_free_fallback_pages(void *p, size_t size, bool wc)
{
	if (wc)
		set_memory_wb((unsigned long)(p), size >> PAGE_SHIFT);
	free_pages_exact(p, size);
}

/* Fallback SG-buffer allocations for x86 */
struct snd_dma_sg_fallback {
	size_t count;
@@ -679,14 +738,11 @@ struct snd_dma_sg_fallback {
static void __snd_dma_sg_fallback_free(struct snd_dma_buffer *dmab,
				       struct snd_dma_sg_fallback *sgbuf)
{
	bool wc = dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK;
	size_t i;

	if (sgbuf->count && dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK)
		set_pages_array_wb(sgbuf->pages, sgbuf->count);
	for (i = 0; i < sgbuf->count && sgbuf->pages[i]; i++)
		dma_free_coherent(dmab->dev.dev, PAGE_SIZE,
				  page_address(sgbuf->pages[i]),
				  sgbuf->addrs[i]);
		do_free_fallback_pages(page_address(sgbuf->pages[i]), PAGE_SIZE, wc);
	kvfree(sgbuf->pages);
	kvfree(sgbuf->addrs);
	kfree(sgbuf);
@@ -698,6 +754,7 @@ static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size)
	struct page **pages;
	size_t i, count;
	void *p;
	bool wc = dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK;

	sgbuf = kzalloc(sizeof(*sgbuf), GFP_KERNEL);
	if (!sgbuf)
@@ -712,15 +769,13 @@ static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size)
		goto error;

	for (i = 0; i < count; sgbuf->count++, i++) {
		p = dma_alloc_coherent(dmab->dev.dev, PAGE_SIZE,
				       &sgbuf->addrs[i], DEFAULT_GFP);
		p = do_alloc_fallback_pages(dmab->dev.dev, PAGE_SIZE,
					    &sgbuf->addrs[i], wc);
		if (!p)
			goto error;
		sgbuf->pages[i] = virt_to_page(p);
	}

	if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK)
		set_pages_array_wc(pages, count);
	p = vmap(pages, count, VM_MAP, PAGE_KERNEL);
	if (!p)
		goto error;
+2 −0
Original line number Diff line number Diff line
@@ -270,7 +270,9 @@ snd_seq_oss_midi_clear_all(void)
void
snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp)
{
	spin_lock_irq(&register_lock);
	dp->max_mididev = max_midi_devs;
	spin_unlock_irq(&register_lock);
}

/*
+5 −7
Original line number Diff line number Diff line
@@ -121,13 +121,13 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
	spin_unlock_irqrestore(&clients_lock, flags);
#ifdef CONFIG_MODULES
	if (!in_interrupt()) {
		static char client_requested[SNDRV_SEQ_GLOBAL_CLIENTS];
		static char card_requested[SNDRV_CARDS];
		static DECLARE_BITMAP(client_requested, SNDRV_SEQ_GLOBAL_CLIENTS);
		static DECLARE_BITMAP(card_requested, SNDRV_CARDS);

		if (clientid < SNDRV_SEQ_GLOBAL_CLIENTS) {
			int idx;
			
			if (!client_requested[clientid]) {
				client_requested[clientid] = 1;
			if (!test_and_set_bit(clientid, client_requested)) {
				for (idx = 0; idx < 15; idx++) {
					if (seq_client_load[idx] < 0)
						break;
@@ -142,10 +142,8 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
			int card = (clientid - SNDRV_SEQ_GLOBAL_CLIENTS) /
				SNDRV_SEQ_CLIENTS_PER_CARD;
			if (card < snd_ecards_limit) {
				if (! card_requested[card]) {
					card_requested[card] = 1;
				if (!test_and_set_bit(card, card_requested))
					snd_request_card(card);
				}
				snd_seq_device_load_drivers();
			}
		}
+7 −1
Original line number Diff line number Diff line
@@ -55,16 +55,22 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)

		/* find max number of channels based on format_configuration */
		if (fmt_configs->fmt_count) {
			struct nhlt_fmt_cfg *fmt_cfg = fmt_configs->fmt_config;

			dev_dbg(dev, "found %d format definitions\n",
				fmt_configs->fmt_count);

			for (i = 0; i < fmt_configs->fmt_count; i++) {
				struct wav_fmt_ext *fmt_ext;

				fmt_ext = &fmt_configs->fmt_config[i].fmt_ext;
				fmt_ext = &fmt_cfg->fmt_ext;

				if (fmt_ext->fmt.channels > max_ch)
					max_ch = fmt_ext->fmt.channels;

				/* Move to the next nhlt_fmt_cfg */
				fmt_cfg = (struct nhlt_fmt_cfg *)(fmt_cfg->config.caps +
								  fmt_cfg->config.size);
			}
			dev_dbg(dev, "max channels found %d\n", max_ch);
		} else {
Loading