Skip to content

Commit 2880e1a

Browse files
committed
Merge tag 'sound-6.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
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
2 parents 2555283 + 5f3d9e8 commit 2880e1a

File tree

7 files changed

+146
-34
lines changed

7 files changed

+146
-34
lines changed

sound/core/control.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ static bool elem_id_matches(const struct snd_kcontrol *kctl,
385385
#define MULTIPLIER 37
386386
static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id)
387387
{
388+
int i;
388389
unsigned long h;
389-
const unsigned char *p;
390390

391391
h = id->iface;
392392
h = MULTIPLIER * h + id->device;
393393
h = MULTIPLIER * h + id->subdevice;
394-
for (p = id->name; *p; p++)
395-
h = MULTIPLIER * h + *p;
394+
for (i = 0; i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN && id->name[i]; i++)
395+
h = MULTIPLIER * h + id->name[i];
396396
h = MULTIPLIER * h + id->index;
397397
h &= LONG_MAX;
398398
return h;

sound/core/memalloc.c

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

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

23+
#ifdef CONFIG_SND_DMA_SGBUF
24+
static void *do_alloc_fallback_pages(struct device *dev, size_t size,
25+
dma_addr_t *addr, bool wc);
26+
static void do_free_fallback_pages(void *p, size_t size, bool wc);
27+
static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size);
28+
#endif
29+
2330
/* a cast to gfp flag from the dev pointer; for CONTINUOUS and VMALLOC types */
2431
static inline gfp_t snd_mem_get_gfp_flags(const struct snd_dma_buffer *dmab,
2532
gfp_t default_gfp)
@@ -277,16 +284,21 @@ EXPORT_SYMBOL(snd_sgbuf_get_chunk_size);
277284
/*
278285
* Continuous pages allocator
279286
*/
280-
static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size)
287+
static void *do_alloc_pages(size_t size, dma_addr_t *addr, gfp_t gfp)
281288
{
282-
gfp_t gfp = snd_mem_get_gfp_flags(dmab, GFP_KERNEL);
283289
void *p = alloc_pages_exact(size, gfp);
284290

285291
if (p)
286-
dmab->addr = page_to_phys(virt_to_page(p));
292+
*addr = page_to_phys(virt_to_page(p));
287293
return p;
288294
}
289295

296+
static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size)
297+
{
298+
return do_alloc_pages(size, &dmab->addr,
299+
snd_mem_get_gfp_flags(dmab, GFP_KERNEL));
300+
}
301+
290302
static void snd_dma_continuous_free(struct snd_dma_buffer *dmab)
291303
{
292304
free_pages_exact(dmab->area, dmab->bytes);
@@ -463,6 +475,25 @@ static const struct snd_malloc_ops snd_dma_dev_ops = {
463475
/*
464476
* Write-combined pages
465477
*/
478+
/* x86-specific allocations */
479+
#ifdef CONFIG_SND_DMA_SGBUF
480+
static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size)
481+
{
482+
return do_alloc_fallback_pages(dmab->dev.dev, size, &dmab->addr, true);
483+
}
484+
485+
static void snd_dma_wc_free(struct snd_dma_buffer *dmab)
486+
{
487+
do_free_fallback_pages(dmab->area, dmab->bytes, true);
488+
}
489+
490+
static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab,
491+
struct vm_area_struct *area)
492+
{
493+
area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
494+
return snd_dma_continuous_mmap(dmab, area);
495+
}
496+
#else
466497
static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size)
467498
{
468499
return dma_alloc_wc(dmab->dev.dev, size, &dmab->addr, DEFAULT_GFP);
@@ -479,17 +510,14 @@ static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab,
479510
return dma_mmap_wc(dmab->dev.dev, area,
480511
dmab->area, dmab->addr, dmab->bytes);
481512
}
513+
#endif /* CONFIG_SND_DMA_SGBUF */
482514

483515
static const struct snd_malloc_ops snd_dma_wc_ops = {
484516
.alloc = snd_dma_wc_alloc,
485517
.free = snd_dma_wc_free,
486518
.mmap = snd_dma_wc_mmap,
487519
};
488520

489-
#ifdef CONFIG_SND_DMA_SGBUF
490-
static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size);
491-
#endif
492-
493521
/*
494522
* Non-contiguous pages allocator
495523
*/
@@ -669,6 +697,37 @@ static const struct snd_malloc_ops snd_dma_sg_wc_ops = {
669697
.get_chunk_size = snd_dma_noncontig_get_chunk_size,
670698
};
671699

700+
/* manual page allocations with wc setup */
701+
static void *do_alloc_fallback_pages(struct device *dev, size_t size,
702+
dma_addr_t *addr, bool wc)
703+
{
704+
gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
705+
void *p;
706+
707+
again:
708+
p = do_alloc_pages(size, addr, gfp);
709+
if (!p || (*addr + size - 1) & ~dev->coherent_dma_mask) {
710+
if (IS_ENABLED(CONFIG_ZONE_DMA32) && !(gfp & GFP_DMA32)) {
711+
gfp |= GFP_DMA32;
712+
goto again;
713+
}
714+
if (IS_ENABLED(CONFIG_ZONE_DMA) && !(gfp & GFP_DMA)) {
715+
gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
716+
goto again;
717+
}
718+
}
719+
if (p && wc)
720+
set_memory_wc((unsigned long)(p), size >> PAGE_SHIFT);
721+
return p;
722+
}
723+
724+
static void do_free_fallback_pages(void *p, size_t size, bool wc)
725+
{
726+
if (wc)
727+
set_memory_wb((unsigned long)(p), size >> PAGE_SHIFT);
728+
free_pages_exact(p, size);
729+
}
730+
672731
/* Fallback SG-buffer allocations for x86 */
673732
struct snd_dma_sg_fallback {
674733
size_t count;
@@ -679,14 +738,11 @@ struct snd_dma_sg_fallback {
679738
static void __snd_dma_sg_fallback_free(struct snd_dma_buffer *dmab,
680739
struct snd_dma_sg_fallback *sgbuf)
681740
{
741+
bool wc = dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK;
682742
size_t i;
683743

684-
if (sgbuf->count && dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK)
685-
set_pages_array_wb(sgbuf->pages, sgbuf->count);
686744
for (i = 0; i < sgbuf->count && sgbuf->pages[i]; i++)
687-
dma_free_coherent(dmab->dev.dev, PAGE_SIZE,
688-
page_address(sgbuf->pages[i]),
689-
sgbuf->addrs[i]);
745+
do_free_fallback_pages(page_address(sgbuf->pages[i]), PAGE_SIZE, wc);
690746
kvfree(sgbuf->pages);
691747
kvfree(sgbuf->addrs);
692748
kfree(sgbuf);
@@ -698,6 +754,7 @@ static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size)
698754
struct page **pages;
699755
size_t i, count;
700756
void *p;
757+
bool wc = dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK;
701758

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

714771
for (i = 0; i < count; sgbuf->count++, i++) {
715-
p = dma_alloc_coherent(dmab->dev.dev, PAGE_SIZE,
716-
&sgbuf->addrs[i], DEFAULT_GFP);
772+
p = do_alloc_fallback_pages(dmab->dev.dev, PAGE_SIZE,
773+
&sgbuf->addrs[i], wc);
717774
if (!p)
718775
goto error;
719776
sgbuf->pages[i] = virt_to_page(p);
720777
}
721778

722-
if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK)
723-
set_pages_array_wc(pages, count);
724779
p = vmap(pages, count, VM_MAP, PAGE_KERNEL);
725780
if (!p)
726781
goto error;

sound/core/seq/oss/seq_oss_midi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ snd_seq_oss_midi_clear_all(void)
270270
void
271271
snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp)
272272
{
273+
spin_lock_irq(&register_lock);
273274
dp->max_mididev = max_midi_devs;
275+
spin_unlock_irq(&register_lock);
274276
}
275277

276278
/*

sound/core/seq/seq_clientmgr.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
121121
spin_unlock_irqrestore(&clients_lock, flags);
122122
#ifdef CONFIG_MODULES
123123
if (!in_interrupt()) {
124-
static char client_requested[SNDRV_SEQ_GLOBAL_CLIENTS];
125-
static char card_requested[SNDRV_CARDS];
124+
static DECLARE_BITMAP(client_requested, SNDRV_SEQ_GLOBAL_CLIENTS);
125+
static DECLARE_BITMAP(card_requested, SNDRV_CARDS);
126+
126127
if (clientid < SNDRV_SEQ_GLOBAL_CLIENTS) {
127128
int idx;
128129

129-
if (!client_requested[clientid]) {
130-
client_requested[clientid] = 1;
130+
if (!test_and_set_bit(clientid, client_requested)) {
131131
for (idx = 0; idx < 15; idx++) {
132132
if (seq_client_load[idx] < 0)
133133
break;
@@ -142,10 +142,8 @@ struct snd_seq_client *snd_seq_client_use_ptr(int clientid)
142142
int card = (clientid - SNDRV_SEQ_GLOBAL_CLIENTS) /
143143
SNDRV_SEQ_CLIENTS_PER_CARD;
144144
if (card < snd_ecards_limit) {
145-
if (! card_requested[card]) {
146-
card_requested[card] = 1;
145+
if (!test_and_set_bit(card, card_requested))
147146
snd_request_card(card);
148-
}
149147
snd_seq_device_load_drivers();
150148
}
151149
}

sound/hda/intel-nhlt.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,22 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
5555

5656
/* find max number of channels based on format_configuration */
5757
if (fmt_configs->fmt_count) {
58+
struct nhlt_fmt_cfg *fmt_cfg = fmt_configs->fmt_config;
59+
5860
dev_dbg(dev, "found %d format definitions\n",
5961
fmt_configs->fmt_count);
6062

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

64-
fmt_ext = &fmt_configs->fmt_config[i].fmt_ext;
66+
fmt_ext = &fmt_cfg->fmt_ext;
6567

6668
if (fmt_ext->fmt.channels > max_ch)
6769
max_ch = fmt_ext->fmt.channels;
70+
71+
/* Move to the next nhlt_fmt_cfg */
72+
fmt_cfg = (struct nhlt_fmt_cfg *)(fmt_cfg->config.caps +
73+
fmt_cfg->config.size);
6874
}
6975
dev_dbg(dev, "max channels found %d\n", max_ch);
7076
} else {

sound/pci/hda/patch_realtek.c

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4700,6 +4700,48 @@ static void alc236_fixup_hp_mute_led_micmute_vref(struct hda_codec *codec,
47004700
alc236_fixup_hp_micmute_led_vref(codec, fix, action);
47014701
}
47024702

4703+
static inline void alc298_samsung_write_coef_pack(struct hda_codec *codec,
4704+
const unsigned short coefs[2])
4705+
{
4706+
alc_write_coef_idx(codec, 0x23, coefs[0]);
4707+
alc_write_coef_idx(codec, 0x25, coefs[1]);
4708+
alc_write_coef_idx(codec, 0x26, 0xb011);
4709+
}
4710+
4711+
struct alc298_samsung_amp_desc {
4712+
unsigned char nid;
4713+
unsigned short init_seq[2][2];
4714+
};
4715+
4716+
static void alc298_fixup_samsung_amp(struct hda_codec *codec,
4717+
const struct hda_fixup *fix, int action)
4718+
{
4719+
int i, j;
4720+
static const unsigned short init_seq[][2] = {
4721+
{ 0x19, 0x00 }, { 0x20, 0xc0 }, { 0x22, 0x44 }, { 0x23, 0x08 },
4722+
{ 0x24, 0x85 }, { 0x25, 0x41 }, { 0x35, 0x40 }, { 0x36, 0x01 },
4723+
{ 0x38, 0x81 }, { 0x3a, 0x03 }, { 0x3b, 0x81 }, { 0x40, 0x3e },
4724+
{ 0x41, 0x07 }, { 0x400, 0x1 }
4725+
};
4726+
static const struct alc298_samsung_amp_desc amps[] = {
4727+
{ 0x3a, { { 0x18, 0x1 }, { 0x26, 0x0 } } },
4728+
{ 0x39, { { 0x18, 0x2 }, { 0x26, 0x1 } } }
4729+
};
4730+
4731+
if (action != HDA_FIXUP_ACT_INIT)
4732+
return;
4733+
4734+
for (i = 0; i < ARRAY_SIZE(amps); i++) {
4735+
alc_write_coef_idx(codec, 0x22, amps[i].nid);
4736+
4737+
for (j = 0; j < ARRAY_SIZE(amps[i].init_seq); j++)
4738+
alc298_samsung_write_coef_pack(codec, amps[i].init_seq[j]);
4739+
4740+
for (j = 0; j < ARRAY_SIZE(init_seq); j++)
4741+
alc298_samsung_write_coef_pack(codec, init_seq[j]);
4742+
}
4743+
}
4744+
47034745
#if IS_REACHABLE(CONFIG_INPUT)
47044746
static void gpio2_mic_hotkey_event(struct hda_codec *codec,
47054747
struct hda_jack_callback *event)
@@ -7030,6 +7072,7 @@ enum {
70307072
ALC236_FIXUP_HP_GPIO_LED,
70317073
ALC236_FIXUP_HP_MUTE_LED,
70327074
ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF,
7075+
ALC298_FIXUP_SAMSUNG_AMP,
70337076
ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET,
70347077
ALC256_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET,
70357078
ALC295_FIXUP_ASUS_MIC_NO_PRESENCE,
@@ -8396,6 +8439,12 @@ static const struct hda_fixup alc269_fixups[] = {
83968439
.type = HDA_FIXUP_FUNC,
83978440
.v.func = alc236_fixup_hp_mute_led_micmute_vref,
83988441
},
8442+
[ALC298_FIXUP_SAMSUNG_AMP] = {
8443+
.type = HDA_FIXUP_FUNC,
8444+
.v.func = alc298_fixup_samsung_amp,
8445+
.chained = true,
8446+
.chain_id = ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET
8447+
},
83998448
[ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET] = {
84008449
.type = HDA_FIXUP_VERBS,
84018450
.v.verbs = (const struct hda_verb[]) {
@@ -9342,13 +9391,13 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
93429391
SND_PCI_QUIRK(0x10ec, 0x1254, "Intel Reference board", ALC295_FIXUP_CHROME_BOOK),
93439392
SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-SZ6", ALC269_FIXUP_HEADSET_MODE),
93449393
SND_PCI_QUIRK(0x144d, 0xc109, "Samsung Ativ book 9 (NP900X3G)", ALC269_FIXUP_INV_DMIC),
9345-
SND_PCI_QUIRK(0x144d, 0xc169, "Samsung Notebook 9 Pen (NP930SBE-K01US)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
9346-
SND_PCI_QUIRK(0x144d, 0xc176, "Samsung Notebook 9 Pro (NP930MBE-K04US)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
9347-
SND_PCI_QUIRK(0x144d, 0xc189, "Samsung Galaxy Flex Book (NT950QCG-X716)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
9348-
SND_PCI_QUIRK(0x144d, 0xc18a, "Samsung Galaxy Book Ion (NP930XCJ-K01US)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
9394+
SND_PCI_QUIRK(0x144d, 0xc169, "Samsung Notebook 9 Pen (NP930SBE-K01US)", ALC298_FIXUP_SAMSUNG_AMP),
9395+
SND_PCI_QUIRK(0x144d, 0xc176, "Samsung Notebook 9 Pro (NP930MBE-K04US)", ALC298_FIXUP_SAMSUNG_AMP),
9396+
SND_PCI_QUIRK(0x144d, 0xc189, "Samsung Galaxy Flex Book (NT950QCG-X716)", ALC298_FIXUP_SAMSUNG_AMP),
9397+
SND_PCI_QUIRK(0x144d, 0xc18a, "Samsung Galaxy Book Ion (NP930XCJ-K01US)", ALC298_FIXUP_SAMSUNG_AMP),
93499398
SND_PCI_QUIRK(0x144d, 0xc740, "Samsung Ativ book 8 (NP870Z5G)", ALC269_FIXUP_ATIV_BOOK_8),
9350-
SND_PCI_QUIRK(0x144d, 0xc812, "Samsung Notebook Pen S (NT950SBE-X58)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
9351-
SND_PCI_QUIRK(0x144d, 0xc830, "Samsung Galaxy Book Ion (NT950XCJ-X716A)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
9399+
SND_PCI_QUIRK(0x144d, 0xc812, "Samsung Notebook Pen S (NT950SBE-X58)", ALC298_FIXUP_SAMSUNG_AMP),
9400+
SND_PCI_QUIRK(0x144d, 0xc830, "Samsung Galaxy Book Ion (NT950XCJ-X716A)", ALC298_FIXUP_SAMSUNG_AMP),
93529401
SND_PCI_QUIRK(0x144d, 0xc832, "Samsung Galaxy Book Flex Alpha (NP730QCJ)", ALC256_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
93539402
SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_HEADSET_MIC),
93549403
SND_PCI_QUIRK(0x1462, 0xb120, "MSI Cubi MS-B120", ALC283_FIXUP_HEADSET_MIC),
@@ -9716,7 +9765,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
97169765
{.id = ALC299_FIXUP_PREDATOR_SPK, .name = "predator-spk"},
97179766
{.id = ALC298_FIXUP_HUAWEI_MBX_STEREO, .name = "huawei-mbx-stereo"},
97189767
{.id = ALC256_FIXUP_MEDION_HEADSET_NO_PRESENCE, .name = "alc256-medion-headset"},
9719-
{.id = ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET, .name = "alc298-samsung-headphone"},
9768+
{.id = ALC298_FIXUP_SAMSUNG_AMP, .name = "alc298-samsung-amp"},
97209769
{.id = ALC256_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET, .name = "alc256-samsung-headphone"},
97219770
{.id = ALC255_FIXUP_XIAOMI_HEADSET_MIC, .name = "alc255-xiaomi-headset"},
97229771
{.id = ALC274_FIXUP_HP_MIC, .name = "alc274-hp-mic-detect"},

sound/usb/quirks.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
19031903
QUIRK_FLAG_SHARE_MEDIA_DEVICE | QUIRK_FLAG_ALIGN_TRANSFER),
19041904
DEVICE_FLG(0x21b4, 0x0081, /* AudioQuest DragonFly */
19051905
QUIRK_FLAG_GET_SAMPLE_RATE),
1906+
DEVICE_FLG(0x2522, 0x0007, /* LH Labs Geek Out HD Audio 1V5 */
1907+
QUIRK_FLAG_SET_IFACE_FIRST),
19061908
DEVICE_FLG(0x2708, 0x0002, /* Audient iD14 */
19071909
QUIRK_FLAG_IGNORE_CTL_ERROR),
19081910
DEVICE_FLG(0x2912, 0x30c8, /* Audioengine D1 */

0 commit comments

Comments
 (0)