From afcfbcb39fe539ff9a24ca9187bb49e09a14abe5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:12 +0100 Subject: ALSA: core: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-1-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/core/control.c | 4 ++-- sound/core/seq/seq_memory.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sound') diff --git a/sound/core/control.c b/sound/core/control.c index 3b44378b9dec..1571c7f7c43b 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -836,7 +836,7 @@ static void fill_remaining_elem_value(struct snd_ctl_elem_value *control, { size_t offset = value_sizes[info->type] * info->count; - offset = (offset + sizeof(u32) - 1) / sizeof(u32); + offset = DIV_ROUND_UP(offset, sizeof(u32)); memset32((u32 *)control->value.bytes.data + offset, pattern, sizeof(control->value) / sizeof(u32) - offset); } @@ -928,7 +928,7 @@ static int sanity_check_elem_value(struct snd_card *card, /* check whether the remaining area kept untouched */ offset = value_sizes[info->type] * info->count; - offset = (offset + sizeof(u32) - 1) / sizeof(u32); + offset = DIV_ROUND_UP(offset, sizeof(u32)); p = (u32 *)control->value.bytes.data + offset; for (; offset < sizeof(control->value) / sizeof(u32); offset++, p++) { if (*p != pattern) { diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c index 65db1a7c77b7..e245bb6ba533 100644 --- a/sound/core/seq/seq_memory.c +++ b/sound/core/seq/seq_memory.c @@ -290,7 +290,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, extlen = 0; if (snd_seq_ev_is_variable(event)) { extlen = event->data.ext.len & ~SNDRV_SEQ_EXT_MASK; - ncells = (extlen + sizeof(struct snd_seq_event) - 1) / sizeof(struct snd_seq_event); + ncells = DIV_ROUND_UP(extlen, sizeof(struct snd_seq_event)); } if (ncells >= pool->total_elements) return -ENOMEM; -- cgit v1.2.3 From 7ef74bdc0d974bed3e2d3fdd806e4d30796833d0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:13 +0100 Subject: ALSA: aloop: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-2-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/drivers/aloop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index 702f91b9c60f..8a24e5ae7cef 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c @@ -219,7 +219,7 @@ static int loopback_jiffies_timer_start(struct loopback_pcm *dpcm) dpcm->period_update_pending = 1; } tick = dpcm->period_size_frac - dpcm->irq_pos; - tick = (tick + dpcm->pcm_bps - 1) / dpcm->pcm_bps; + tick = DIV_ROUND_UP(tick, dpcm->pcm_bps); mod_timer(&dpcm->timer, jiffies + tick); return 0; -- cgit v1.2.3 From af787b2e837fb6003886c151f8cea0484fcd381d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:14 +0100 Subject: ALSA: asihpi: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-3-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/asihpi/hpidebug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/asihpi/hpidebug.c b/sound/pci/asihpi/hpidebug.c index f37856ab05f8..9570d9a44fe8 100644 --- a/sound/pci/asihpi/hpidebug.c +++ b/sound/pci/asihpi/hpidebug.c @@ -52,7 +52,7 @@ void hpi_debug_data(u16 *pdata, u32 len) int lines; int cols = 8; - lines = (len + cols - 1) / cols; + lines = DIV_ROUND_UP(len, cols); if (lines > 8) lines = 8; -- cgit v1.2.3 From e02e198e88f4c3bd9a56b031d46895a191919c4e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:15 +0100 Subject: ALSA: bt87x: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @r1@ expression x; constant C1; constant C2; @@ (x + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ try: if int(C1) != int(C2) - 1: cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_UP(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-4-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/bt87x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c index 54cb223caa2f..cf9f8d80a0b6 100644 --- a/sound/pci/bt87x.c +++ b/sound/pci/bt87x.c @@ -327,7 +327,8 @@ static irqreturn_t snd_bt87x_interrupt(int irq, void *dev_id) current_block = chip->current_line * 16 / chip->lines; irq_block = status >> INT_RISCS_SHIFT; if (current_block != irq_block) - chip->current_line = (irq_block * chip->lines + 15) / 16; + chip->current_line = DIV_ROUND_UP(irq_block * chip->lines, + 16); snd_pcm_period_elapsed(chip->substream); } -- cgit v1.2.3 From 636c46c51cfcb82859be3e4a903ebe5b790e1ac0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:16 +0100 Subject: ALSA: cx46xx: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-5-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/cs46xx/cs46xx_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c index 4490dd7469d9..37f516e6a5c2 100644 --- a/sound/pci/cs46xx/cs46xx_lib.c +++ b/sound/pci/cs46xx/cs46xx_lib.c @@ -813,7 +813,7 @@ static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned correctionPerGOF = tmp1 / GOF_PER_SEC; tmp1 -= correctionPerGOF * GOF_PER_SEC; correctionPerSec = tmp1; - initialDelay = ((48000 * 24) + rate - 1) / rate; + initialDelay = DIV_ROUND_UP(48000 * 24, rate); /* * Fill in the VariDecimate control block. -- cgit v1.2.3 From 7ca4282ade77de53b6e9ffa2695566e5d35dab1e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:17 +0100 Subject: ALSA: ctxfi: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-6-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/ctxfi/ctresource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/ctxfi/ctresource.c b/sound/pci/ctxfi/ctresource.c index 61e51e35ba16..6d0a01b189e1 100644 --- a/sound/pci/ctxfi/ctresource.c +++ b/sound/pci/ctxfi/ctresource.c @@ -209,7 +209,7 @@ int rsc_mgr_init(struct rsc_mgr *mgr, enum RSCTYP type, mgr->type = NUM_RSCTYP; - mgr->rscs = kzalloc(((amount + 8 - 1) / 8), GFP_KERNEL); + mgr->rscs = kzalloc(DIV_ROUND_UP(amount, 8), GFP_KERNEL); if (!mgr->rscs) return -ENOMEM; -- cgit v1.2.3 From 7095be6d2cc2870299c9e6c6c2df3148be410c4a Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:18 +0100 Subject: ALSA: dummy: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-7-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/drivers/dummy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index b5486de08b97..316c9afadefe 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -236,7 +236,7 @@ struct dummy_systimer_pcm { static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm) { mod_timer(&dpcm->timer, jiffies + - (dpcm->frac_period_rest + dpcm->rate - 1) / dpcm->rate); + DIV_ROUND_UP(dpcm->frac_period_rest, dpcm->rate)); } static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm) -- cgit v1.2.3 From 483548a26f1aa65caf16eb99413e5003b3cfc81b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:19 +0100 Subject: ALSA: emu10k1: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-8-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/emu10k1/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c index 94b8d5b08225..288e0fd2e47d 100644 --- a/sound/pci/emu10k1/memory.c +++ b/sound/pci/emu10k1/memory.c @@ -375,7 +375,7 @@ int snd_emu10k1_alloc_pages_maybe_wider(struct snd_emu10k1 *emu, size_t size, struct snd_dma_buffer *dmab) { if (emu->iommu_workaround) { - size_t npages = (size + PAGE_SIZE - 1) / PAGE_SIZE; + size_t npages = DIV_ROUND_UP(size, PAGE_SIZE); size_t size_real = npages * PAGE_SIZE; /* -- cgit v1.2.3 From 81d0ec4349ec53e990e018ad0ce553046aab0fa3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:20 +0100 Subject: ALSA: hda: Use DIV_ROUND_UP()/roundup() instead of open-coding it Use DIV_ROUND_UP() and roundup() instead of open-coding them. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -((((x) + (y) - 1) / (y)) * y) +roundup(x, y) @r1@ expression x; constant C1; constant C2; @@ (x + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ print C1, C2 try: if int(C1) != int(C2) - 1: cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_UP(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-9-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/hda/hdac_stream.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sound') diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c index abe7a1b16fe1..a6ed3dc35f7e 100644 --- a/sound/hda/hdac_stream.c +++ b/sound/hda/hdac_stream.c @@ -435,12 +435,11 @@ int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev) pos_adj = bus->bdl_pos_adj; if (!azx_dev->no_period_wakeup && pos_adj > 0) { pos_align = pos_adj; - pos_adj = (pos_adj * runtime->rate + 47999) / 48000; + pos_adj = DIV_ROUND_UP(pos_adj * runtime->rate, 48000); if (!pos_adj) pos_adj = pos_align; else - pos_adj = ((pos_adj + pos_align - 1) / pos_align) * - pos_align; + pos_adj = roundup(pos_adj, pos_align); pos_adj = frames_to_bytes(runtime, pos_adj); if (pos_adj >= period_bytes) { dev_warn(bus->dev, "Too big adjustment %d\n", -- cgit v1.2.3 From a434713bfefa4058e6b500f8cb6f8350acdce08b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:21 +0100 Subject: ALSA: lola: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @r1@ expression x; constant C1; constant C2; @@ (x + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ try: if int(C1) != int(C2) - 1: cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_UP(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-10-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/lola/lola_clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/lola/lola_clock.c b/sound/pci/lola/lola_clock.c index fdb85f256ed5..cafd30e30913 100644 --- a/sound/pci/lola/lola_clock.c +++ b/sound/pci/lola/lola_clock.c @@ -135,7 +135,7 @@ int lola_init_clock_widget(struct lola *chip, int nid) } nitems = chip->clock.items; - nb_verbs = (nitems + 3) / 4; + nb_verbs = DIV_ROUND_UP(nitems, 4); idx = 0; idx_list = 0; for (i = 0; i < nb_verbs; i++) { -- cgit v1.2.3 From e4d8aef21403a48c8cf43b2f98b9a27b990fae5b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:22 +0100 Subject: ALSA: usb: Use DIV_ROUND_UP() instead of open-coding it Use DIV_ROUND_UP() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -(((x) + (y) - 1) / (y)) +DIV_ROUND_UP(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-11-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/usb/mixer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index 12b15ed59eaa..412fcd817ecc 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -254,7 +254,7 @@ static int get_relative_value(struct usb_mixer_elem_info *cval, int val) if (val < cval->min) return 0; else if (val >= cval->max) - return (cval->max - cval->min + cval->res - 1) / cval->res; + return DIV_ROUND_UP(cval->max - cval->min, cval->res); else return (val - cval->min) / cval->res; } @@ -1338,7 +1338,7 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, } uinfo->value.integer.min = 0; uinfo->value.integer.max = - (cval->max - cval->min + cval->res - 1) / cval->res; + DIV_ROUND_UP(cval->max - cval->min, cval->res); } return 0; } -- cgit v1.2.3 From af102a88ade2aca4b5c38843fbdc05d9f85b7723 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:23 +0100 Subject: ALSA: vx: Use roundup() instead of open-coding it Use roundup() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -((((x) + (y) - 1) / (y)) * y) +roundup(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-12-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/drivers/vx/vx_pcm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/drivers/vx/vx_pcm.c b/sound/drivers/vx/vx_pcm.c index 3d2e3bcafca8..daffda99b4f7 100644 --- a/sound/drivers/vx/vx_pcm.c +++ b/sound/drivers/vx/vx_pcm.c @@ -1154,8 +1154,7 @@ static int vx_init_audio_io(struct vx_core *chip) chip->ibl.size = 0; vx_set_ibl(chip, &chip->ibl); /* query the info */ if (preferred > 0) { - chip->ibl.size = ((preferred + chip->ibl.granularity - 1) / - chip->ibl.granularity) * chip->ibl.granularity; + chip->ibl.size = roundup(preferred, chip->ibl.granularity); if (chip->ibl.size > chip->ibl.max_size) chip->ibl.size = chip->ibl.max_size; } else -- cgit v1.2.3 From 6b5edf1dcc6005feb0151e3b6c8465770593d5f8 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:24 +0100 Subject: ALSA: oss: Use DIV_ROUND_CLOSEST() instead of open-coding it Use DIV_ROUND_CLOSEST() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -((x) + ((y) / 2)) / (y) +DIV_ROUND_CLOSEST(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-13-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/core/oss/mixer_oss.c | 2 +- sound/core/oss/rate.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sound') diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index f702c96a7478..af5de08f9819 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c @@ -418,7 +418,7 @@ static long snd_mixer_oss_conv(long val, long omin, long omax, long nmin, long n if (orange == 0) return 0; - return ((nrange * (val - omin)) + (orange / 2)) / orange + nmin; + return DIV_ROUND_CLOSEST(nrange * (val - omin), orange) + nmin; } /* convert from alsa native to oss values (0-100) */ diff --git a/sound/core/oss/rate.c b/sound/core/oss/rate.c index d381f4c967c9..98269119347f 100644 --- a/sound/core/oss/rate.c +++ b/sound/core/oss/rate.c @@ -193,7 +193,7 @@ static snd_pcm_sframes_t rate_src_frames(struct snd_pcm_plugin *plugin, snd_pcm_ if (plugin->src_format.rate < plugin->dst_format.rate) { res = (((frames * data->pitch) + (BITS/2)) >> SHIFT); } else { - res = (((frames << SHIFT) + (data->pitch / 2)) / data->pitch); + res = DIV_ROUND_CLOSEST(frames << SHIFT, data->pitch); } if (data->old_src_frames > 0) { snd_pcm_sframes_t frames1 = frames, res1 = data->old_dst_frames; @@ -224,7 +224,7 @@ static snd_pcm_sframes_t rate_dst_frames(struct snd_pcm_plugin *plugin, snd_pcm_ return 0; data = (struct rate_priv *)plugin->extra_data; if (plugin->src_format.rate < plugin->dst_format.rate) { - res = (((frames << SHIFT) + (data->pitch / 2)) / data->pitch); + res = DIV_ROUND_CLOSEST(frames << SHIFT, data->pitch); } else { res = (((frames * data->pitch) + (BITS/2)) >> SHIFT); } -- cgit v1.2.3 From 4743feb9f43b896b22af93e20307eb62fa1299d3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:25 +0100 Subject: ALSA: sonicvibes: Use DIV_ROUND_CLOSEST() instead of open-coding it Use DIV_ROUND_CLOSEST() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -((x) + ((y) / 2)) / (y) +DIV_ROUND_CLOSEST(x, y) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-14-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/sonicvibes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index ecdd54d7a4e1..bd805e416e12 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c @@ -570,7 +570,7 @@ static void snd_sonicvibes_set_dac_rate(struct sonicvibes * sonic, unsigned int unsigned int div; unsigned long flags; - div = (rate * 65536 + SV_FULLRATE / 2) / SV_FULLRATE; + div = DIV_ROUND_CLOSEST(rate * 65536, SV_FULLRATE); if (div > 65535) div = 65535; spin_lock_irqsave(&sonic->reg_lock, flags); -- cgit v1.2.3 From a8667a3f1588bf61f73ac76f8caff3d9dfcf272e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:26 +0100 Subject: ALSA: trident: Use DIV_ROUND_CLOSEST() instead of open-coding it Use DIV_ROUND_CLOSEST() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @@ expression x, y; @@ -((x) + ((y) / 2)) / (y) +DIV_ROUND_CLOSEST(x, y) @r1@ expression x; constant C1; constant C2; @@ ((x) + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ try: if int(C1) * 2 != int(C2): cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_CLOSEST(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-15-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/trident/trident_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index 6e50376163a2..8d0d0d8335ec 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c @@ -678,7 +678,7 @@ static unsigned int snd_trident_convert_rate(unsigned int rate) else if (rate == 48000) delta = 0x1000; else - delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff; + delta = DIV_ROUND_CLOSEST(rate << 12, 48000) & 0x0000ffff; return delta; } @@ -1034,7 +1034,7 @@ static int snd_trident_capture_prepare(struct snd_pcm_substream *substream) ESO_bytes++; // Set channel sample rate, 4.12 format - val = (((unsigned int) 48000L << 12) + (runtime->rate/2)) / runtime->rate; + val = DIV_ROUND_CLOSEST(48000U << 12, runtime->rate); outw(val, TRID_REG(trident, T4D_SBDELTA_DELTA_R)); // Set channel interrupt blk length -- cgit v1.2.3 From db43394690d00508464da724e9d2f54c0ef13ea3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:27 +0100 Subject: ALSA: ens1370: Use DIV_ROUND_CLOSEST() instead of open-coding it Use DIV_ROUND_CLOSEST() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @r1@ expression x; constant C1; constant C2; @@ ((x) + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ try: if int(C1) * 2 != int(C2): cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_CLOSEST(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-16-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/ens1370.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c index d9acef0826a9..93c4fd313311 100644 --- a/sound/pci/ens1370.c +++ b/sound/pci/ens1370.c @@ -752,7 +752,7 @@ static void snd_es1371_dac1_rate(struct ensoniq * ensoniq, unsigned int rate) unsigned int freq, r; mutex_lock(&ensoniq->src_mutex); - freq = ((rate << 15) + 1500) / 3000; + freq = DIV_ROUND_CLOSEST(rate << 15, 3000); r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE | ES_1371_DIS_P2 | ES_1371_DIS_R1)) | ES_1371_DIS_P1; @@ -773,7 +773,7 @@ static void snd_es1371_dac2_rate(struct ensoniq * ensoniq, unsigned int rate) unsigned int freq, r; mutex_lock(&ensoniq->src_mutex); - freq = ((rate << 15) + 1500) / 3000; + freq = DIV_ROUND_CLOSEST(rate << 15, 3000); r = (snd_es1371_wait_src_ready(ensoniq) & (ES_1371_SRC_DISABLE | ES_1371_DIS_P1 | ES_1371_DIS_R1)) | ES_1371_DIS_P2; -- cgit v1.2.3 From e08eaf4003e2afbab98b8a1172b5b17323962543 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:28 +0100 Subject: ALSA: sis7019: Use DIV_ROUND_CLOSEST() instead of open-coding it Use DIV_ROUND_CLOSEST() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @r1@ expression x; constant C1; constant C2; @@ ((x) + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ try: if int(C1) * 2 != int(C2): cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_CLOSEST(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-17-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/sis7019.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c index 7bf6059d50fb..8ffa2f53c0b5 100644 --- a/sound/pci/sis7019.c +++ b/sound/pci/sis7019.c @@ -363,7 +363,7 @@ static u32 sis_rate_to_delta(unsigned int rate) else if (rate == 48000) delta = 0x1000; else - delta = (((rate << 12) + 24000) / 48000) & 0x0000ffff; + delta = DIV_ROUND_CLOSEST(rate << 12, 48000) & 0x0000ffff; return delta; } -- cgit v1.2.3 From 64062869f0d63d118560c15f671376b43f71b102 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 23 Dec 2020 18:22:29 +0100 Subject: ALSA: maestro: Use DIV_ROUND_CLOSEST() instead of open-coding it Use DIV_ROUND_CLOSEST() instead of open-coding it. This documents intent and makes it more clear what is going on for the casual reviewer. Generated using the following the Coccinelle semantic patch. // @r1@ expression x; constant C1; constant C2; @@ ((x) + C1) / C2 @script:python@ C1 << r1.C1; C2 << r1.C2; @@ try: if int(C1) * 2 != int(C2): cocci.include_match(False) except: cocci.include_match(False) @@ expression r1.x; constant r1.C1; constant r1.C2; @@ -(((x) + C1) / C2) +DIV_ROUND_CLOSEST(x, C2) // Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201223172229.781-18-lars@metafoo.de Signed-off-by: Takashi Iwai --- sound/pci/maestro3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index 40232a278b1a..f622c2a6f746 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c @@ -1245,7 +1245,7 @@ static void snd_m3_pcm_setup2(struct snd_m3 *chip, struct m3_dma *s, snd_pcm_format_width(runtime->format) == 16 ? 0 : 1); /* set up dac/adc rate */ - freq = ((runtime->rate << 15) + 24000 ) / 48000; + freq = DIV_ROUND_CLOSEST(runtime->rate << 15, 48000); if (freq) freq--; -- cgit v1.2.3 From 75b1a8f9d62e50f05d0e4e9f3c8bcde32527ffc1 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Mon, 4 Jan 2021 09:17:34 -0800 Subject: ALSA: Convert strlcpy to strscpy when return value is unused strlcpy is deprecated. see: Documentation/process/deprecated.rst Change the calls that do not use the strlcpy return value to the preferred strscpy. Done with cocci script: @@ expression e1, e2, e3; @@ - strlcpy( + strscpy( e1, e2, e3); This cocci script leaves the instances where the return value is used unchanged. After this patch, sound/ has 3 uses of strlcpy() that need to be manually inspected for conversion and changed one day. $ git grep -w strlcpy sound/ sound/usb/card.c: len = strlcpy(card->longname, s, sizeof(card->longname)); sound/usb/mixer.c: return strlcpy(buf, p->name, buflen); sound/usb/mixer.c: return strlcpy(buf, p->names[index], buflen); Miscellenea: o Remove trailing whitespace in conversion of sound/core/hwdep.c Link: https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/ Signed-off-by: Joe Perches Acked-by: Mark Brown Link: https://lore.kernel.org/r/22b393d1790bb268769d0bab7bacf0866dcb0c14.camel@perches.com Signed-off-by: Takashi Iwai --- sound/aoa/codecs/onyx.c | 2 +- sound/aoa/codecs/tas.c | 2 +- sound/aoa/codecs/toonie.c | 2 +- sound/aoa/core/alsa.c | 8 ++++---- sound/aoa/fabrics/layout.c | 6 +++--- sound/aoa/soundbus/sysfs.c | 2 +- sound/arm/aaci.c | 6 +++--- sound/arm/pxa2xx-ac97.c | 2 +- sound/core/compress_offload.c | 2 +- sound/core/control.c | 16 ++++++++-------- sound/core/ctljack.c | 2 +- sound/core/hwdep.c | 6 +++--- sound/core/init.c | 4 ++-- sound/core/oss/mixer_oss.c | 12 ++++++------ sound/core/pcm.c | 2 +- sound/core/pcm_native.c | 6 +++--- sound/core/rawmidi.c | 2 +- sound/core/seq/oss/seq_oss_midi.c | 4 ++-- sound/core/seq/oss/seq_oss_synth.c | 6 +++--- sound/core/seq/seq_clientmgr.c | 2 +- sound/core/seq/seq_ports.c | 6 +++--- sound/core/timer.c | 10 +++++----- sound/core/timer_compat.c | 4 ++-- sound/drivers/opl3/opl3_oss.c | 2 +- sound/drivers/opl3/opl3_synth.c | 2 +- sound/firewire/bebob/bebob_hwdep.c | 2 +- sound/firewire/dice/dice-hwdep.c | 2 +- sound/firewire/digi00x/digi00x-hwdep.c | 2 +- sound/firewire/fireface/ff-hwdep.c | 2 +- sound/firewire/fireworks/fireworks_hwdep.c | 2 +- sound/firewire/motu/motu-hwdep.c | 2 +- sound/firewire/oxfw/oxfw-hwdep.c | 2 +- sound/firewire/tascam/tascam-hwdep.c | 2 +- sound/i2c/i2c.c | 4 ++-- sound/isa/ad1848/ad1848.c | 4 ++-- sound/isa/cs423x/cs4231.c | 4 ++-- sound/isa/cs423x/cs4236.c | 4 ++-- sound/isa/es1688/es1688.c | 4 ++-- sound/isa/sb/sb16_csp.c | 2 +- sound/isa/sb/sb_mixer.c | 2 +- sound/oss/dmasound/dmasound_core.c | 4 ++-- sound/pci/cs5535audio/cs5535audio_olpc.c | 4 ++-- sound/pci/ctxfi/ctpcm.c | 2 +- sound/pci/emu10k1/emu10k1.c | 4 ++-- sound/pci/emu10k1/emu10k1_main.c | 2 +- sound/pci/emu10k1/emufx.c | 6 +++--- sound/pci/es1968.c | 2 +- sound/pci/fm801.c | 2 +- sound/pci/hda/hda_auto_parser.c | 2 +- sound/pci/hda/hda_codec.c | 2 +- sound/pci/hda/hda_controller.c | 2 +- sound/pci/hda/hda_eld.c | 2 +- sound/pci/hda/hda_generic.c | 2 +- sound/pci/hda/hda_intel.c | 2 +- sound/pci/hda/hda_jack.c | 2 +- sound/pci/ice1712/juli.c | 2 +- sound/pci/ice1712/psc724.c | 4 ++-- sound/pci/ice1712/quartet.c | 2 +- sound/pci/ice1712/wm8776.c | 2 +- sound/pci/lola/lola.c | 2 +- sound/pci/lola/lola_pcm.c | 2 +- sound/pci/rme9652/hdspm.c | 2 +- sound/ppc/keywest.c | 2 +- sound/soc/qcom/qdsp6/q6afe.c | 2 +- sound/soc/sh/rcar/core.c | 2 +- sound/usb/bcd2000/bcd2000.c | 2 +- sound/usb/caiaq/audio.c | 2 +- sound/usb/caiaq/device.c | 6 +++--- sound/usb/caiaq/midi.c | 2 +- sound/usb/card.c | 4 ++-- sound/usb/hiface/chip.c | 6 +++--- sound/usb/hiface/pcm.c | 2 +- sound/usb/mixer.c | 12 ++++++------ sound/usb/mixer_quirks.c | 2 +- sound/usb/mixer_scarlett.c | 2 +- sound/usb/mixer_scarlett_gen2.c | 2 +- sound/usb/mixer_us16x08.c | 2 +- sound/x86/intel_hdmi_audio.c | 2 +- sound/xen/xen_snd_front_cfg.c | 2 +- 79 files changed, 134 insertions(+), 134 deletions(-) (limited to 'sound') diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c index 12028b3e2eee..1abee841cc45 100644 --- a/sound/aoa/codecs/onyx.c +++ b/sound/aoa/codecs/onyx.c @@ -1013,7 +1013,7 @@ static int onyx_i2c_probe(struct i2c_client *client, goto fail; } - strlcpy(onyx->codec.name, "onyx", MAX_CODEC_NAME_LEN); + strscpy(onyx->codec.name, "onyx", MAX_CODEC_NAME_LEN); onyx->codec.owner = THIS_MODULE; onyx->codec.init = onyx_init_codec; onyx->codec.exit = onyx_exit_codec; diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c index d3e37577b529..ac246dd3ab49 100644 --- a/sound/aoa/codecs/tas.c +++ b/sound/aoa/codecs/tas.c @@ -894,7 +894,7 @@ static int tas_i2c_probe(struct i2c_client *client, /* seems that half is a saner default */ tas->drc_range = TAS3004_DRC_MAX / 2; - strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); + strscpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN); tas->codec.owner = THIS_MODULE; tas->codec.init = tas_init_codec; tas->codec.exit = tas_exit_codec; diff --git a/sound/aoa/codecs/toonie.c b/sound/aoa/codecs/toonie.c index c2d014486c33..0da5af129492 100644 --- a/sound/aoa/codecs/toonie.c +++ b/sound/aoa/codecs/toonie.c @@ -126,7 +126,7 @@ static int __init toonie_init(void) if (!toonie) return -ENOMEM; - strlcpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name)); + strscpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name)); toonie->codec.owner = THIS_MODULE; toonie->codec.init = toonie_init_codec; toonie->codec.exit = toonie_exit_codec; diff --git a/sound/aoa/core/alsa.c b/sound/aoa/core/alsa.c index b61081342266..7fce8581ddbd 100644 --- a/sound/aoa/core/alsa.c +++ b/sound/aoa/core/alsa.c @@ -28,10 +28,10 @@ int aoa_alsa_init(char *name, struct module *mod, struct device *dev) return err; aoa_card = alsa_card->private_data; aoa_card->alsa_card = alsa_card; - strlcpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver)); - strlcpy(alsa_card->shortname, name, sizeof(alsa_card->shortname)); - strlcpy(alsa_card->longname, name, sizeof(alsa_card->longname)); - strlcpy(alsa_card->mixername, name, sizeof(alsa_card->mixername)); + strscpy(alsa_card->driver, "AppleOnbdAudio", sizeof(alsa_card->driver)); + strscpy(alsa_card->shortname, name, sizeof(alsa_card->shortname)); + strscpy(alsa_card->longname, name, sizeof(alsa_card->longname)); + strscpy(alsa_card->mixername, name, sizeof(alsa_card->mixername)); err = snd_card_register(aoa_card->alsa_card); if (err < 0) { printk(KERN_ERR "snd-aoa: couldn't register alsa card\n"); diff --git a/sound/aoa/fabrics/layout.c b/sound/aoa/fabrics/layout.c index d2e85b83f7ed..ec4ef18555bc 100644 --- a/sound/aoa/fabrics/layout.c +++ b/sound/aoa/fabrics/layout.c @@ -948,7 +948,7 @@ static void layout_attached_codec(struct aoa_codec *codec) ldev->gpio.methods->set_lineout(codec->gpio, 1); ctl = snd_ctl_new1(&lineout_ctl, codec->gpio); if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE) - strlcpy(ctl->id.name, + strscpy(ctl->id.name, "Headphone Switch", sizeof(ctl->id.name)); ldev->lineout_ctrl = ctl; aoa_snd_ctl_add(ctl); @@ -962,14 +962,14 @@ static void layout_attached_codec(struct aoa_codec *codec) ctl = snd_ctl_new1(&lineout_detect_choice, ldev); if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE) - strlcpy(ctl->id.name, + strscpy(ctl->id.name, "Headphone Detect Autoswitch", sizeof(ctl->id.name)); aoa_snd_ctl_add(ctl); ctl = snd_ctl_new1(&lineout_detected, ldev); if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE) - strlcpy(ctl->id.name, + strscpy(ctl->id.name, "Headphone Detected", sizeof(ctl->id.name)); ldev->lineout_detected_ctrl = ctl; diff --git a/sound/aoa/soundbus/sysfs.c b/sound/aoa/soundbus/sysfs.c index a2d55e15afbb..dead3105689b 100644 --- a/sound/aoa/soundbus/sysfs.c +++ b/sound/aoa/soundbus/sysfs.c @@ -13,7 +13,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, int length; if (*sdev->modalias) { - strlcpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1); + strscpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1); strcat(buf, "\n"); length = strlen(buf); } else { diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c index a0996c47e58f..f02a91bdaa97 100644 --- a/sound/arm/aaci.c +++ b/sound/arm/aaci.c @@ -890,8 +890,8 @@ static struct aaci *aaci_init_card(struct amba_device *dev) card->private_free = aaci_free_card; - strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver)); - strlcpy(card->shortname, "ARM AC'97 Interface", sizeof(card->shortname)); + strscpy(card->driver, DRIVER_NAME, sizeof(card->driver)); + strscpy(card->shortname, "ARM AC'97 Interface", sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s PL%03x rev%u at 0x%08llx, irq %d", card->shortname, amba_part(dev), amba_rev(dev), @@ -921,7 +921,7 @@ static int aaci_init_pcm(struct aaci *aaci) pcm->private_data = aaci; pcm->info_flags = 0; - strlcpy(pcm->name, DRIVER_NAME, sizeof(pcm->name)); + strscpy(pcm->name, DRIVER_NAME, sizeof(pcm->name)); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &aaci_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &aaci_capture_ops); diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c index ea8e233150c8..6322e6392594 100644 --- a/sound/arm/pxa2xx-ac97.c +++ b/sound/arm/pxa2xx-ac97.c @@ -235,7 +235,7 @@ static int pxa2xx_ac97_probe(struct platform_device *dev) if (ret < 0) goto err; - strlcpy(card->driver, dev->dev.driver->name, sizeof(card->driver)); + strscpy(card->driver, dev->dev.driver->name, sizeof(card->driver)); ret = pxa2xx_ac97_pcm_new(card); if (ret) diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index debc30fcf5b3..21ce4c056a92 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -1132,7 +1132,7 @@ static void snd_compress_proc_done(struct snd_compr *compr) static inline void snd_compress_set_id(struct snd_compr *compr, const char *id) { - strlcpy(compr->id, id, sizeof(compr->id)); + strscpy(compr->id, id, sizeof(compr->id)); } #else static inline int snd_compress_proc_init(struct snd_compr *compr) diff --git a/sound/core/control.c b/sound/core/control.c index 1571c7f7c43b..5165741a8400 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -261,7 +261,7 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, kctl->id.device = ncontrol->device; kctl->id.subdevice = ncontrol->subdevice; if (ncontrol->name) { - strlcpy(kctl->id.name, ncontrol->name, sizeof(kctl->id.name)); + strscpy(kctl->id.name, ncontrol->name, sizeof(kctl->id.name)); if (strcmp(ncontrol->name, kctl->id.name) != 0) pr_warn("ALSA: Control name '%s' truncated to '%s'\n", ncontrol->name, kctl->id.name); @@ -701,12 +701,12 @@ static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl, return -ENOMEM; down_read(&snd_ioctl_rwsem); info->card = card->number; - strlcpy(info->id, card->id, sizeof(info->id)); - strlcpy(info->driver, card->driver, sizeof(info->driver)); - strlcpy(info->name, card->shortname, sizeof(info->name)); - strlcpy(info->longname, card->longname, sizeof(info->longname)); - strlcpy(info->mixername, card->mixername, sizeof(info->mixername)); - strlcpy(info->components, card->components, sizeof(info->components)); + strscpy(info->id, card->id, sizeof(info->id)); + strscpy(info->driver, card->driver, sizeof(info->driver)); + strscpy(info->name, card->shortname, sizeof(info->name)); + strscpy(info->longname, card->longname, sizeof(info->longname)); + strscpy(info->mixername, card->mixername, sizeof(info->mixername)); + strscpy(info->components, card->components, sizeof(info->components)); up_read(&snd_ioctl_rwsem); if (copy_to_user(arg, info, sizeof(struct snd_ctl_card_info))) { kfree(info); @@ -2137,7 +2137,7 @@ int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels, WARN(strlen(names[info->value.enumerated.item]) >= sizeof(info->value.enumerated.name), "ALSA: too long item name '%s'\n", names[info->value.enumerated.item]); - strlcpy(info->value.enumerated.name, + strscpy(info->value.enumerated.name, names[info->value.enumerated.item], sizeof(info->value.enumerated.name)); return 0; diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c index 9be4e282f2e0..709b1a9c2caa 100644 --- a/sound/core/ctljack.c +++ b/sound/core/ctljack.c @@ -35,7 +35,7 @@ static int get_available_index(struct snd_card *card, const char *name) sid.index = 0; sid.iface = SNDRV_CTL_ELEM_IFACE_CARD; - strlcpy(sid.name, name, sizeof(sid.name)); + strscpy(sid.name, name, sizeof(sid.name)); while (snd_ctl_find_id(card, &sid)) { sid.index++; diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index 0c029892880a..264b8ea64bc2 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c @@ -177,8 +177,8 @@ static int snd_hwdep_info(struct snd_hwdep *hw, memset(&info, 0, sizeof(info)); info.card = hw->card->number; - strlcpy(info.id, hw->id, sizeof(info.id)); - strlcpy(info.name, hw->name, sizeof(info.name)); + strscpy(info.id, hw->id, sizeof(info.id)); + strscpy(info.name, hw->name, sizeof(info.name)); info.iface = hw->iface; if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; @@ -379,7 +379,7 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device, hwdep->card = card; hwdep->device = device; if (id) - strlcpy(hwdep->id, id, sizeof(hwdep->id)); + strscpy(hwdep->id, id, sizeof(hwdep->id)); snd_device_initialize(&hwdep->dev, card); hwdep->dev.release = release_hwdep_device; diff --git a/sound/core/init.c b/sound/core/init.c index 75aec71c48a8..56834febc7a4 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -174,7 +174,7 @@ int snd_card_new(struct device *parent, int idx, const char *xid, if (extra_size > 0) card->private_data = (char *)card + sizeof(struct snd_card); if (xid) - strlcpy(card->id, xid, sizeof(card->id)); + strscpy(card->id, xid, sizeof(card->id)); err = 0; mutex_lock(&snd_card_mutex); if (idx < 0) /* first check the matching module-name slot */ @@ -623,7 +623,7 @@ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src, /* last resort... */ dev_err(card->dev, "unable to set card id (%s)\n", id); if (card->proc_root->name) - strlcpy(card->id, card->proc_root->name, sizeof(card->id)); + strscpy(card->id, card->proc_root->name, sizeof(card->id)); } /** diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c index af5de08f9819..bec928327478 100644 --- a/sound/core/oss/mixer_oss.c +++ b/sound/core/oss/mixer_oss.c @@ -87,8 +87,8 @@ static int snd_mixer_oss_info(struct snd_mixer_oss_file *fmixer, struct mixer_info info; memset(&info, 0, sizeof(info)); - strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id)); - strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name)); + strscpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id)); + strscpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name)); info.modify_counter = card->mixer_oss_change_count; if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; @@ -103,8 +103,8 @@ static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file *fmixer, _old_mixer_info info; memset(&info, 0, sizeof(info)); - strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id)); - strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name)); + strscpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id)); + strscpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name)); if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; return 0; @@ -499,7 +499,7 @@ static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, c memset(&id, 0, sizeof(id)); id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strlcpy(id.name, name, sizeof(id.name)); + strscpy(id.name, name, sizeof(id.name)); id.index = index; return snd_ctl_find_id(card, &id); } @@ -1355,7 +1355,7 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd) mixer->oss_dev_alloc = 1; mixer->card = card; if (*card->mixername) - strlcpy(mixer->name, card->mixername, sizeof(mixer->name)); + strscpy(mixer->name, card->mixername, sizeof(mixer->name)); else snprintf(mixer->name, sizeof(mixer->name), "mixer%i", card->number); diff --git a/sound/core/pcm.c b/sound/core/pcm.c index be5714f1bb58..e5947281e5fc 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -729,7 +729,7 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device, init_waitqueue_head(&pcm->open_wait); INIT_LIST_HEAD(&pcm->list); if (id) - strlcpy(pcm->id, id, sizeof(pcm->id)); + strscpy(pcm->id, id, sizeof(pcm->id)); err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count); diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 9f3f8e953ff0..66ae1e248103 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -209,13 +209,13 @@ int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info) info->device = pcm->device; info->stream = substream->stream; info->subdevice = substream->number; - strlcpy(info->id, pcm->id, sizeof(info->id)); - strlcpy(info->name, pcm->name, sizeof(info->name)); + strscpy(info->id, pcm->id, sizeof(info->id)); + strscpy(info->name, pcm->name, sizeof(info->name)); info->dev_class = pcm->dev_class; info->dev_subclass = pcm->dev_subclass; info->subdevices_count = pstr->substream_count; info->subdevices_avail = pstr->substream_count - pstr->substream_opened; - strlcpy(info->subname, substream->name, sizeof(info->subname)); + strscpy(info->subname, substream->name, sizeof(info->subname)); return 0; } diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index 257ad5206240..aca00af93afe 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c @@ -1686,7 +1686,7 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device, INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams); if (id != NULL) - strlcpy(rmidi->id, id, sizeof(rmidi->id)); + strscpy(rmidi->id, id, sizeof(rmidi->id)); snd_device_initialize(&rmidi->dev, card); rmidi->dev.release = release_rawmidi_device; diff --git a/sound/core/seq/oss/seq_oss_midi.c b/sound/core/seq/oss/seq_oss_midi.c index 2ddfe2226651..3f82c196de46 100644 --- a/sound/core/seq/oss/seq_oss_midi.c +++ b/sound/core/seq/oss/seq_oss_midi.c @@ -173,7 +173,7 @@ snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo) snd_use_lock_init(&mdev->use_lock); /* copy and truncate the name of synth device */ - strlcpy(mdev->name, pinfo->name, sizeof(mdev->name)); + strscpy(mdev->name, pinfo->name, sizeof(mdev->name)); /* create MIDI coder */ if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &mdev->coder) < 0) { @@ -647,7 +647,7 @@ snd_seq_oss_midi_make_info(struct seq_oss_devinfo *dp, int dev, struct midi_info inf->device = dev; inf->dev_type = 0; /* FIXME: ?? */ inf->capabilities = 0; /* FIXME: ?? */ - strlcpy(inf->name, mdev->name, sizeof(inf->name)); + strscpy(inf->name, mdev->name, sizeof(inf->name)); snd_use_lock_free(&mdev->use_lock); return 0; } diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c index 11554d0412f0..136dc663887a 100644 --- a/sound/core/seq/oss/seq_oss_synth.c +++ b/sound/core/seq/oss/seq_oss_synth.c @@ -107,7 +107,7 @@ snd_seq_oss_synth_probe(struct device *_dev) snd_use_lock_init(&rec->use_lock); /* copy and truncate the name of synth device */ - strlcpy(rec->name, dev->name, sizeof(rec->name)); + strscpy(rec->name, dev->name, sizeof(rec->name)); /* registration */ spin_lock_irqsave(®ister_lock, flags); @@ -616,7 +616,7 @@ snd_seq_oss_synth_make_info(struct seq_oss_devinfo *dp, int dev, struct synth_in inf->synth_subtype = 0; inf->nr_voices = 16; inf->device = dev; - strlcpy(inf->name, minf.name, sizeof(inf->name)); + strscpy(inf->name, minf.name, sizeof(inf->name)); } else { if ((rec = get_synthdev(dp, dev)) == NULL) return -ENXIO; @@ -624,7 +624,7 @@ snd_seq_oss_synth_make_info(struct seq_oss_devinfo *dp, int dev, struct synth_in inf->synth_subtype = rec->synth_subtype; inf->nr_voices = rec->nr_voices; inf->device = dev; - strlcpy(inf->name, rec->name, sizeof(inf->name)); + strscpy(inf->name, rec->name, sizeof(inf->name)); snd_use_lock_free(&rec->use_lock); } return 0; diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c index f9f2fea58b32..b6a24fb5e76b 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -1584,7 +1584,7 @@ static int snd_seq_ioctl_get_queue_info(struct snd_seq_client *client, info->queue = q->queue; info->owner = q->owner; info->locked = q->locked; - strlcpy(info->name, q->name, sizeof(info->name)); + strscpy(info->name, q->name, sizeof(info->name)); queuefree(q); return 0; diff --git a/sound/core/seq/seq_ports.c b/sound/core/seq/seq_ports.c index 83be6b982a87..b9c2ce2b8d5a 100644 --- a/sound/core/seq/seq_ports.c +++ b/sound/core/seq/seq_ports.c @@ -327,7 +327,7 @@ int snd_seq_set_port_info(struct snd_seq_client_port * port, /* set port name */ if (info->name[0]) - strlcpy(port->name, info->name, sizeof(port->name)); + strscpy(port->name, info->name, sizeof(port->name)); /* set capabilities */ port->capability = info->capability; @@ -356,7 +356,7 @@ int snd_seq_get_port_info(struct snd_seq_client_port * port, return -EINVAL; /* get port name */ - strlcpy(info->name, port->name, sizeof(info->name)); + strscpy(info->name, port->name, sizeof(info->name)); /* get capabilities */ info->capability = port->capability; @@ -654,7 +654,7 @@ int snd_seq_event_port_attach(int client, /* Set up the port */ memset(&portinfo, 0, sizeof(portinfo)); portinfo.addr.client = client; - strlcpy(portinfo.name, portname ? portname : "Unnamed port", + strscpy(portinfo.name, portname ? portname : "Unnamed port", sizeof(portinfo.name)); portinfo.capability = cap; diff --git a/sound/core/timer.c b/sound/core/timer.c index 765ea66665a8..6898b1ac0d7f 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -959,7 +959,7 @@ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, timer->tmr_device = tid->device; timer->tmr_subdevice = tid->subdevice; if (id) - strlcpy(timer->id, id, sizeof(timer->id)); + strscpy(timer->id, id, sizeof(timer->id)); timer->sticks = 1; INIT_LIST_HEAD(&timer->device_list); INIT_LIST_HEAD(&timer->open_list_head); @@ -1659,8 +1659,8 @@ static int snd_timer_user_ginfo(struct file *file, ginfo->card = t->card ? t->card->number : -1; if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) ginfo->flags |= SNDRV_TIMER_FLG_SLAVE; - strlcpy(ginfo->id, t->id, sizeof(ginfo->id)); - strlcpy(ginfo->name, t->name, sizeof(ginfo->name)); + strscpy(ginfo->id, t->id, sizeof(ginfo->id)); + strscpy(ginfo->name, t->name, sizeof(ginfo->name)); ginfo->resolution = t->hw.resolution; if (t->hw.resolution_min > 0) { ginfo->resolution_min = t->hw.resolution_min; @@ -1814,8 +1814,8 @@ static int snd_timer_user_info(struct file *file, info->card = t->card ? t->card->number : -1; if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) info->flags |= SNDRV_TIMER_FLG_SLAVE; - strlcpy(info->id, t->id, sizeof(info->id)); - strlcpy(info->name, t->name, sizeof(info->name)); + strscpy(info->id, t->id, sizeof(info->id)); + strscpy(info->name, t->name, sizeof(info->name)); info->resolution = t->hw.resolution; if (copy_to_user(_info, info, sizeof(*_info))) err = -EFAULT; diff --git a/sound/core/timer_compat.c b/sound/core/timer_compat.c index 0103d16f6f9f..ee973b7b8044 100644 --- a/sound/core/timer_compat.c +++ b/sound/core/timer_compat.c @@ -61,8 +61,8 @@ static int snd_timer_user_info_compat(struct file *file, info.card = t->card ? t->card->number : -1; if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) info.flags |= SNDRV_TIMER_FLG_SLAVE; - strlcpy(info.id, t->id, sizeof(info.id)); - strlcpy(info.name, t->name, sizeof(info.name)); + strscpy(info.id, t->id, sizeof(info.id)); + strscpy(info.name, t->name, sizeof(info.name)); info.resolution = t->hw.resolution; if (copy_to_user(_info, &info, sizeof(*_info))) return -EFAULT; diff --git a/sound/drivers/opl3/opl3_oss.c b/sound/drivers/opl3/opl3_oss.c index 7bf0d5f3fedd..c82c7c1c0714 100644 --- a/sound/drivers/opl3/opl3_oss.c +++ b/sound/drivers/opl3/opl3_oss.c @@ -97,7 +97,7 @@ void snd_opl3_init_seq_oss(struct snd_opl3 *opl3, char *name) return; opl3->oss_seq_dev = dev; - strlcpy(dev->name, name, sizeof(dev->name)); + strscpy(dev->name, name, sizeof(dev->name)); arg = SNDRV_SEQ_DEVICE_ARGPTR(dev); arg->type = SYNTH_TYPE_FM; if (opl3->hardware < OPL3_HW_OPL3) { diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_synth.c index 08c10ac9d6c8..97d30a833ac8 100644 --- a/sound/drivers/opl3/opl3_synth.c +++ b/sound/drivers/opl3/opl3_synth.c @@ -290,7 +290,7 @@ int snd_opl3_load_patch(struct snd_opl3 *opl3, } if (name) - strlcpy(patch->name, name, sizeof(patch->name)); + strscpy(patch->name, name, sizeof(patch->name)); return 0; } diff --git a/sound/firewire/bebob/bebob_hwdep.c b/sound/firewire/bebob/bebob_hwdep.c index c362eb38ab90..8677e3ec8d14 100644 --- a/sound/firewire/bebob/bebob_hwdep.c +++ b/sound/firewire/bebob/bebob_hwdep.c @@ -80,7 +80,7 @@ hwdep_get_info(struct snd_bebob *bebob, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/dice/dice-hwdep.c b/sound/firewire/dice/dice-hwdep.c index f69f7996762f..ffc0b97782d6 100644 --- a/sound/firewire/dice/dice-hwdep.c +++ b/sound/firewire/dice/dice-hwdep.c @@ -79,7 +79,7 @@ static int hwdep_get_info(struct snd_dice *dice, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/digi00x/digi00x-hwdep.c b/sound/firewire/digi00x/digi00x-hwdep.c index 41c5857c612e..aadf7d724856 100644 --- a/sound/firewire/digi00x/digi00x-hwdep.c +++ b/sound/firewire/digi00x/digi00x-hwdep.c @@ -87,7 +87,7 @@ static int hwdep_get_info(struct snd_dg00x *dg00x, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/fireface/ff-hwdep.c b/sound/firewire/fireface/ff-hwdep.c index e73e8d2865a5..4b2e0dff5ddb 100644 --- a/sound/firewire/fireface/ff-hwdep.c +++ b/sound/firewire/fireface/ff-hwdep.c @@ -79,7 +79,7 @@ static int hwdep_get_info(struct snd_ff *ff, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/fireworks/fireworks_hwdep.c b/sound/firewire/fireworks/fireworks_hwdep.c index e93eb4616c5f..626c0c34b0b6 100644 --- a/sound/firewire/fireworks/fireworks_hwdep.c +++ b/sound/firewire/fireworks/fireworks_hwdep.c @@ -212,7 +212,7 @@ hwdep_get_info(struct snd_efw *efw, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/motu/motu-hwdep.c b/sound/firewire/motu/motu-hwdep.c index 0764a477052a..b5ced5d27758 100644 --- a/sound/firewire/motu/motu-hwdep.c +++ b/sound/firewire/motu/motu-hwdep.c @@ -86,7 +86,7 @@ static int hwdep_get_info(struct snd_motu *motu, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/oxfw/oxfw-hwdep.c b/sound/firewire/oxfw/oxfw-hwdep.c index eba33d050060..9e1b3e151bad 100644 --- a/sound/firewire/oxfw/oxfw-hwdep.c +++ b/sound/firewire/oxfw/oxfw-hwdep.c @@ -79,7 +79,7 @@ static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/firewire/tascam/tascam-hwdep.c b/sound/firewire/tascam/tascam-hwdep.c index 6f38335fe10b..74eed9505665 100644 --- a/sound/firewire/tascam/tascam-hwdep.c +++ b/sound/firewire/tascam/tascam-hwdep.c @@ -154,7 +154,7 @@ static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg) info.card = dev->card->index; *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); - strlcpy(info.device_name, dev_name(&dev->device), + strscpy(info.device_name, dev_name(&dev->device), sizeof(info.device_name)); if (copy_to_user(arg, &info, sizeof(info))) diff --git a/sound/i2c/i2c.c b/sound/i2c/i2c.c index a684faa771ef..847e3b6ca601 100644 --- a/sound/i2c/i2c.c +++ b/sound/i2c/i2c.c @@ -84,7 +84,7 @@ int snd_i2c_bus_create(struct snd_card *card, const char *name, list_add_tail(&bus->buses, &master->buses); bus->master = master; } - strlcpy(bus->name, name, sizeof(bus->name)); + strscpy(bus->name, name, sizeof(bus->name)); err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops); if (err < 0) { snd_i2c_bus_free(bus); @@ -108,7 +108,7 @@ int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name, if (device == NULL) return -ENOMEM; device->addr = addr; - strlcpy(device->name, name, sizeof(device->name)); + strscpy(device->name, name, sizeof(device->name)); list_add_tail(&device->list, &bus->devices); device->bus = bus; *rdevice = device; diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c index 593c6e959afe..47bffe623105 100644 --- a/sound/isa/ad1848/ad1848.c +++ b/sound/isa/ad1848/ad1848.c @@ -95,8 +95,8 @@ static int snd_ad1848_probe(struct device *dev, unsigned int n) if (error < 0) goto out; - strlcpy(card->driver, "AD1848", sizeof(card->driver)); - strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); + strscpy(card->driver, "AD1848", sizeof(card->driver)); + strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); if (!thinkpad[n]) snprintf(card->longname, sizeof(card->longname), diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c index 2135963eba78..bcbea6962d7e 100644 --- a/sound/isa/cs423x/cs4231.c +++ b/sound/isa/cs423x/cs4231.c @@ -95,8 +95,8 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n) if (error < 0) goto out; - strlcpy(card->driver, "CS4231", sizeof(card->driver)); - strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); + strscpy(card->driver, "CS4231", sizeof(card->driver)); + strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); if (dma2[n] < 0) snprintf(card->longname, sizeof(card->longname), diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c index fa3c39cff5f8..fb9d8a4b7084 100644 --- a/sound/isa/cs423x/cs4236.c +++ b/sound/isa/cs423x/cs4236.c @@ -405,8 +405,8 @@ static int snd_cs423x_probe(struct snd_card *card, int dev) if (err < 0) return err; } - strlcpy(card->driver, chip->pcm->name, sizeof(card->driver)); - strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); + strscpy(card->driver, chip->pcm->name, sizeof(card->driver)); + strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); if (dma2[dev] < 0) snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx, irq %i, dma %i", diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c index 64610571a5e1..766ab43aaf77 100644 --- a/sound/isa/es1688/es1688.c +++ b/sound/isa/es1688/es1688.c @@ -133,8 +133,8 @@ static int snd_es1688_probe(struct snd_card *card, unsigned int n) if (error < 0) return error; - strlcpy(card->driver, "ES1688", sizeof(card->driver)); - strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); + strscpy(card->driver, "ES1688", sizeof(card->driver)); + strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx, irq %i, dma %i", chip->pcm->name, chip->port, chip->irq, chip->dma8); diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c index 270af863e198..8635a2b6b36b 100644 --- a/sound/isa/sb/sb16_csp.c +++ b/sound/isa/sb/sb16_csp.c @@ -388,7 +388,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p, return err; /* fill in codec header */ - strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name)); + strscpy(p->codec_name, info.codec_name, sizeof(p->codec_name)); p->func_nr = func_nr; p->mode = le16_to_cpu(funcdesc_h.flags_play_rec); switch (le16_to_cpu(funcdesc_h.VOC_type)) { diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c index 3f703b4a304d..5de5506e7e60 100644 --- a/sound/isa/sb/sb_mixer.c +++ b/sound/isa/sb/sb_mixer.c @@ -482,7 +482,7 @@ int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int ty ctl = snd_ctl_new1(&newctls[type], chip); if (! ctl) return -ENOMEM; - strlcpy(ctl->id.name, name, sizeof(ctl->id.name)); + strscpy(ctl->id.name, name, sizeof(ctl->id.name)); ctl->id.index = index; ctl->private_value = value; if ((err = snd_ctl_add(chip->card, ctl)) < 0) diff --git a/sound/oss/dmasound/dmasound_core.c b/sound/oss/dmasound/dmasound_core.c index 38f25e97538f..49679aa8631d 100644 --- a/sound/oss/dmasound/dmasound_core.c +++ b/sound/oss/dmasound/dmasound_core.c @@ -355,8 +355,8 @@ static int mixer_ioctl(struct file *file, u_int cmd, u_long arg) { mixer_info info; memset(&info, 0, sizeof(info)); - strlcpy(info.id, dmasound.mach.name2, sizeof(info.id)); - strlcpy(info.name, dmasound.mach.name2, sizeof(info.name)); + strscpy(info.id, dmasound.mach.name2, sizeof(info.id)); + strscpy(info.name, dmasound.mach.name2, sizeof(info.name)); info.modify_counter = mixer.modify_counter; if (copy_to_user((void __user *)arg, &info, sizeof(info))) return -EFAULT; diff --git a/sound/pci/cs5535audio/cs5535audio_olpc.c b/sound/pci/cs5535audio/cs5535audio_olpc.c index 4e295303b041..110d3209441b 100644 --- a/sound/pci/cs5535audio/cs5535audio_olpc.c +++ b/sound/pci/cs5535audio/cs5535audio_olpc.c @@ -158,13 +158,13 @@ int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) /* drop the original AD1888 HPF control */ memset(&elem, 0, sizeof(elem)); elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strlcpy(elem.name, "High Pass Filter Enable", sizeof(elem.name)); + strscpy(elem.name, "High Pass Filter Enable", sizeof(elem.name)); snd_ctl_remove_id(card, &elem); /* drop the original V_REFOUT control */ memset(&elem, 0, sizeof(elem)); elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strlcpy(elem.name, "V_REFOUT Enable", sizeof(elem.name)); + strscpy(elem.name, "V_REFOUT Enable", sizeof(elem.name)); snd_ctl_remove_id(card, &elem); /* add the OLPC-specific controls */ diff --git a/sound/pci/ctxfi/ctpcm.c b/sound/pci/ctxfi/ctpcm.c index 3f48ad0e27e7..81dfc6a76b18 100644 --- a/sound/pci/ctxfi/ctpcm.c +++ b/sound/pci/ctxfi/ctpcm.c @@ -433,7 +433,7 @@ int ct_alsa_pcm_create(struct ct_atc *atc, pcm->private_data = atc; pcm->info_flags = 0; pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; - strlcpy(pcm->name, device_name, sizeof(pcm->name)); + strscpy(pcm->name, device_name, sizeof(pcm->name)); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &ct_pcm_playback_ops); diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c index 29b7720d7961..353934c88cbd 100644 --- a/sound/pci/emu10k1/emu10k1.c +++ b/sound/pci/emu10k1/emu10k1.c @@ -168,9 +168,9 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci, } #endif - strlcpy(card->driver, emu->card_capabilities->driver, + strscpy(card->driver, emu->card_capabilities->driver, sizeof(card->driver)); - strlcpy(card->shortname, emu->card_capabilities->name, + strscpy(card->shortname, emu->card_capabilities->name, sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s (rev.%d, serial:0x%x) at 0x%lx, irq %i", diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index bd70e112ffd7..24a2fd706d69 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -1869,7 +1869,7 @@ int snd_emu10k1_create(struct snd_card *card, emu->serial); if (!*card->id && c->id) - strlcpy(card->id, c->id, sizeof(card->id)); + strscpy(card->id, c->id, sizeof(card->id)); is_audigy = emu->audigy = c->emu10k2_chip; diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c index 4e76ed0e91d5..80ef62a4a7c0 100644 --- a/sound/pci/emu10k1/emufx.c +++ b/sound/pci/emu10k1/emufx.c @@ -940,7 +940,7 @@ static int snd_emu10k1_list_controls(struct snd_emu10k1 *emu, memset(gctl, 0, sizeof(*gctl)); id = &ctl->kcontrol->id; gctl->id.iface = (__force int)id->iface; - strlcpy(gctl->id.name, id->name, sizeof(gctl->id.name)); + strscpy(gctl->id.name, id->name, sizeof(gctl->id.name)); gctl->id.index = id->index; gctl->id.device = id->device; gctl->id.subdevice = id->subdevice; @@ -976,7 +976,7 @@ static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu, err = snd_emu10k1_verify_controls(emu, icode, in_kernel); if (err < 0) goto __error; - strlcpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name)); + strscpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name)); /* stop FX processor - this may be dangerous, but it's better to miss some samples than generate wrong ones - [jk] */ if (emu->audigy) @@ -1015,7 +1015,7 @@ static int snd_emu10k1_icode_peek(struct snd_emu10k1 *emu, int err; mutex_lock(&emu->fx8010.lock); - strlcpy(icode->name, emu->fx8010.name, sizeof(icode->name)); + strscpy(icode->name, emu->fx8010.name, sizeof(icode->name)); /* ok, do the main job */ err = snd_emu10k1_gpr_peek(emu, icode); if (err >= 0) diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index 34332d008b27..c6be14c4f311 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c @@ -2768,7 +2768,7 @@ static int snd_es1968_create(struct snd_card *card, if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) { dev_info(card->dev, "detected TEA575x radio type %s\n", get_tea575x_gpio(chip)->name); - strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name, + strscpy(chip->tea.card, get_tea575x_gpio(chip)->name, sizeof(chip->tea.card)); break; } diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index 0a95032fd297..c6ad6235a669 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -1300,7 +1300,7 @@ static int snd_fm801_create(struct snd_card *card, chip->tea575x_tuner |= tuner_only; } if (!(chip->tea575x_tuner & TUNER_DISABLED)) { - strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name, + strscpy(chip->tea.card, get_tea575x_gpio(chip)->name, sizeof(chip->tea.card)); } #endif diff --git a/sound/pci/hda/hda_auto_parser.c b/sound/pci/hda/hda_auto_parser.c index 4dc01647753c..1a001ecf7f63 100644 --- a/sound/pci/hda/hda_auto_parser.c +++ b/sound/pci/hda/hda_auto_parser.c @@ -764,7 +764,7 @@ int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid, } if (!name) return 0; - strlcpy(label, name, maxlen); + strscpy(label, name, maxlen); return 1; } EXPORT_SYMBOL_GPL(snd_hda_get_pin_label); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 687216e74526..bc3b51eb8390 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -4009,7 +4009,7 @@ int snd_hda_add_imux_item(struct hda_codec *codec, sizeof(imux->items[imux->num_items].label), "%s %d", label, label_idx); else - strlcpy(imux->items[imux->num_items].label, label, + strscpy(imux->items[imux->num_items].label, label, sizeof(imux->items[imux->num_items].label)); imux->items[imux->num_items].index = index; imux->num_items++; diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index 80016b7b6849..9087981cd1f7 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -735,7 +735,7 @@ int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec, &pcm); if (err < 0) return err; - strlcpy(pcm->name, cpcm->name, sizeof(pcm->name)); + strscpy(pcm->name, cpcm->name, sizeof(pcm->name)); apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); if (apcm == NULL) { snd_device_free(chip->card, pcm); diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c index 136477ed46ae..9e97443795f8 100644 --- a/sound/pci/hda/hda_eld.c +++ b/sound/pci/hda/hda_eld.c @@ -260,7 +260,7 @@ int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e, codec_info(codec, "HDMI: out of range MNL %d\n", mnl); goto out_fail; } else - strlcpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1); + strscpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1); for (i = 0; i < e->sad_count; i++) { if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) { diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index 8060cc86dfea..5e40944e7342 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -5721,7 +5721,7 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, if (*str) return; - strlcpy(str, chip_name, len); + strscpy(str, chip_name, len); /* drop non-alnum chars after a space */ for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) { diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 770ad25f1907..694d95e3a46e 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -2037,7 +2037,7 @@ static int azx_first_init(struct azx *chip) return -EBUSY; strcpy(card->driver, "HDA-Intel"); - strlcpy(card->shortname, driver_short_names[chip->driver_type], + strscpy(card->shortname, driver_short_names[chip->driver_type], sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx irq %i", diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c index 588059428d8f..b8b568046592 100644 --- a/sound/pci/hda/hda_jack.c +++ b/sound/pci/hda/hda_jack.c @@ -530,7 +530,7 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, !is_jack_detectable(codec, nid); if (base_name) - strlcpy(name, base_name, sizeof(name)); + strscpy(name, base_name, sizeof(name)); else snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), NULL); if (phantom_jack) diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c index e57a55cebc5a..f0f8324b08b6 100644 --- a/sound/pci/ice1712/juli.c +++ b/sound/pci/ice1712/juli.c @@ -413,7 +413,7 @@ static struct snd_kcontrol *ctl_find(struct snd_card *card, { struct snd_ctl_elem_id sid = {0}; - strlcpy(sid.name, name, sizeof(sid.name)); + strscpy(sid.name, name, sizeof(sid.name)); sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; return snd_ctl_find_id(card, &sid); } diff --git a/sound/pci/ice1712/psc724.c b/sound/pci/ice1712/psc724.c index 7aa3f92040d0..82cf365cda10 100644 --- a/sound/pci/ice1712/psc724.c +++ b/sound/pci/ice1712/psc724.c @@ -189,12 +189,12 @@ static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected) /* notify about master speaker mute change */ memset(&elem_id, 0, sizeof(elem_id)); elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; - strlcpy(elem_id.name, "Master Speakers Playback Switch", + strscpy(elem_id.name, "Master Speakers Playback Switch", sizeof(elem_id.name)); kctl = snd_ctl_find_id(ice->card, &elem_id); snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); /* and headphone mute change */ - strlcpy(elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW].name, + strscpy(elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW].name, sizeof(elem_id.name)); kctl = snd_ctl_find_id(ice->card, &elem_id); snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c index 0e3e04aa9faf..0dfa093f7dca 100644 --- a/sound/pci/ice1712/quartet.c +++ b/sound/pci/ice1712/quartet.c @@ -771,7 +771,7 @@ static struct snd_kcontrol *ctl_find(struct snd_card *card, { struct snd_ctl_elem_id sid = {0}; - strlcpy(sid.name, name, sizeof(sid.name)); + strscpy(sid.name, name, sizeof(sid.name)); sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; return snd_ctl_find_id(card, &sid); } diff --git a/sound/pci/ice1712/wm8776.c b/sound/pci/ice1712/wm8776.c index d96008df880d..6eda86119dff 100644 --- a/sound/pci/ice1712/wm8776.c +++ b/sound/pci/ice1712/wm8776.c @@ -38,7 +38,7 @@ static void snd_wm8776_activate_ctl(struct snd_wm8776 *wm, unsigned int index_offset; memset(&elem_id, 0, sizeof(elem_id)); - strlcpy(elem_id.name, ctl_name, sizeof(elem_id.name)); + strscpy(elem_id.name, ctl_name, sizeof(elem_id.name)); elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; kctl = snd_ctl_find_id(card, &elem_id); if (!kctl) diff --git a/sound/pci/lola/lola.c b/sound/pci/lola/lola.c index cdd8db79bcfa..491c90f83fbc 100644 --- a/sound/pci/lola/lola.c +++ b/sound/pci/lola/lola.c @@ -669,7 +669,7 @@ static int lola_create(struct snd_card *card, struct pci_dev *pci, } strcpy(card->driver, "Lola"); - strlcpy(card->shortname, "Digigram Lola", sizeof(card->shortname)); + strscpy(card->shortname, "Digigram Lola", sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx irq %i", card->shortname, chip->bar[0].addr, chip->irq); diff --git a/sound/pci/lola/lola_pcm.c b/sound/pci/lola/lola_pcm.c index f647c7ed00c4..684faaf40f31 100644 --- a/sound/pci/lola/lola_pcm.c +++ b/sound/pci/lola/lola_pcm.c @@ -601,7 +601,7 @@ int lola_create_pcm(struct lola *chip) &pcm); if (err < 0) return err; - strlcpy(pcm->name, "Digigram Lola", sizeof(pcm->name)); + strscpy(pcm->name, "Digigram Lola", sizeof(pcm->name)); pcm->private_data = chip; for (i = 0; i < 2; i++) { if (chip->pcm[i].num_streams) diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 04e878a0f773..b66711574b1a 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6329,7 +6329,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, memset(&hdspm_version, 0, sizeof(hdspm_version)); hdspm_version.card_type = hdspm->io_type; - strlcpy(hdspm_version.cardname, hdspm->card_name, + strscpy(hdspm_version.cardname, hdspm->card_name, sizeof(hdspm_version.cardname)); hdspm_version.serial = hdspm->serial; hdspm_version.firmware_rev = hdspm->firmware_rev; diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c index 9554a0c506af..a6c1905039de 100644 --- a/sound/ppc/keywest.c +++ b/sound/ppc/keywest.c @@ -49,7 +49,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter) return -EINVAL; /* ignored */ memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "keywest", I2C_NAME_SIZE); + strscpy(info.type, "keywest", I2C_NAME_SIZE); info.addr = keywest_ctx->addr; client = i2c_new_client_device(adapter, &info); if (IS_ERR(client)) diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index daa58b5f941e..cad1cd1bfdf0 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -1707,7 +1707,7 @@ int q6afe_vote_lpass_core_hw(struct device *dev, uint32_t hw_block_id, pkt->hdr.token = hw_block_id; pkt->hdr.opcode = AFE_CMD_REMOTE_LPASS_CORE_HW_VOTE_REQUEST; vote_cfg->hw_block_id = hw_block_id; - strlcpy(vote_cfg->client_name, client_name, + strscpy(vote_cfg->client_name, client_name, sizeof(vote_cfg->client_name)); ret = afe_apr_send_pkt(afe, pkt, NULL, diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c index 6e670b3e92a0..6dd5659db44c 100644 --- a/sound/soc/sh/rcar/core.c +++ b/sound/soc/sh/rcar/core.c @@ -1472,7 +1472,7 @@ static int rsnd_kctrl_info(struct snd_kcontrol *kctrl, uinfo->value.enumerated.items = cfg->max; if (uinfo->value.enumerated.item >= cfg->max) uinfo->value.enumerated.item = cfg->max - 1; - strlcpy(uinfo->value.enumerated.name, + strscpy(uinfo->value.enumerated.name, cfg->texts[uinfo->value.enumerated.item], sizeof(uinfo->value.enumerated.name)); } else { diff --git a/sound/usb/bcd2000/bcd2000.c b/sound/usb/bcd2000/bcd2000.c index 010976d9ceb2..cd4a0bc6d278 100644 --- a/sound/usb/bcd2000/bcd2000.c +++ b/sound/usb/bcd2000/bcd2000.c @@ -300,7 +300,7 @@ static int bcd2000_init_midi(struct bcd2000 *bcd2k) if (ret < 0) return ret; - strlcpy(rmidi->name, bcd2k->card->shortname, sizeof(rmidi->name)); + strscpy(rmidi->name, bcd2k->card->shortname, sizeof(rmidi->name)); rmidi->info_flags = SNDRV_RAWMIDI_INFO_DUPLEX; rmidi->private_data = bcd2k; diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c index 3b6bb2cbe886..4981753652a7 100644 --- a/sound/usb/caiaq/audio.c +++ b/sound/usb/caiaq/audio.c @@ -804,7 +804,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev) } cdev->pcm->private_data = cdev; - strlcpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name)); + strscpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name)); memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback)); memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture)); diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c index 2af3b7eb0a88..e03481caf7f6 100644 --- a/sound/usb/caiaq/device.c +++ b/sound/usb/caiaq/device.c @@ -477,9 +477,9 @@ static int init_card(struct snd_usb_caiaqdev *cdev) usb_string(usb_dev, usb_dev->descriptor.iProduct, cdev->product_name, CAIAQ_USB_STR_LEN); - strlcpy(card->driver, MODNAME, sizeof(card->driver)); - strlcpy(card->shortname, cdev->product_name, sizeof(card->shortname)); - strlcpy(card->mixername, cdev->product_name, sizeof(card->mixername)); + strscpy(card->driver, MODNAME, sizeof(card->driver)); + strscpy(card->shortname, cdev->product_name, sizeof(card->shortname)); + strscpy(card->mixername, cdev->product_name, sizeof(card->mixername)); /* if the id was not passed as module option, fill it with a shortened * version of the product string which does not contain any diff --git a/sound/usb/caiaq/midi.c b/sound/usb/caiaq/midi.c index 512fbb3ee604..c656d0162432 100644 --- a/sound/usb/caiaq/midi.c +++ b/sound/usb/caiaq/midi.c @@ -125,7 +125,7 @@ int snd_usb_caiaq_midi_init(struct snd_usb_caiaqdev *device) if (ret < 0) return ret; - strlcpy(rmidi->name, device->product_name, sizeof(rmidi->name)); + strscpy(rmidi->name, device->product_name, sizeof(rmidi->name)); rmidi->info_flags = SNDRV_RAWMIDI_INFO_DUPLEX; rmidi->private_data = device; diff --git a/sound/usb/card.c b/sound/usb/card.c index d731ca62d599..85e79b9ecb08 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -474,7 +474,7 @@ static void usb_audio_make_shortname(struct usb_device *dev, else if (quirk && quirk->product_name) s = quirk->product_name; if (s && *s) { - strlcpy(card->shortname, s, sizeof(card->shortname)); + strscpy(card->shortname, s, sizeof(card->shortname)); return; } @@ -506,7 +506,7 @@ static void usb_audio_make_longname(struct usb_device *dev, if (preset && preset->profile_name) s = preset->profile_name; if (s && *s) { - strlcpy(card->longname, s, sizeof(card->longname)); + strscpy(card->longname, s, sizeof(card->longname)); return; } diff --git a/sound/usb/hiface/chip.c b/sound/usb/hiface/chip.c index b2d9623e9934..c2824188d142 100644 --- a/sound/usb/hiface/chip.c +++ b/sound/usb/hiface/chip.c @@ -80,12 +80,12 @@ static int hiface_chip_create(struct usb_interface *intf, return ret; } - strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver)); + strscpy(card->driver, DRIVER_NAME, sizeof(card->driver)); if (quirk && quirk->device_name) - strlcpy(card->shortname, quirk->device_name, sizeof(card->shortname)); + strscpy(card->shortname, quirk->device_name, sizeof(card->shortname)); else - strlcpy(card->shortname, "M2Tech generic audio", sizeof(card->shortname)); + strscpy(card->shortname, "M2Tech generic audio", sizeof(card->shortname)); strlcat(card->longname, card->shortname, sizeof(card->longname)); len = strlcat(card->longname, " at ", sizeof(card->longname)); diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c index d942179ca095..71f17f02f341 100644 --- a/sound/usb/hiface/pcm.c +++ b/sound/usb/hiface/pcm.c @@ -594,7 +594,7 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq) pcm->private_data = rt; pcm->private_free = hiface_pcm_free; - strlcpy(pcm->name, "USB-SPDIF Audio", sizeof(pcm->name)); + strscpy(pcm->name, "USB-SPDIF Audio", sizeof(pcm->name)); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pcm_ops); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0); diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index 412fcd817ecc..85fed017710e 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1556,7 +1556,7 @@ static void check_no_speaker_on_headset(struct snd_kcontrol *kctl, if (!found) return; - strlcpy(kctl->id.name, "Headphone", sizeof(kctl->id.name)); + strscpy(kctl->id.name, "Headphone", sizeof(kctl->id.name)); } static const struct usb_feature_control_info *get_feature_control_info(int control) @@ -1691,7 +1691,7 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer, break; default: if (!len) - strlcpy(kctl->id.name, audio_feature_info[control-1].name, + strscpy(kctl->id.name, audio_feature_info[control-1].name, sizeof(kctl->id.name)); break; } @@ -1770,7 +1770,7 @@ static void get_connector_control_name(struct usb_mixer_interface *mixer, int name_len = get_term_name(mixer->chip, term, name, name_size, 0); if (name_len == 0) - strlcpy(name, "Unknown", name_size); + strscpy(name, "Unknown", name_size); /* * sound/core/ctljack.c has a convention of naming jack controls @@ -2490,7 +2490,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name))) { /* nothing */ ; } else if (info->name) { - strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); + strscpy(kctl->id.name, info->name, sizeof(kctl->id.name)); } else { if (extension_unit) nameid = uac_extension_unit_iExtension(desc, state->mixer->protocol); @@ -2503,7 +2503,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, kctl->id.name, sizeof(kctl->id.name)); if (!len) - strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); + strscpy(kctl->id.name, name, sizeof(kctl->id.name)); } append_ctl_name(kctl, " "); append_ctl_name(kctl, valinfo->suffix); @@ -2743,7 +2743,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, kctl->id.name, sizeof(kctl->id.name), 0); /* ... or use the fixed string "USB" as the last resort */ if (!len) - strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); + strscpy(kctl->id.name, "USB", sizeof(kctl->id.name)); /* and add the proper suffix */ if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR || diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index df036a359f2f..abad1d61a536 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -2725,7 +2725,7 @@ static int snd_pioneer_djm_controls_info(struct snd_kcontrol *kctl, struct snd_c if (info->value.enumerated.item >= count) info->value.enumerated.item = count - 1; name = group->options[info->value.enumerated.item].name; - strlcpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name)); + strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name)); info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; info->count = 1; info->value.enumerated.items = count; diff --git a/sound/usb/mixer_scarlett.c b/sound/usb/mixer_scarlett.c index 49fcd2505443..691b95466d0f 100644 --- a/sound/usb/mixer_scarlett.c +++ b/sound/usb/mixer_scarlett.c @@ -569,7 +569,7 @@ static int add_new_ctl(struct usb_mixer_interface *mixer, } kctl->private_free = snd_usb_mixer_elem_free; - strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); + strscpy(kctl->id.name, name, sizeof(kctl->id.name)); err = snd_usb_mixer_add_control(&elem->head, kctl); if (err < 0) diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c index 4bbec56c7df3..560c2ade829d 100644 --- a/sound/usb/mixer_scarlett_gen2.c +++ b/sound/usb/mixer_scarlett_gen2.c @@ -961,7 +961,7 @@ static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer, } kctl->private_free = snd_usb_mixer_elem_free; - strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); + strscpy(kctl->id.name, name, sizeof(kctl->id.name)); err = snd_usb_mixer_add_control(&elem->head, kctl); if (err < 0) diff --git a/sound/usb/mixer_us16x08.c b/sound/usb/mixer_us16x08.c index bd63a9ce6a70..b7b6f3834ed5 100644 --- a/sound/usb/mixer_us16x08.c +++ b/sound/usb/mixer_us16x08.c @@ -1076,7 +1076,7 @@ static int add_new_ctl(struct usb_mixer_interface *mixer, else kctl->private_free = snd_usb_mixer_elem_free; - strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); + strscpy(kctl->id.name, name, sizeof(kctl->id.name)); err = snd_usb_mixer_add_control(&elem->head, kctl); if (err < 0) diff --git a/sound/x86/intel_hdmi_audio.c b/sound/x86/intel_hdmi_audio.c index 9f9fcd2749f2..5b351f4ca543 100644 --- a/sound/x86/intel_hdmi_audio.c +++ b/sound/x86/intel_hdmi_audio.c @@ -1790,7 +1790,7 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) /* setup private data which can be retrieved when required */ pcm->private_data = ctx; pcm->info_flags = 0; - strlcpy(pcm->name, card->shortname, strlen(card->shortname)); + strscpy(pcm->name, card->shortname, strlen(card->shortname)); /* setup the ops for playabck */ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &had_pcm_ops); diff --git a/sound/xen/xen_snd_front_cfg.c b/sound/xen/xen_snd_front_cfg.c index eda077c8087a..63b0398c3276 100644 --- a/sound/xen/xen_snd_front_cfg.c +++ b/sound/xen/xen_snd_front_cfg.c @@ -398,7 +398,7 @@ static int cfg_device(struct xen_snd_front_info *front_info, str = xenbus_read(XBT_NIL, device_path, XENSND_FIELD_DEVICE_NAME, NULL); if (!IS_ERR(str)) { - strlcpy(pcm_instance->name, str, sizeof(pcm_instance->name)); + strscpy(pcm_instance->name, str, sizeof(pcm_instance->name)); kfree(str); } -- cgit v1.2.3 From e8afdfdc8125801b1e28b5a54d2bd94cf2d59965 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 15 Jan 2021 10:57:58 +0100 Subject: ALSA: usb-audio: Convert remaining strlcpy() to strscpy() USB-audio driver still contains two calls of strlcpy() because the return size is evaluated. Basically it just checks whether the string is copied or not, but since strcpy() may return a negative error code, we should check the negative value and treat as filled. Link: https://lore.kernel.org/r/20210115095758.19707-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/mixer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sound') diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index 85fed017710e..c7da38348035 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -115,11 +115,14 @@ find_map(const struct usbmix_name_map *p, int unitid, int control) static int check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen) { + int len; + if (!p || !p->name) return 0; buflen--; - return strlcpy(buf, p->name, buflen); + len = strscpy(buf, p->name, buflen); + return len < 0 ? buflen : len; } /* ignore the error value if ignore_ctl_error flag is set */ @@ -151,12 +154,15 @@ static int check_mapped_selector_name(struct mixer_build *state, int unitid, int index, char *buf, int buflen) { const struct usbmix_selector_map *p; + int len; if (!state->selector_map) return 0; for (p = state->selector_map; p->id; p++) { - if (p->id == unitid && index < p->count) - return strlcpy(buf, p->names[index], buflen); + if (p->id == unitid && index < p->count) { + len = strscpy(buf, p->names[index], buflen); + return len < 0 ? buflen : len; + } } return 0; } -- cgit v1.2.3 From 42ef170d57d8fc59b36619b00cadacac84ecfb90 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 15 Jan 2021 11:04:37 +0100 Subject: ALSA: usb-audio: Convert the last strlcpy() usage The last remaining usage of strlcpy() in USB-audio driver is the setup of the card longname string. Basically we need to know whether any non-empty string is set or not, and no real length is needed. Refactor the code and use strscpy() instead. After this change, strlcpy() is gone from all sound/* code. Link: https://lore.kernel.org/r/20210115100437.20906-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/card.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'sound') diff --git a/sound/usb/card.c b/sound/usb/card.c index 85e79b9ecb08..45407cb81b66 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -514,18 +514,17 @@ static void usb_audio_make_longname(struct usb_device *dev, s = preset->vendor_name; else if (quirk && quirk->vendor_name) s = quirk->vendor_name; + *card->longname = 0; if (s && *s) { - len = strlcpy(card->longname, s, sizeof(card->longname)); + strscpy(card->longname, s, sizeof(card->longname)); } else { /* retrieve the vendor and device strings as longname */ if (dev->descriptor.iManufacturer) - len = usb_string(dev, dev->descriptor.iManufacturer, - card->longname, sizeof(card->longname)); - else - len = 0; + usb_string(dev, dev->descriptor.iManufacturer, + card->longname, sizeof(card->longname)); /* we don't really care if there isn't any vendor string */ } - if (len > 0) { + if (*card->longname) { strim(card->longname); if (*card->longname) strlcat(card->longname, " ", sizeof(card->longname)); -- cgit v1.2.3 From 9a08676fc5968be8575ee2fa8926e55d8aef166c Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Fri, 15 Jan 2021 12:56:23 +0900 Subject: ALSA: dice: add support for Lexicon I-ONIX FW810s I-ONIX FW810s was shipped in Lexicon brand of HARMAN International industries, Inc 2009. The model uses TCD2220 ASIC as its communication engine. TCAT general protocol is supported, its extension isn't. This patch adds support for the model with hard-coded stream formats. $ python3 ~/git/linux-firewire-utils/src/crpp < /sys/bus/firewire/devices/fw1/config_rom ROM header and bus information block ----------------------------------------------------------------- 400 04042b91 bus_info_length 4, crc_length 4, crc 11153 404 31333934 bus_name "1394" 408 e0008102 irmc 1, cmc 1, isc 1, bmc 0, cyc_clk_acc 0, max_rec 8 (512) 40c 000fd720 company_id 000fd7 | 410 007d7ecf device_id 20007d7ecf | EUI-64 000fd720007d7ecf root directory ----------------------------------------------------------------- 414 00064c2d directory_length 6, crc 19501 418 03000fd7 vendor 41c 8100000a --> descriptor leaf at 444 420 17000001 model 424 8100000d --> descriptor leaf at 458 428 0c0087c0 node capabilities per IEEE 1394 42c d1000001 --> unit directory at 430 unit directory at 430 ----------------------------------------------------------------- 430 000438f2 directory_length 4, crc 14578 434 12000fd7 specifier id 438 13000001 version 43c 17000001 model 440 8100000d --> descriptor leaf at 474 descriptor leaf at 444 ----------------------------------------------------------------- 444 000489d5 leaf_length 4, crc 35285 448 00000000 textual descriptor 44c 00000000 minimal ASCII 450 4c657869 "Lexi" 454 636f6e00 "con" descriptor leaf at 458 ----------------------------------------------------------------- 458 0006594b leaf_length 6, crc 22859 45c 00000000 textual descriptor 460 00000000 minimal ASCII 464 492d4f4e "I-ON" 468 49585f46 "IX_F" 46c 57383130 "W810" 470 53000000 "S" descriptor leaf at 474 ----------------------------------------------------------------- 474 0006594b leaf_length 6, crc 22859 478 00000000 textual descriptor 47c 00000000 minimal ASCII 480 492d4f4e "I-ON" 484 49585f46 "IX_F" 488 57383130 "W810" 48c 53000000 "S" Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20210115035623.148580-1-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/dice/Makefile | 3 ++- sound/firewire/dice/dice-harman.c | 26 ++++++++++++++++++++++++++ sound/firewire/dice/dice.c | 12 ++++++++++++ sound/firewire/dice/dice.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 sound/firewire/dice/dice-harman.c (limited to 'sound') diff --git a/sound/firewire/dice/Makefile b/sound/firewire/dice/Makefile index 7a62dafd0f78..9bf7b960a720 100644 --- a/sound/firewire/dice/Makefile +++ b/sound/firewire/dice/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only snd-dice-objs := dice-transaction.o dice-stream.o dice-proc.o dice-midi.o \ dice-pcm.o dice-hwdep.o dice.o dice-tcelectronic.o \ - dice-alesis.o dice-extension.o dice-mytek.o dice-presonus.o + dice-alesis.o dice-extension.o dice-mytek.o dice-presonus.o \ + dice-harman.o obj-$(CONFIG_SND_DICE) += snd-dice.o diff --git a/sound/firewire/dice/dice-harman.c b/sound/firewire/dice/dice-harman.c new file mode 100644 index 000000000000..a8ca00c397e8 --- /dev/null +++ b/sound/firewire/dice/dice-harman.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +// dice-harman.c - a part of driver for DICE based devices +// +// Copyright (c) 2021 Takashi Sakamoto +// +// Licensed under the terms of the GNU General Public License, version 2. + +#include "dice.h" + +int snd_dice_detect_harman_formats(struct snd_dice *dice) +{ + int i; + + // Lexicon I-ONYX FW810s supports sampling transfer frequency up to + // 96.0 kHz, 12 PCM channels and 1 MIDI channel in its first tx stream + // , 10 PCM channels and 1 MIDI channel in its first rx stream for all + // of the frequencies. + for (i = 0; i < 2; ++i) { + dice->tx_pcm_chs[0][i] = 12; + dice->tx_midi_ports[0] = 1; + dice->rx_pcm_chs[0][i] = 10; + dice->rx_midi_ports[0] = 1; + } + + return 0; +} diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c index 06c94f009dfb..107a81691f0e 100644 --- a/sound/firewire/dice/dice.c +++ b/sound/firewire/dice/dice.c @@ -20,10 +20,12 @@ MODULE_LICENSE("GPL v2"); #define OUI_MYTEK 0x001ee8 #define OUI_SSL 0x0050c2 // Actually ID reserved by IEEE. #define OUI_PRESONUS 0x000a92 +#define OUI_HARMAN 0x000fd7 #define DICE_CATEGORY_ID 0x04 #define WEISS_CATEGORY_ID 0x00 #define LOUD_CATEGORY_ID 0x10 +#define HARMAN_CATEGORY_ID 0x20 #define MODEL_ALESIS_IO_BOTH 0x000001 @@ -56,6 +58,8 @@ static int check_dice_category(struct fw_unit *unit) category = WEISS_CATEGORY_ID; else if (vendor == OUI_LOUD) category = LOUD_CATEGORY_ID; + else if (vendor == OUI_HARMAN) + category = HARMAN_CATEGORY_ID; else category = DICE_CATEGORY_ID; if (device->config_rom[3] != ((vendor << 8) | category) || @@ -388,6 +392,14 @@ static const struct ieee1394_device_id dice_id_table[] = { .model_id = 0x000008, .driver_data = (kernel_ulong_t)snd_dice_detect_presonus_formats, }, + // Lexicon I-ONYX FW810S. + { + .match_flags = IEEE1394_MATCH_VENDOR_ID | + IEEE1394_MATCH_MODEL_ID, + .vendor_id = OUI_HARMAN, + .model_id = 0x000001, + .driver_data = (kernel_ulong_t)snd_dice_detect_harman_formats, + }, { .match_flags = IEEE1394_MATCH_VERSION, .version = DICE_INTERFACE, diff --git a/sound/firewire/dice/dice.h b/sound/firewire/dice/dice.h index 7fbffcab94c2..adc6f7c84460 100644 --- a/sound/firewire/dice/dice.h +++ b/sound/firewire/dice/dice.h @@ -233,5 +233,6 @@ int snd_dice_detect_alesis_mastercontrol_formats(struct snd_dice *dice); int snd_dice_detect_extension_formats(struct snd_dice *dice); int snd_dice_detect_mytek_formats(struct snd_dice *dice); int snd_dice_detect_presonus_formats(struct snd_dice *dice); +int snd_dice_detect_harman_formats(struct snd_dice *dice); #endif -- cgit v1.2.3 From 669f65eaeb969ef60811939a5811479d3e8087af Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 14 Jan 2021 13:54:11 +0100 Subject: ALSA: pci: Simplify with dma_set_mask_and_coherent() Many PCI drivers still have two explicit calls of dma_set_mask() and dma_set_coherent_mask(). Let's simplify with dma_set_mask_and_coherent(). Link: https://lore.kernel.org/r/20210114125412.993-2-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/pci/ad1889.c | 3 +-- sound/pci/ali5451/ali5451.c | 3 +-- sound/pci/als300.c | 3 +-- sound/pci/als4000.c | 3 +-- sound/pci/au88x0/au88x0.c | 3 +-- sound/pci/aw2/aw2-alsa.c | 3 +-- sound/pci/azt3328.c | 3 +-- sound/pci/ca0106/ca0106_main.c | 3 +-- sound/pci/cs5535audio/cs5535audio.c | 3 +-- sound/pci/ctxfi/cthw20k1.c | 8 ++------ sound/pci/ctxfi/cthw20k2.c | 8 ++------ sound/pci/es1938.c | 3 +-- sound/pci/es1968.c | 3 +-- sound/pci/hda/hda_intel.c | 8 ++------ sound/pci/ice1712/ice1712.c | 3 +-- sound/pci/maestro3.c | 3 +-- sound/pci/sonicvibes.c | 3 +-- sound/pci/trident/trident_main.c | 3 +-- 18 files changed, 21 insertions(+), 48 deletions(-) (limited to 'sound') diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c index 5d42c42491bf..5d835d2af054 100644 --- a/sound/pci/ad1889.c +++ b/sound/pci/ad1889.c @@ -857,8 +857,7 @@ snd_ad1889_create(struct snd_card *card, return err; /* check PCI availability (32bit DMA) */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_err(card->dev, "error setting 32-bit DMA mask.\n"); pci_disable_device(pci); return -ENXIO; diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c index 4462375d2d82..51f24796f03f 100644 --- a/sound/pci/ali5451/ali5451.c +++ b/sound/pci/ali5451/ali5451.c @@ -2057,8 +2057,7 @@ static int snd_ali_create(struct snd_card *card, if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 31 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(31)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(31)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31))) { dev_err(card->dev, "architecture does not support 31bit PCI busmaster DMA\n"); pci_disable_device(pci); diff --git a/sound/pci/als300.c b/sound/pci/als300.c index 8d2471ea090b..1dc8c4ed0592 100644 --- a/sound/pci/als300.c +++ b/sound/pci/als300.c @@ -625,8 +625,7 @@ static int snd_als300_create(struct snd_card *card, if ((err = pci_enable_device(pci)) < 0) return err; - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { dev_err(card->dev, "error setting 28bit DMA mask\n"); pci_disable_device(pci); return -ENXIO; diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index ba6390e9a694..2edc7455285a 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c @@ -837,8 +837,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci, return err; } /* check, if we can restrict PCI DMA transfers to 24 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n"); pci_disable_device(pci); return -ENXIO; diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c index be276fb3f5af..5dd98e6ff34b 100644 --- a/sound/pci/au88x0/au88x0.c +++ b/sound/pci/au88x0/au88x0.c @@ -151,8 +151,7 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip) // check PCI availability (DMA). if ((err = pci_enable_device(pci)) < 0) return err; - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_err(card->dev, "error to set DMA mask\n"); pci_disable_device(pci); return -ENXIO; diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c index f1865afedc59..43396849a01c 100644 --- a/sound/pci/aw2/aw2-alsa.c +++ b/sound/pci/aw2/aw2-alsa.c @@ -236,8 +236,7 @@ static int snd_aw2_create(struct snd_card *card, pci_set_master(pci); /* check PCI availability (32bit DMA) */ - if ((dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) || - (dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0)) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_err(card->dev, "Impossible to set 32bit mask DMA\n"); pci_disable_device(pci); return -ENXIO; diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index 77c7030ebbfa..e3ea72a2116b 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c @@ -2379,8 +2379,7 @@ snd_azf3328_create(struct snd_card *card, chip->irq = -1; /* check if we can restrict PCI DMA transfers to 24 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(card->dev, "architecture does not support 24bit PCI busmaster DMA\n" ); diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c index c189f70c82cb..ee20f9a1aae9 100644 --- a/sound/pci/ca0106/ca0106_main.c +++ b/sound/pci/ca0106/ca0106_main.c @@ -1605,8 +1605,7 @@ static int snd_ca0106_create(int dev, struct snd_card *card, err = pci_enable_device(pci); if (err < 0) return err; - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_err(card->dev, "error to set 32bit mask DMA\n"); pci_disable_device(pci); return -ENXIO; diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c index 11ce3c4589fa..359bc6af8670 100644 --- a/sound/pci/cs5535audio/cs5535audio.c +++ b/sound/pci/cs5535audio/cs5535audio.c @@ -269,8 +269,7 @@ static int snd_cs5535audio_create(struct snd_card *card, if ((err = pci_enable_device(pci)) < 0) return err; - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_warn(card->dev, "unable to get 32bit dma\n"); err = -ENXIO; goto pcifail; diff --git a/sound/pci/ctxfi/cthw20k1.c b/sound/pci/ctxfi/cthw20k1.c index 108ab449c968..0cea4982ed7d 100644 --- a/sound/pci/ctxfi/cthw20k1.c +++ b/sound/pci/ctxfi/cthw20k1.c @@ -1901,12 +1901,8 @@ static int hw_card_start(struct hw *hw) return err; /* Set DMA transfer mask */ - if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) { - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits)); - } else { - dma_set_mask(&pci->dev, DMA_BIT_MASK(32)); - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)); - } + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(dma_bits))) + dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)); if (!hw->io_base) { err = pci_request_regions(pci, "XFi"); diff --git a/sound/pci/ctxfi/cthw20k2.c b/sound/pci/ctxfi/cthw20k2.c index fc1bc18caee9..a855fb8c58bd 100644 --- a/sound/pci/ctxfi/cthw20k2.c +++ b/sound/pci/ctxfi/cthw20k2.c @@ -2026,12 +2026,8 @@ static int hw_card_start(struct hw *hw) return err; /* Set DMA transfer mask */ - if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) { - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits)); - } else { - dma_set_mask(&pci->dev, DMA_BIT_MASK(32)); - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)); - } + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(dma_bits))) + dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)); if (!hw->io_base) { err = pci_request_regions(pci, "XFi"); diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index 09704a78d799..3b5d68ce9dd5 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c @@ -1560,8 +1560,7 @@ static int snd_es1938_create(struct snd_card *card, if ((err = pci_enable_device(pci)) < 0) return err; /* check, if we can restrict PCI DMA transfers to 24 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(card->dev, "architecture does not support 24bit PCI busmaster DMA\n"); pci_disable_device(pci); diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c index c6be14c4f311..747fa69bb1c9 100644 --- a/sound/pci/es1968.c +++ b/sound/pci/es1968.c @@ -2668,8 +2668,7 @@ static int snd_es1968_create(struct snd_card *card, if ((err = pci_enable_device(pci)) < 0) return err; /* check, if we can restrict PCI DMA transfers to 28 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { dev_err(card->dev, "architecture does not support 28bit PCI busmaster DMA\n"); pci_disable_device(pci); diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 694d95e3a46e..292d3ff44709 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1967,12 +1967,8 @@ static int azx_first_init(struct azx *chip) /* allow 64bit DMA address if supported by H/W */ if (!(gcap & AZX_GCAP_64OK)) dma_bits = 32; - if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(dma_bits))) { - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(dma_bits)); - } else { - dma_set_mask(&pci->dev, DMA_BIT_MASK(32)); - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32)); - } + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(dma_bits))) + dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)); /* read number of streams from GCAP register instead of using * hardcoded value diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c index 73e1e5400506..f814dbbec2a4 100644 --- a/sound/pci/ice1712/ice1712.c +++ b/sound/pci/ice1712/ice1712.c @@ -2486,8 +2486,7 @@ static int snd_ice1712_create(struct snd_card *card, if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 28 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { dev_err(card->dev, "architecture does not support 28bit PCI busmaster DMA\n"); pci_disable_device(pci); diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index f622c2a6f746..d2c2cd6006f0 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c @@ -2532,8 +2532,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, return -EIO; /* check, if we can restrict PCI DMA transfers to 28 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(28)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { dev_err(card->dev, "architecture does not support 28bit PCI busmaster DMA\n"); pci_disable_device(pci); diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index bd805e416e12..26fd1d08c179 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c @@ -1230,8 +1230,7 @@ static int snd_sonicvibes_create(struct snd_card *card, if ((err = pci_enable_device(pci)) < 0) return err; /* check, if we can restrict PCI DMA transfers to 24 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(card->dev, "architecture does not support 24bit PCI busmaster DMA\n"); pci_disable_device(pci); diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index 8d0d0d8335ec..20145143f6a6 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c @@ -3497,8 +3497,7 @@ int snd_trident_create(struct snd_card *card, if ((err = pci_enable_device(pci)) < 0) return err; /* check, if we can restrict PCI DMA transfers to 30 bits */ - if (dma_set_mask(&pci->dev, DMA_BIT_MASK(30)) < 0 || - dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(30)) < 0) { + if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(30))) { dev_err(card->dev, "architecture does not support 30bit PCI busmaster DMA\n"); pci_disable_device(pci); -- cgit v1.2.3 From 915183b62276191ef767e00e683f4c085c4cc325 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 14 Jan 2021 13:54:12 +0100 Subject: ALSA: x86: Simplify with dma_set_mask_and_coherent() LPE driver still has explicit calls of dma_set_mask() and dma_set_coherent_mask(). Let's simplify with dma_set_mask_and_coherent(). Link: https://lore.kernel.org/r/20210114125412.993-3-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/x86/intel_hdmi_audio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/x86/intel_hdmi_audio.c b/sound/x86/intel_hdmi_audio.c index 5b351f4ca543..1d66c3a4fb10 100644 --- a/sound/x86/intel_hdmi_audio.c +++ b/sound/x86/intel_hdmi_audio.c @@ -1770,8 +1770,7 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) card_ctx->irq = irq; /* only 32bit addressable */ - dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); + dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); init_channel_allocations(); -- cgit v1.2.3 From b952ac76a20bc0b23cd7e22de19fb407713238a3 Mon Sep 17 00:00:00 2001 From: Olivia Mackintosh Date: Mon, 18 Jan 2021 13:06:21 +0000 Subject: ALSA: usb-audio: Add support for Pioneer DJM-750 This adds the Pioneer DJ DJM-750 to the quirks table and ensures skip_pioneer_sync_ep() is (also) called: this device uses the vendor ID of 0x08e4 (I'm not sure why they use multiple vendor IDs but many just like to be awkward it seems). Playback on all 8 channels works. I'll likely keep this working in the future and submit futher patches and improvements as necessary. Signed-off-by: Olivia Mackintosh Link: https://lore.kernel.org/r/20210118130621.77miiie47wp7mump@base.nu Signed-off-by: Takashi Iwai --- sound/usb/implicit.c | 3 ++- sound/usb/quirks-table.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/usb/implicit.c b/sound/usb/implicit.c index 521cc846d9d9..e7216d0b860d 100644 --- a/sound/usb/implicit.c +++ b/sound/usb/implicit.c @@ -302,7 +302,8 @@ static int audioformat_implicit_fb_quirk(struct snd_usb_audio *chip, /* Pioneer devices with vendor spec class */ if (attr == USB_ENDPOINT_SYNC_ASYNC && alts->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC && - USB_ID_VENDOR(chip->usb_id) == 0x2b73 /* Pioneer */) { + (USB_ID_VENDOR(chip->usb_id) == 0x2b73 || /* Pioneer */ + USB_ID_VENDOR(chip->usb_id) == 0x08e4 /* Pioneer */)) { if (skip_pioneer_sync_ep(chip, fmt, alts)) return 1; } diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index c8a4bdf18207..93d55cd1a5a4 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -3757,6 +3757,66 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"), } } }, +{ + /* + * Pioneer DJ DJM-750 + * 8 channels playback & 8 channels capture @ 44.1/48/96kHz S24LE + */ + USB_DEVICE_VENDOR_SPEC(0x08e4, 0x017f), + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { + .ifnum = QUIRK_ANY_INTERFACE, + .type = QUIRK_COMPOSITE, + .data = (const struct snd_usb_audio_quirk[]) { + { + .ifnum = 0, + .type = QUIRK_AUDIO_FIXED_ENDPOINT, + .data = &(const struct audioformat) { + .formats = SNDRV_PCM_FMTBIT_S24_3LE, + .channels = 8, + .iface = 0, + .altsetting = 1, + .altset_idx = 1, + .endpoint = 0x05, + .ep_attr = USB_ENDPOINT_XFER_ISOC| + USB_ENDPOINT_SYNC_ASYNC, + .rates = SNDRV_PCM_RATE_44100| + SNDRV_PCM_RATE_48000| + SNDRV_PCM_RATE_96000, + .rate_min = 44100, + .rate_max = 96000, + .nr_rates = 3, + .rate_table = (unsigned int[]) { 44100, 48000, 96000 } + } + }, + { + .ifnum = 0, + .type = QUIRK_AUDIO_FIXED_ENDPOINT, + .data = &(const struct audioformat) { + .formats = SNDRV_PCM_FMTBIT_S24_3LE, + .channels = 8, + .iface = 0, + .altsetting = 1, + .altset_idx = 1, + .endpoint = 0x86, + .ep_idx = 1, + .ep_attr = USB_ENDPOINT_XFER_ISOC| + USB_ENDPOINT_SYNC_ASYNC| + USB_ENDPOINT_USAGE_IMPLICIT_FB, + .rates = SNDRV_PCM_RATE_44100| + SNDRV_PCM_RATE_48000| + SNDRV_PCM_RATE_96000, + .rate_min = 44100, + .rate_max = 96000, + .nr_rates = 3, + .rate_table = (unsigned int[]) { 44100, 48000, 96000 } + } + }, + { + .ifnum = -1 + } + } + } +}, #undef USB_DEVICE_VENDOR_SPEC #undef USB_AUDIO_DEVICE -- cgit v1.2.3 From 086b957cc17f53f03bae9d2baf930ac51cf68b99 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 20 Jan 2021 22:39:31 +0100 Subject: ALSA: usb-audio: Skip the clock selector inquiry for single connections The current USB-audio driver gets an error at probing NUX MG-300 about parsing the clocks. This is because the firmware doesn't return the proper connection of the clock selector that is connected to a single clock; it's likely that the firmware was lazy^w optimized and the inquiry wasn't handled. Actually it makes little sense to inquire and set up the single connection explicitly. This patch fixes the issue by simply skipping the clock selector inquiry if it's a single connection. Reported-by: Mike Oliphant Link: https://lore.kernel.org/r/20210120213932.1971-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/clock.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sound') diff --git a/sound/usb/clock.c b/sound/usb/clock.c index dc68ed65e478..8243652d5604 100644 --- a/sound/usb/clock.c +++ b/sound/usb/clock.c @@ -298,6 +298,11 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip, if (selector) { int ret, i, cur; + if (selector->bNrInPins == 1) { + ret = 1; + goto find_source; + } + /* the entity ID we are looking for is a selector. * find out what it currently selects */ ret = uac_clock_selector_get_val(chip, selector->bClockID); @@ -314,6 +319,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip, return -EINVAL; } + find_source: cur = ret; ret = __uac_clock_find_source(chip, fmt, selector->baCSourceID[ret - 1], -- cgit v1.2.3 From 85db1cfb13e37d24be225739dc0e2da478dd2c1c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 20 Jan 2021 22:39:32 +0100 Subject: ALSA: usb-audio: Fix "RANGE setting not yet supported" errors At probing a UAC2/UAC3 device like NUX MG-300 USB interface, we get error messages "RANGE setting not yet supported". It comes the place where the driver tries to determine the resolution of mixer volumes via SET_CUR_RES and GET_CUR_RES verbs. Those verbs aren't supported on UAC2 and UAC3, hence the driver warns like the above. Although the driver handles this error and works as expected, it's still ugly to show such errors unnecessarily. This patch papers over the errors by applying the resolution detection only for UAC1 and skipping it for UAC2/UAC3. Reported-by: Mike Oliphant Link: https://lore.kernel.org/r/20210120213932.1971-2-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/mixer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index c7da38348035..b1c78db0d470 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -1238,7 +1238,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval, (cval->control << 8) | minchn, &cval->res) < 0) { cval->res = 1; - } else { + } else if (cval->head.mixer->protocol == UAC_VERSION_1) { int last_valid_res = cval->res; while (cval->res > 1) { -- cgit v1.2.3 From d15f73315deb45fccbf44c6a4024d430bbb26b0c Mon Sep 17 00:00:00 2001 From: Jiapeng Zhong Date: Mon, 18 Jan 2021 16:27:49 +0800 Subject: ALSA: hda: boolean values to a bool variable Fix the following coccicheck warnings: ./sound/pci/hda/patch_conexant.c:570:2-20: WARNING: Assignment of 0/1 to bool variable. Reported-by: Abaci Robot Signed-off-by: Jiapeng Zhong Link: https://lore.kernel.org/r/1610958469-65856-1-git-send-email-abaci-bugfix@linux.alibaba.com Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_conexant.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index d49cc4409d59..f2aa226d1373 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -567,7 +567,7 @@ static void cxt_fixup_mute_led_eapd(struct hda_codec *codec, if (action == HDA_FIXUP_ACT_PRE_PROBE) { spec->mute_led_eapd = 0x1b; - spec->dynamic_eapd = 1; + spec->dynamic_eapd = true; snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led); } } -- cgit v1.2.3 From 62c2b4be0d858bb4d381868459fb8f82c3b58a21 Mon Sep 17 00:00:00 2001 From: Jiapeng Zhong Date: Mon, 25 Jan 2021 15:17:27 +0800 Subject: ALSA: hda: Assign boolean values to a bool variable Fix the following coccicheck warnings: ./sound/pci/hda/hda_intel.c:2309:3-23: WARNING: Assignment of 0/1 to bool variable. Reported-by: Abaci Robot Signed-off-by: Jiapeng Zhong Link: https://lore.kernel.org/r/1611559047-106928-1-git-send-email-abaci-bugfix@linux.alibaba.com Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_intel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 7f0000e2c953..6c439f377a7e 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -2300,7 +2300,7 @@ static int azx_probe_continue(struct azx *chip) /* HSW/BDW controllers need this power */ if (CONTROLLER_IN_GPU(pci)) - hda->need_i915_power = 1; + hda->need_i915_power = true; } /* Request display power well for the HDA controller or codec. For -- cgit v1.2.3 From 00f3a4113c73823e22bb30129d3ec0523706a158 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 25 Jan 2021 14:12:54 +0300 Subject: ALSA: oxfw: remove an unnecessary condition in hwdep_read() Smatch complains that "count" isn't clamped properly and "oxfw->dev_lock_changed" is false then it leads to an information leak. But it turns out that "oxfw->dev_lock_changed" is always set and the condition can be removed. Signed-off-by: Dan Carpenter Acked-by: Takashi Sakamoto Link: https://lore.kernel.org/r/YA6ntkBxT/4DJ4YK@mwanda Signed-off-by: Takashi Iwai --- sound/firewire/oxfw/oxfw-hwdep.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'sound') diff --git a/sound/firewire/oxfw/oxfw-hwdep.c b/sound/firewire/oxfw/oxfw-hwdep.c index 9e1b3e151bad..a0fe99618554 100644 --- a/sound/firewire/oxfw/oxfw-hwdep.c +++ b/sound/firewire/oxfw/oxfw-hwdep.c @@ -35,13 +35,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, } memset(&event, 0, sizeof(event)); - if (oxfw->dev_lock_changed) { - event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; - event.lock_status.status = (oxfw->dev_lock_count > 0); - oxfw->dev_lock_changed = false; + event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; + event.lock_status.status = (oxfw->dev_lock_count > 0); + oxfw->dev_lock_changed = false; - count = min_t(long, count, sizeof(event.lock_status)); - } + count = min_t(long, count, sizeof(event.lock_status)); spin_unlock_irq(&oxfw->lock); -- cgit v1.2.3 From f4514249d6483effbc08984ed908fc741de798f0 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 25 Jan 2021 14:13:44 +0300 Subject: ALSA: fireface: remove unnecessary condition in hwdep_read() Smatch complains that "count" is not clamped when "ff->dev_lock_changed" and it leads to an information leak. Fortunately, that's not actually possible and the condition can be deleted. Signed-off-by: Dan Carpenter Acked-by: Takashi Sakamoto Link: https://lore.kernel.org/r/YA6n6I8EcNAO5ZFs@mwanda Signed-off-by: Takashi Iwai --- sound/firewire/fireface/ff-hwdep.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'sound') diff --git a/sound/firewire/fireface/ff-hwdep.c b/sound/firewire/fireface/ff-hwdep.c index 4b2e0dff5ddb..ea64a2a41eea 100644 --- a/sound/firewire/fireface/ff-hwdep.c +++ b/sound/firewire/fireface/ff-hwdep.c @@ -35,13 +35,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, } memset(&event, 0, sizeof(event)); - if (ff->dev_lock_changed) { - event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; - event.lock_status.status = (ff->dev_lock_count > 0); - ff->dev_lock_changed = false; + event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; + event.lock_status.status = (ff->dev_lock_count > 0); + ff->dev_lock_changed = false; - count = min_t(long, count, sizeof(event.lock_status)); - } + count = min_t(long, count, sizeof(event.lock_status)); spin_unlock_irq(&ff->lock); -- cgit v1.2.3 From e32da5eb627c9dd60fd245cb5beb3079e96890d1 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 25 Jan 2021 23:02:08 +0900 Subject: ALSA: bebob: remove an unnecessary condition in hwdep_read() Drivers in ALSA firewire stack supports eventing to userspace applications via ALSA hwdep interface. All of the drivers supports stream lock events. Some of them supports their unique events according to specification of target device. ALSA bebob driver supports the stream lock event only. In the case, it's enough to check condition only in loop with process blocking. However, current implementation check it again after breaking the loop. This commit removes the redundant check. Reported-by: Dan Carpenter Reported-by: Christophe JAILLET Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20210125140208.26318-1-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/bebob/bebob_hwdep.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'sound') diff --git a/sound/firewire/bebob/bebob_hwdep.c b/sound/firewire/bebob/bebob_hwdep.c index 8677e3ec8d14..6f9331655d43 100644 --- a/sound/firewire/bebob/bebob_hwdep.c +++ b/sound/firewire/bebob/bebob_hwdep.c @@ -37,11 +37,9 @@ hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, memset(&event, 0, sizeof(event)); count = min_t(long, count, sizeof(event.lock_status)); - if (bebob->dev_lock_changed) { - event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; - event.lock_status.status = (bebob->dev_lock_count > 0); - bebob->dev_lock_changed = false; - } + event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; + event.lock_status.status = (bebob->dev_lock_count > 0); + bebob->dev_lock_changed = false; spin_unlock_irq(&bebob->lock); -- cgit v1.2.3 From 3a465f027a33cbd2af74f882ad41729583195e8f Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Wed, 20 Jan 2021 03:31:49 +0300 Subject: ALSA: hda/tegra: Use clk_bulk helpers Use clk_bulk helpers to make code cleaner. Note that this patch changed the order in which clocks are enabled to make code look nicer, but this doesn't matter in terms of hardware. Tested-by: Peter Geis # Ouya T30 audio works Tested-by: Matt Merhar # Ouya T30 boot-tested Tested-by: Nicolas Chauvet # TK1 boot-tested Acked-by: Thierry Reding Signed-off-by: Dmitry Osipenko Link: https://lore.kernel.org/r/20210120003154.26749-2-digetx@gmail.com Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_tegra.c | 68 +++++++---------------------------------------- 1 file changed, 9 insertions(+), 59 deletions(-) (limited to 'sound') diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 361cf2041911..a25bf7083c28 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -70,9 +70,8 @@ struct hda_tegra { struct azx chip; struct device *dev; - struct clk *hda_clk; - struct clk *hda2codec_2x_clk; - struct clk *hda2hdmi_clk; + struct clk_bulk_data clocks[3]; + unsigned int nclocks; void __iomem *regs; struct work_struct probe_work; }; @@ -113,36 +112,6 @@ static void hda_tegra_init(struct hda_tegra *hda) writel(v, hda->regs + HDA_IPFS_INTR_MASK); } -static int hda_tegra_enable_clocks(struct hda_tegra *data) -{ - int rc; - - rc = clk_prepare_enable(data->hda_clk); - if (rc) - return rc; - rc = clk_prepare_enable(data->hda2codec_2x_clk); - if (rc) - goto disable_hda; - rc = clk_prepare_enable(data->hda2hdmi_clk); - if (rc) - goto disable_codec_2x; - - return 0; - -disable_codec_2x: - clk_disable_unprepare(data->hda2codec_2x_clk); -disable_hda: - clk_disable_unprepare(data->hda_clk); - return rc; -} - -static void hda_tegra_disable_clocks(struct hda_tegra *data) -{ - clk_disable_unprepare(data->hda2hdmi_clk); - clk_disable_unprepare(data->hda2codec_2x_clk); - clk_disable_unprepare(data->hda_clk); -} - /* * power management */ @@ -186,7 +155,7 @@ static int __maybe_unused hda_tegra_runtime_suspend(struct device *dev) azx_stop_chip(chip); azx_enter_link_reset(chip); } - hda_tegra_disable_clocks(hda); + clk_bulk_disable_unprepare(hda->nclocks, hda->clocks); return 0; } @@ -198,7 +167,7 @@ static int __maybe_unused hda_tegra_runtime_resume(struct device *dev) struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); int rc; - rc = hda_tegra_enable_clocks(hda); + rc = clk_bulk_prepare_enable(hda->nclocks, hda->clocks); if (rc != 0) return rc; if (chip && chip->running) { @@ -268,29 +237,6 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev) return 0; } -static int hda_tegra_init_clk(struct hda_tegra *hda) -{ - struct device *dev = hda->dev; - - hda->hda_clk = devm_clk_get(dev, "hda"); - if (IS_ERR(hda->hda_clk)) { - dev_err(dev, "failed to get hda clock\n"); - return PTR_ERR(hda->hda_clk); - } - hda->hda2codec_2x_clk = devm_clk_get(dev, "hda2codec_2x"); - if (IS_ERR(hda->hda2codec_2x_clk)) { - dev_err(dev, "failed to get hda2codec_2x clock\n"); - return PTR_ERR(hda->hda2codec_2x_clk); - } - hda->hda2hdmi_clk = devm_clk_get(dev, "hda2hdmi"); - if (IS_ERR(hda->hda2hdmi_clk)) { - dev_err(dev, "failed to get hda2hdmi clock\n"); - return PTR_ERR(hda->hda2hdmi_clk); - } - - return 0; -} - static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev) { struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); @@ -495,7 +441,11 @@ static int hda_tegra_probe(struct platform_device *pdev) return err; } - err = hda_tegra_init_clk(hda); + hda->clocks[hda->nclocks++].id = "hda"; + hda->clocks[hda->nclocks++].id = "hda2hdmi"; + hda->clocks[hda->nclocks++].id = "hda2codec_2x"; + + err = devm_clk_bulk_get(&pdev->dev, hda->nclocks, hda->clocks); if (err < 0) goto out_free; -- cgit v1.2.3 From 87f0e46e7559beb6f1d1ff99f8f48b1b9d86db52 Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Wed, 20 Jan 2021 03:31:50 +0300 Subject: ALSA: hda/tegra: Reset hardware Reset hardware on RPM-resume in order to bring it into a predictable state. Tested-by: Peter Geis # Ouya T30 audio works Tested-by: Matt Merhar # Ouya T30 boot-tested Tested-by: Nicolas Chauvet # TK1 boot-tested Signed-off-by: Dmitry Osipenko Link: https://lore.kernel.org/r/20210120003154.26749-3-digetx@gmail.com Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_tegra.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sound') diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index a25bf7083c28..04dcd4cdfd9e 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct hda_tegra { struct azx chip; struct device *dev; + struct reset_control *reset; struct clk_bulk_data clocks[3]; unsigned int nclocks; void __iomem *regs; @@ -167,6 +169,12 @@ static int __maybe_unused hda_tegra_runtime_resume(struct device *dev) struct hda_tegra *hda = container_of(chip, struct hda_tegra, chip); int rc; + if (!chip->running) { + rc = reset_control_assert(hda->reset); + if (rc) + return rc; + } + rc = clk_bulk_prepare_enable(hda->nclocks, hda->clocks); if (rc != 0) return rc; @@ -176,6 +184,12 @@ static int __maybe_unused hda_tegra_runtime_resume(struct device *dev) /* disable controller wake up event*/ azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) & ~STATESTS_INT_MASK); + } else { + usleep_range(10, 100); + + rc = reset_control_deassert(hda->reset); + if (rc) + return rc; } return 0; @@ -441,6 +455,12 @@ static int hda_tegra_probe(struct platform_device *pdev) return err; } + hda->reset = devm_reset_control_array_get_exclusive(&pdev->dev); + if (IS_ERR(hda->reset)) { + err = PTR_ERR(hda->reset); + goto out_free; + } + hda->clocks[hda->nclocks++].id = "hda"; hda->clocks[hda->nclocks++].id = "hda2hdmi"; hda->clocks[hda->nclocks++].id = "hda2codec_2x"; -- cgit v1.2.3 From 6755568ad111394da224c823e8baf31a05a1469c Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Wed, 20 Jan 2021 03:31:51 +0300 Subject: ALSA: hda/tegra: Remove unnecessary null-check from hda_tegra_runtime_resume() The "chip" can't be NULL in hda_tegra_runtime_resume() because code would crash otherwise. Let's remove the unnecessary check in order to clean up code a tad. Tested-by: Peter Geis # Ouya T30 audio works Tested-by: Matt Merhar # Ouya T30 boot-tested Suggested-by: Thierry Reding Signed-off-by: Dmitry Osipenko Link: https://lore.kernel.org/r/20210120003154.26749-4-digetx@gmail.com Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c index 04dcd4cdfd9e..6f2b743b9d75 100644 --- a/sound/pci/hda/hda_tegra.c +++ b/sound/pci/hda/hda_tegra.c @@ -178,7 +178,7 @@ static int __maybe_unused hda_tegra_runtime_resume(struct device *dev) rc = clk_bulk_prepare_enable(hda->nclocks, hda->clocks); if (rc != 0) return rc; - if (chip && chip->running) { + if (chip->running) { hda_tegra_init(hda); azx_init_chip(chip, 1); /* disable controller wake up event*/ -- cgit v1.2.3 From 30e88d017fcbeb50c4b07577fe059558361067e7 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 22 Jan 2021 10:24:49 +0100 Subject: isa: Make the remove callback for isa drivers return void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver core ignores the return value of the remove callback, so don't give isa drivers the chance to provide a value. Adapt all isa_drivers with a remove callbacks accordingly; they all return 0 unconditionally anyhow. Acked-by: Marc Kleine-Budde # for drivers/net/can/sja1000/tscan1.c Acked-by: William Breathitt Gray Acked-by: Wolfram Sang # for drivers/i2c/ Reviewed-by: Takashi Iway # for sound/ Reviewed-by: Hans Verkuil # for drivers/media/ Signed-off-by: Uwe Kleine-König Link: https://lore.kernel.org/r/20210122092449.426097-4-uwe@kleine-koenig.org Signed-off-by: Takashi Iwai --- drivers/base/isa.c | 2 +- drivers/i2c/busses/i2c-elektor.c | 4 +--- drivers/i2c/busses/i2c-pca-isa.c | 4 +--- drivers/input/touchscreen/htcpen.c | 4 +--- drivers/media/radio/radio-isa.c | 4 +--- drivers/media/radio/radio-isa.h | 2 +- drivers/media/radio/radio-sf16fmr2.c | 4 +--- drivers/net/can/sja1000/tscan1.c | 4 +--- drivers/net/ethernet/3com/3c509.c | 3 +-- drivers/scsi/advansys.c | 3 +-- drivers/scsi/aha1542.c | 3 +-- drivers/scsi/fdomain_isa.c | 3 +-- drivers/scsi/g_NCR5380.c | 5 ++--- drivers/watchdog/pcwd.c | 4 +--- include/linux/isa.h | 2 +- sound/isa/ad1848/ad1848.c | 3 +-- sound/isa/adlib.c | 3 +-- sound/isa/cmi8328.c | 3 +-- sound/isa/cmi8330.c | 3 +-- sound/isa/cs423x/cs4231.c | 3 +-- sound/isa/cs423x/cs4236.c | 3 +-- sound/isa/es1688/es1688.c | 3 +-- sound/isa/es18xx.c | 5 ++--- sound/isa/galaxy/galaxy.c | 3 +-- sound/isa/gus/gusclassic.c | 3 +-- sound/isa/gus/gusextreme.c | 3 +-- sound/isa/gus/gusmax.c | 3 +-- sound/isa/gus/interwave.c | 3 +-- sound/isa/msnd/msnd_pinnacle.c | 3 +-- sound/isa/opl3sa2.c | 3 +-- sound/isa/opti9xx/miro.c | 3 +-- sound/isa/opti9xx/opti92x-ad1848.c | 5 ++--- sound/isa/sb/jazz16.c | 3 +-- sound/isa/sb/sb16.c | 3 +-- sound/isa/sb/sb8.c | 3 +-- sound/isa/sc6000.c | 3 +-- sound/isa/sscape.c | 3 +-- sound/isa/wavefront/wavefront.c | 3 +-- 38 files changed, 41 insertions(+), 83 deletions(-) (limited to 'sound') diff --git a/drivers/base/isa.c b/drivers/base/isa.c index 2772f5d1948a..aa4737667026 100644 --- a/drivers/base/isa.c +++ b/drivers/base/isa.c @@ -51,7 +51,7 @@ static int isa_bus_remove(struct device *dev) struct isa_driver *isa_driver = dev->platform_data; if (isa_driver && isa_driver->remove) - return isa_driver->remove(dev, to_isa_dev(dev)->id); + isa_driver->remove(dev, to_isa_dev(dev)->id); return 0; } diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c index 140426db28df..b72a3c3ef2ab 100644 --- a/drivers/i2c/busses/i2c-elektor.c +++ b/drivers/i2c/busses/i2c-elektor.c @@ -282,7 +282,7 @@ static int elektor_probe(struct device *dev, unsigned int id) return -ENODEV; } -static int elektor_remove(struct device *dev, unsigned int id) +static void elektor_remove(struct device *dev, unsigned int id) { i2c_del_adapter(&pcf_isa_ops); @@ -298,8 +298,6 @@ static int elektor_remove(struct device *dev, unsigned int id) iounmap(base_iomem); release_mem_region(base, 2); } - - return 0; } static struct isa_driver i2c_elektor_driver = { diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index f27bc1e55385..85e8cf58e8bf 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c @@ -161,7 +161,7 @@ static int pca_isa_probe(struct device *dev, unsigned int id) return -ENODEV; } -static int pca_isa_remove(struct device *dev, unsigned int id) +static void pca_isa_remove(struct device *dev, unsigned int id) { i2c_del_adapter(&pca_isa_ops); @@ -170,8 +170,6 @@ static int pca_isa_remove(struct device *dev, unsigned int id) free_irq(irq, &pca_isa_ops); } release_region(base, IO_SIZE); - - return 0; } static struct isa_driver pca_isa_driver = { diff --git a/drivers/input/touchscreen/htcpen.c b/drivers/input/touchscreen/htcpen.c index 2f261a34f9c2..056ba76087e8 100644 --- a/drivers/input/touchscreen/htcpen.c +++ b/drivers/input/touchscreen/htcpen.c @@ -171,7 +171,7 @@ static int htcpen_isa_probe(struct device *dev, unsigned int id) return err; } -static int htcpen_isa_remove(struct device *dev, unsigned int id) +static void htcpen_isa_remove(struct device *dev, unsigned int id) { struct input_dev *htcpen_dev = dev_get_drvdata(dev); @@ -182,8 +182,6 @@ static int htcpen_isa_remove(struct device *dev, unsigned int id) release_region(HTCPEN_PORT_INDEX, 2); release_region(HTCPEN_PORT_INIT, 1); release_region(HTCPEN_PORT_IRQ_CLEAR, 1); - - return 0; } #ifdef CONFIG_PM diff --git a/drivers/media/radio/radio-isa.c b/drivers/media/radio/radio-isa.c index 527f4c3b0ca4..c591c0851fa2 100644 --- a/drivers/media/radio/radio-isa.c +++ b/drivers/media/radio/radio-isa.c @@ -337,13 +337,11 @@ int radio_isa_probe(struct device *pdev, unsigned int dev) } EXPORT_SYMBOL_GPL(radio_isa_probe); -int radio_isa_remove(struct device *pdev, unsigned int dev) +void radio_isa_remove(struct device *pdev, unsigned int dev) { struct radio_isa_card *isa = dev_get_drvdata(pdev); radio_isa_common_remove(isa, isa->drv->region_size); - - return 0; } EXPORT_SYMBOL_GPL(radio_isa_remove); diff --git a/drivers/media/radio/radio-isa.h b/drivers/media/radio/radio-isa.h index 2f0736edfda8..c9159958203e 100644 --- a/drivers/media/radio/radio-isa.h +++ b/drivers/media/radio/radio-isa.h @@ -91,7 +91,7 @@ struct radio_isa_driver { int radio_isa_match(struct device *pdev, unsigned int dev); int radio_isa_probe(struct device *pdev, unsigned int dev); -int radio_isa_remove(struct device *pdev, unsigned int dev); +void radio_isa_remove(struct device *pdev, unsigned int dev); #ifdef CONFIG_PNP int radio_isa_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id); diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c index 0388894cfe41..d0dde55b7930 100644 --- a/drivers/media/radio/radio-sf16fmr2.c +++ b/drivers/media/radio/radio-sf16fmr2.c @@ -293,11 +293,9 @@ static void fmr2_remove(struct fmr2 *fmr2) kfree(fmr2); } -static int fmr2_isa_remove(struct device *pdev, unsigned int ndev) +static void fmr2_isa_remove(struct device *pdev, unsigned int ndev) { fmr2_remove(dev_get_drvdata(pdev)); - - return 0; } static void fmr2_pnp_remove(struct pnp_dev *pdev) diff --git a/drivers/net/can/sja1000/tscan1.c b/drivers/net/can/sja1000/tscan1.c index 6ea802c66124..3dbba8d61afb 100644 --- a/drivers/net/can/sja1000/tscan1.c +++ b/drivers/net/can/sja1000/tscan1.c @@ -159,7 +159,7 @@ static int tscan1_probe(struct device *dev, unsigned id) return -ENXIO; } -static int tscan1_remove(struct device *dev, unsigned id /*unused*/) +static void tscan1_remove(struct device *dev, unsigned id /*unused*/) { struct net_device *netdev; struct sja1000_priv *priv; @@ -179,8 +179,6 @@ static int tscan1_remove(struct device *dev, unsigned id /*unused*/) release_region(pld_base, TSCAN1_PLD_SIZE); free_sja1000dev(netdev); - - return 0; } static struct isa_driver tscan1_isa_driver = { diff --git a/drivers/net/ethernet/3com/3c509.c b/drivers/net/ethernet/3com/3c509.c index 667f38c9e4c6..53e1f7e07959 100644 --- a/drivers/net/ethernet/3com/3c509.c +++ b/drivers/net/ethernet/3com/3c509.c @@ -335,12 +335,11 @@ static int el3_isa_match(struct device *pdev, unsigned int ndev) return 1; } -static int el3_isa_remove(struct device *pdev, +static void el3_isa_remove(struct device *pdev, unsigned int ndev) { el3_device_remove(pdev); dev_set_drvdata(pdev, NULL); - return 0; } #ifdef CONFIG_PM diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c index 79830e77afa9..b1e97f75b0ba 100644 --- a/drivers/scsi/advansys.c +++ b/drivers/scsi/advansys.c @@ -11459,12 +11459,11 @@ static int advansys_isa_probe(struct device *dev, unsigned int id) return err; } -static int advansys_isa_remove(struct device *dev, unsigned int id) +static void advansys_isa_remove(struct device *dev, unsigned int id) { int ioport = _asc_def_iop_base[id]; advansys_release(dev_get_drvdata(dev)); release_region(ioport, ASC_IOADR_GAP); - return 0; } static struct isa_driver advansys_isa_driver = { diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c index dc5667afeb27..e0d8cca1c70b 100644 --- a/drivers/scsi/aha1542.c +++ b/drivers/scsi/aha1542.c @@ -1025,12 +1025,11 @@ static int aha1542_isa_match(struct device *pdev, unsigned int ndev) return 1; } -static int aha1542_isa_remove(struct device *pdev, +static void aha1542_isa_remove(struct device *pdev, unsigned int ndev) { aha1542_release(dev_get_drvdata(pdev)); dev_set_drvdata(pdev, NULL); - return 0; } static struct isa_driver aha1542_isa_driver = { diff --git a/drivers/scsi/fdomain_isa.c b/drivers/scsi/fdomain_isa.c index e0cdcd2003d0..2b4280a43a53 100644 --- a/drivers/scsi/fdomain_isa.c +++ b/drivers/scsi/fdomain_isa.c @@ -175,7 +175,7 @@ static int fdomain_isa_param_match(struct device *dev, unsigned int ndev) return 1; } -static int fdomain_isa_remove(struct device *dev, unsigned int ndev) +static void fdomain_isa_remove(struct device *dev, unsigned int ndev) { struct Scsi_Host *sh = dev_get_drvdata(dev); int base = sh->io_port; @@ -183,7 +183,6 @@ static int fdomain_isa_remove(struct device *dev, unsigned int ndev) fdomain_destroy(sh); release_region(base, FDOMAIN_REGION_SIZE); dev_set_drvdata(dev, NULL); - return 0; } static struct isa_driver fdomain_isa_driver = { diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c index 2df2f38a9b12..7ba3c9312731 100644 --- a/drivers/scsi/g_NCR5380.c +++ b/drivers/scsi/g_NCR5380.c @@ -720,12 +720,11 @@ static int generic_NCR5380_isa_match(struct device *pdev, unsigned int ndev) return 1; } -static int generic_NCR5380_isa_remove(struct device *pdev, - unsigned int ndev) +static void generic_NCR5380_isa_remove(struct device *pdev, + unsigned int ndev) { generic_NCR5380_release_resources(dev_get_drvdata(pdev)); dev_set_drvdata(pdev, NULL); - return 0; } static struct isa_driver generic_NCR5380_isa_driver = { diff --git a/drivers/watchdog/pcwd.c b/drivers/watchdog/pcwd.c index b95cd38f3ceb..a793b03a785d 100644 --- a/drivers/watchdog/pcwd.c +++ b/drivers/watchdog/pcwd.c @@ -951,7 +951,7 @@ error_request_region: return ret; } -static int pcwd_isa_remove(struct device *dev, unsigned int id) +static void pcwd_isa_remove(struct device *dev, unsigned int id) { if (debug >= DEBUG) pr_debug("pcwd_isa_remove id=%d\n", id); @@ -968,8 +968,6 @@ static int pcwd_isa_remove(struct device *dev, unsigned int id) (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); pcwd_private.io_addr = 0x0000; cards_found--; - - return 0; } static void pcwd_isa_shutdown(struct device *dev, unsigned int id) diff --git a/include/linux/isa.h b/include/linux/isa.h index 41336da0f4e7..e30963190968 100644 --- a/include/linux/isa.h +++ b/include/linux/isa.h @@ -13,7 +13,7 @@ struct isa_driver { int (*match)(struct device *, unsigned int); int (*probe)(struct device *, unsigned int); - int (*remove)(struct device *, unsigned int); + void (*remove)(struct device *, unsigned int); void (*shutdown)(struct device *, unsigned int); int (*suspend)(struct device *, unsigned int, pm_message_t); int (*resume)(struct device *, unsigned int); diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c index 593c6e959afe..48f7cc57c3da 100644 --- a/sound/isa/ad1848/ad1848.c +++ b/sound/isa/ad1848/ad1848.c @@ -118,10 +118,9 @@ out: snd_card_free(card); return error; } -static int snd_ad1848_remove(struct device *dev, unsigned int n) +static void snd_ad1848_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/adlib.c b/sound/isa/adlib.c index 5105524b6f38..e6cd7c4da38e 100644 --- a/sound/isa/adlib.c +++ b/sound/isa/adlib.c @@ -97,10 +97,9 @@ out: snd_card_free(card); return error; } -static int snd_adlib_remove(struct device *dev, unsigned int n) +static void snd_adlib_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } static struct isa_driver snd_adlib_driver = { diff --git a/sound/isa/cmi8328.c b/sound/isa/cmi8328.c index faca5dd95bfe..3b9fbb02864b 100644 --- a/sound/isa/cmi8328.c +++ b/sound/isa/cmi8328.c @@ -403,7 +403,7 @@ error: return err; } -static int snd_cmi8328_remove(struct device *pdev, unsigned int dev) +static void snd_cmi8328_remove(struct device *pdev, unsigned int dev) { struct snd_card *card = dev_get_drvdata(pdev); struct snd_cmi8328 *cmi = card->private_data; @@ -420,7 +420,6 @@ static int snd_cmi8328_remove(struct device *pdev, unsigned int dev) snd_cmi8328_cfg_write(cmi->port, CFG2, 0); snd_cmi8328_cfg_write(cmi->port, CFG3, 0); snd_card_free(card); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c index 4669eb0cc8ce..19e258527d69 100644 --- a/sound/isa/cmi8330.c +++ b/sound/isa/cmi8330.c @@ -631,11 +631,10 @@ static int snd_cmi8330_isa_probe(struct device *pdev, return 0; } -static int snd_cmi8330_isa_remove(struct device *devptr, +static void snd_cmi8330_isa_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c index 2135963eba78..383ee621cea1 100644 --- a/sound/isa/cs423x/cs4231.c +++ b/sound/isa/cs423x/cs4231.c @@ -135,10 +135,9 @@ out: snd_card_free(card); return error; } -static int snd_cs4231_remove(struct device *dev, unsigned int n) +static void snd_cs4231_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c index fa3c39cff5f8..24688271e73f 100644 --- a/sound/isa/cs423x/cs4236.c +++ b/sound/isa/cs423x/cs4236.c @@ -487,11 +487,10 @@ static int snd_cs423x_isa_probe(struct device *pdev, return 0; } -static int snd_cs423x_isa_remove(struct device *pdev, +static void snd_cs423x_isa_remove(struct device *pdev, unsigned int dev) { snd_card_free(dev_get_drvdata(pdev)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c index 64610571a5e1..d99bb3f8f0c1 100644 --- a/sound/isa/es1688/es1688.c +++ b/sound/isa/es1688/es1688.c @@ -192,10 +192,9 @@ out: return error; } -static int snd_es1688_isa_remove(struct device *dev, unsigned int n) +static void snd_es1688_isa_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } static struct isa_driver snd_es1688_driver = { diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c index 5f8d7e8a5477..9beef8079177 100644 --- a/sound/isa/es18xx.c +++ b/sound/isa/es18xx.c @@ -2210,11 +2210,10 @@ static int snd_es18xx_isa_probe(struct device *pdev, unsigned int dev) } } -static int snd_es18xx_isa_remove(struct device *devptr, - unsigned int dev) +static void snd_es18xx_isa_remove(struct device *devptr, + unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/galaxy/galaxy.c b/sound/isa/galaxy/galaxy.c index 65f9f46c9f58..d33d69f29924 100644 --- a/sound/isa/galaxy/galaxy.c +++ b/sound/isa/galaxy/galaxy.c @@ -608,10 +608,9 @@ error: return err; } -static int snd_galaxy_remove(struct device *dev, unsigned int n) +static void snd_galaxy_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } static struct isa_driver snd_galaxy_driver = { diff --git a/sound/isa/gus/gusclassic.c b/sound/isa/gus/gusclassic.c index 7419b1939754..015f88a11352 100644 --- a/sound/isa/gus/gusclassic.c +++ b/sound/isa/gus/gusclassic.c @@ -195,10 +195,9 @@ out: snd_card_free(card); return error; } -static int snd_gusclassic_remove(struct device *dev, unsigned int n) +static void snd_gusclassic_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } static struct isa_driver snd_gusclassic_driver = { diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c index ed2f9d64efae..c9f31b4fb887 100644 --- a/sound/isa/gus/gusextreme.c +++ b/sound/isa/gus/gusextreme.c @@ -324,10 +324,9 @@ out: snd_card_free(card); return error; } -static int snd_gusextreme_remove(struct device *dev, unsigned int n) +static void snd_gusextreme_remove(struct device *dev, unsigned int n) { snd_card_free(dev_get_drvdata(dev)); - return 0; } static struct isa_driver snd_gusextreme_driver = { diff --git a/sound/isa/gus/gusmax.c b/sound/isa/gus/gusmax.c index 05cd9be4dd8a..dc09fbd6f88d 100644 --- a/sound/isa/gus/gusmax.c +++ b/sound/isa/gus/gusmax.c @@ -338,10 +338,9 @@ static int snd_gusmax_probe(struct device *pdev, unsigned int dev) return err; } -static int snd_gusmax_remove(struct device *devptr, unsigned int dev) +static void snd_gusmax_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #define DEV_NAME "gusmax" diff --git a/sound/isa/gus/interwave.c b/sound/isa/gus/interwave.c index 3e9ad930deae..e4d412e72b75 100644 --- a/sound/isa/gus/interwave.c +++ b/sound/isa/gus/interwave.c @@ -825,10 +825,9 @@ static int snd_interwave_isa_probe(struct device *pdev, } } -static int snd_interwave_isa_remove(struct device *devptr, unsigned int dev) +static void snd_interwave_isa_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } static struct isa_driver snd_interwave_driver = { diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c index 24b34ecf5e5b..69647b41300d 100644 --- a/sound/isa/msnd/msnd_pinnacle.c +++ b/sound/isa/msnd/msnd_pinnacle.c @@ -1049,10 +1049,9 @@ cfg_error: #endif } -static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev) +static void snd_msnd_isa_remove(struct device *pdev, unsigned int dev) { snd_msnd_unload(dev_get_drvdata(pdev)); - return 0; } static struct isa_driver snd_msnd_driver = { diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c index 85a181acd388..7649a8a4128d 100644 --- a/sound/isa/opl3sa2.c +++ b/sound/isa/opl3sa2.c @@ -878,11 +878,10 @@ static int snd_opl3sa2_isa_probe(struct device *pdev, return 0; } -static int snd_opl3sa2_isa_remove(struct device *devptr, +static void snd_opl3sa2_isa_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c index 44ed1b65f6ce..20933342f5eb 100644 --- a/sound/isa/opti9xx/miro.c +++ b/sound/isa/opti9xx/miro.c @@ -1480,11 +1480,10 @@ static int snd_miro_isa_probe(struct device *devptr, unsigned int n) return 0; } -static int snd_miro_isa_remove(struct device *devptr, +static void snd_miro_isa_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #define DEV_NAME "miro" diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index 881d3b5711d2..758f5b579138 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c @@ -1024,11 +1024,10 @@ static int snd_opti9xx_isa_probe(struct device *devptr, return 0; } -static int snd_opti9xx_isa_remove(struct device *devptr, - unsigned int dev) +static void snd_opti9xx_isa_remove(struct device *devptr, + unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/sb/jazz16.c b/sound/isa/sb/jazz16.c index ee379bbf70a4..0e2e0ab3b9e4 100644 --- a/sound/isa/sb/jazz16.c +++ b/sound/isa/sb/jazz16.c @@ -339,12 +339,11 @@ err_free: return err; } -static int snd_jazz16_remove(struct device *devptr, unsigned int dev) +static void snd_jazz16_remove(struct device *devptr, unsigned int dev) { struct snd_card *card = dev_get_drvdata(devptr); snd_card_free(card); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c index 479197c13803..db284b7b88a7 100644 --- a/sound/isa/sb/sb16.c +++ b/sound/isa/sb/sb16.c @@ -547,10 +547,9 @@ static int snd_sb16_isa_probe(struct device *pdev, unsigned int dev) } } -static int snd_sb16_isa_remove(struct device *pdev, unsigned int dev) +static void snd_sb16_isa_remove(struct device *pdev, unsigned int dev) { snd_card_free(dev_get_drvdata(pdev)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c index 438109f167d6..8e3e67b9a341 100644 --- a/sound/isa/sb/sb8.c +++ b/sound/isa/sb/sb8.c @@ -192,10 +192,9 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) return err; } -static int snd_sb8_remove(struct device *pdev, unsigned int dev) +static void snd_sb8_remove(struct device *pdev, unsigned int dev) { snd_card_free(dev_get_drvdata(pdev)); - return 0; } #ifdef CONFIG_PM diff --git a/sound/isa/sc6000.c b/sound/isa/sc6000.c index 3d0bea44f454..def137579717 100644 --- a/sound/isa/sc6000.c +++ b/sound/isa/sc6000.c @@ -672,7 +672,7 @@ err_exit: return err; } -static int snd_sc6000_remove(struct device *devptr, unsigned int dev) +static void snd_sc6000_remove(struct device *devptr, unsigned int dev) { struct snd_card *card = dev_get_drvdata(devptr); char __iomem **vport = card->private_data; @@ -684,7 +684,6 @@ static int snd_sc6000_remove(struct device *devptr, unsigned int dev) release_region(mss_port[dev], 4); snd_card_free(card); - return 0; } static struct isa_driver snd_sc6000_driver = { diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c index 2e5a5c5279e8..e70ef9aee545 100644 --- a/sound/isa/sscape.c +++ b/sound/isa/sscape.c @@ -1183,10 +1183,9 @@ _release_card: return ret; } -static int snd_sscape_remove(struct device *devptr, unsigned int dev) +static void snd_sscape_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #define DEV_NAME "sscape" diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c index 9e0f6b226775..b750a4fd40de 100644 --- a/sound/isa/wavefront/wavefront.c +++ b/sound/isa/wavefront/wavefront.c @@ -565,11 +565,10 @@ static int snd_wavefront_isa_probe(struct device *pdev, return 0; } -static int snd_wavefront_isa_remove(struct device *devptr, +static void snd_wavefront_isa_remove(struct device *devptr, unsigned int dev) { snd_card_free(dev_get_drvdata(devptr)); - return 0; } #define DEV_NAME "wavefront" -- cgit v1.2.3 From fa2e5a647ed2ed299974ea5916c1e7648f81030b Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Sun, 31 Jan 2021 01:12:40 +0100 Subject: ALSA: ac97: Constify static struct attribute_group The only usage of ac97_adapter_attr_group is to put its address in an array of pointers to const attribute_group structs. Make it const to allow the compiler to put it in read-only memory. Signed-off-by: Rikard Falkeborn Link: https://lore.kernel.org/r/20210131001241.2278-2-rikard.falkeborn@gmail.com Signed-off-by: Takashi Iwai --- sound/ac97/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c index 7985dd8198b6..d9077e91382b 100644 --- a/sound/ac97/bus.c +++ b/sound/ac97/bus.c @@ -273,7 +273,7 @@ static struct attribute *ac97_controller_device_attrs[] = { NULL }; -static struct attribute_group ac97_adapter_attr_group = { +static const struct attribute_group ac97_adapter_attr_group = { .name = "ac97_operations", .attrs = ac97_controller_device_attrs, }; -- cgit v1.2.3 From 0417fadab493b55093ba2590f4e66c828f7084fe Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Sun, 31 Jan 2021 01:12:41 +0100 Subject: ALSA: hda: Constify static attribute_group The only usage of hdac_dev_attr_group is to put its address in an array of pointers to const attribute_group structs. Make it const to allow the compiler to put it in read-only memory. Signed-off-by: Rikard Falkeborn Link: https://lore.kernel.org/r/20210131001241.2278-3-rikard.falkeborn@gmail.com Signed-off-by: Takashi Iwai --- sound/hda/hdac_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c index e56e83325903..0d7771fca9f0 100644 --- a/sound/hda/hdac_sysfs.c +++ b/sound/hda/hdac_sysfs.c @@ -66,7 +66,7 @@ static struct attribute *hdac_dev_attrs[] = { NULL }; -static struct attribute_group hdac_dev_attr_group = { +static const struct attribute_group hdac_dev_attr_group = { .attrs = hdac_dev_attrs, }; -- cgit v1.2.3 From 0074946932cbd42647da947408a9d620746a4e0e Mon Sep 17 00:00:00 2001 From: Dinghao Liu Date: Sun, 31 Jan 2021 18:09:14 +0800 Subject: ALSA: intel8x0: Fix missing check in snd_intel8x0m_create When device_type == DEVICE_ALI, we should also check the return value of pci_iomap() to avoid potential null pointer dereference. Signed-off-by: Dinghao Liu Link: https://lore.kernel.org/r/20210131100916.7915-1-dinghao.liu@zju.edu.cn Signed-off-by: Takashi Iwai --- sound/pci/intel8x0m.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c index 1b7df0c4e57c..19872cecc9d2 100644 --- a/sound/pci/intel8x0m.c +++ b/sound/pci/intel8x0m.c @@ -1129,13 +1129,14 @@ static int snd_intel8x0m_create(struct snd_card *card, chip->bmaddr = pci_iomap(pci, 3, 0); else chip->bmaddr = pci_iomap(pci, 1, 0); + +port_inited: if (!chip->bmaddr) { dev_err(card->dev, "Controller space ioremap problem\n"); snd_intel8x0m_free(chip); return -EIO; } - port_inited: /* initialize offsets */ chip->bdbars_count = 2; tbl = intel_regs; -- cgit v1.2.3 From da2a040ee7cfe1dd57d5bec7906cb979c5787a86 Mon Sep 17 00:00:00 2001 From: Jasmin Fazlic Date: Mon, 1 Feb 2021 15:28:52 +0100 Subject: ALSA: hdsp: hardware output loopback Output loopback is a feature where you can record what you hear. The HDSP series of the RME interfaces provides this functionality at the hardware level and this patch exposes controls to enable or disable it per output (playback) channel. This probably works on other cards but due to a lack of hardware it is only tested and enabled for the HDSP9632 card with this patch. Should this patch be accepted a separate patch will be posted to https://github.com/alsa-project/alsa-tools/tree/master/hdspmixer which adds "LPBK" buttons to each output in the playback strip for the user to be able to control this feature from the user land. Users from Windows tool TotalMixFX should be familiar with this. Signed-off-by: Jasmin Fazlic Link: https://lore.kernel.org/r/95cb3117-e85a-51a6-c2ce-bf736e70fc4c@gmail.com Signed-off-by: Takashi Iwai --- sound/pci/rme9652/hdsp.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index cea53a878c36..6d9029333a12 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -469,6 +469,7 @@ struct hdsp { unsigned char qs_out_channels; unsigned char ds_out_channels; unsigned char ss_out_channels; + u32 io_loopback; /* output loopback channel states*/ struct snd_dma_buffer capture_dma_buf; struct snd_dma_buffer playback_dma_buf; @@ -3253,6 +3254,60 @@ static const struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AnalogExtensionBoard); static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK; + +static bool hdsp_loopback_get(struct hdsp *const hdsp, const u8 channel) +{ + return hdsp->io_loopback & (1 << channel); +} + +static int hdsp_loopback_set(struct hdsp *const hdsp, const u8 channel, const bool enable) +{ + if (hdsp_loopback_get(hdsp, channel) == enable) + return 0; + + hdsp->io_loopback ^= (1 << channel); + + hdsp_write(hdsp, HDSP_inputEnable + (4 * (hdsp->max_channels + channel)), enable); + + return 1; +} + +static int snd_hdsp_loopback_get(struct snd_kcontrol *const kcontrol, + struct snd_ctl_elem_value *const ucontrol) +{ + struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol); + const u8 channel = snd_ctl_get_ioff(kcontrol, &ucontrol->id); + + if (channel >= hdsp->max_channels) + return -ENOENT; + + ucontrol->value.integer.value[0] = hdsp_loopback_get(hdsp, channel); + + return 0; +} + +static int snd_hdsp_loopback_put(struct snd_kcontrol *const kcontrol, + struct snd_ctl_elem_value *const ucontrol) +{ + struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol); + const u8 channel = snd_ctl_get_ioff(kcontrol, &ucontrol->id); + const bool enable = ucontrol->value.integer.value[0] & 1; + + if (channel >= hdsp->max_channels) + return -ENOENT; + + return hdsp_loopback_set(hdsp, channel, enable); +} + +static struct snd_kcontrol_new snd_hdsp_loopback_control = { + .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, + .name = "Output Loopback", + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .info = snd_ctl_boolean_mono_info, + .get = snd_hdsp_loopback_get, + .put = snd_hdsp_loopback_put +}; + static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp) { unsigned int idx; @@ -3297,6 +3352,17 @@ static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp) } } + /* Output loopback controls for H9632 cards */ + if (hdsp->io_type == H9632) { + snd_hdsp_loopback_control.count = hdsp->max_channels; + kctl = snd_ctl_new1(&snd_hdsp_loopback_control, hdsp); + if (kctl == NULL) + return -ENOMEM; + err = snd_ctl_add(card, kctl); + if (err < 0) + return err; + } + /* AEB control for H96xx card */ if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) @@ -4956,7 +5022,7 @@ static int snd_hdsp_enable_io (struct hdsp *hdsp) static void snd_hdsp_initialize_channels(struct hdsp *hdsp) { - int status, aebi_channels, aebo_channels; + int status, aebi_channels, aebo_channels, i; switch (hdsp->io_type) { case Digiface: @@ -4983,6 +5049,12 @@ static void snd_hdsp_initialize_channels(struct hdsp *hdsp) hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels; hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels; hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels; + /* Disable loopback of output channels, as the set function + * only sets on a change we fake all bits (channels) as enabled. + */ + hdsp->io_loopback = 0xffffffff; + for (i = 0; i < hdsp->max_channels; ++i) + hdsp_loopback_set(hdsp, i, false); break; case Multiface: -- cgit v1.2.3 From 2d670ea2bd53a9792f453bb5b97cb8ef695988ff Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Wed, 27 Jan 2021 16:56:39 +0800 Subject: ALSA: jack: implement software jack injection via debugfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds audio jack injection feature through debugfs, with this feature, we could validate alsa userspace changes by injecting plugin or plugout events to the non-phantom audio jacks. With this change, the sound core will build the folders $debugfs_mount_dir/sound/cardN if SND_DEBUG and DEBUG_FS are enabled. And if users also enable the SND_JACK_INJECTION_DEBUG, the jack injection nodes will be built in the folder cardN like below: $tree $debugfs_mount_dir/sound $debugfs_mount_dir/sound ├── card0 │   ├── HDMI_DP_pcm_10_Jack │   │   ├── jackin_inject │   │   ├── kctl_id │   │   ├── mask_bits │   │   ├── status │   │   ├── sw_inject_enable │   │   └── type ... │   └── HDMI_DP_pcm_9_Jack │   ├── jackin_inject │   ├── kctl_id │   ├── mask_bits │   ├── status │   ├── sw_inject_enable │   └── type └── card1 ├── HDMI_DP_pcm_5_Jack │   ├── jackin_inject │   ├── kctl_id │   ├── mask_bits │   ├── status │   ├── sw_inject_enable │   └── type ... ├── Headphone_Jack │   ├── jackin_inject │   ├── kctl_id │   ├── mask_bits │   ├── status │   ├── sw_inject_enable │   └── type └── Headset_Mic_Jack ├── jackin_inject ├── kctl_id ├── mask_bits ├── status ├── sw_inject_enable └── type The nodes kctl_id, mask_bits, status and type are read-only, users could check jack or jack_kctl's information through them. The nodes sw_inject_enable and jackin_inject are directly used for injection. The sw_inject_enable is read-write, users could check if software injection is enabled or not on this jack, and users could echo 1 or 0 to enable or disable software injection on this jack. Once the injection is enabled, the jack will not change by hardware events anymore, once the injection is disabled, the jack will restore the last reported hardware events to the jack. The jackin_inject is write-only, if the injection is enabled, users could echo 1 or 0 to this node to inject plugin or plugout events to this jack. For the detailed usage information on these nodes, please refer to Documentation/sound/designs/jack-injection.rst. Reviewed-by: Takashi Iwai Reviewed-by: Jaroslav Kysela Reviewed-by: Kai Vehmanen Signed-off-by: Hui Wang Link: https://lore.kernel.org/r/20210127085639.74954-2-hui.wang@canonical.com Signed-off-by: Takashi Iwai --- Documentation/sound/designs/index.rst | 1 + Documentation/sound/designs/jack-injection.rst | 166 ++++++++++++++ include/sound/core.h | 6 + include/sound/jack.h | 1 + sound/core/Kconfig | 9 + sound/core/init.c | 16 ++ sound/core/jack.c | 304 ++++++++++++++++++++++++- sound/core/sound.c | 13 ++ 8 files changed, 512 insertions(+), 4 deletions(-) create mode 100644 Documentation/sound/designs/jack-injection.rst (limited to 'sound') diff --git a/Documentation/sound/designs/index.rst b/Documentation/sound/designs/index.rst index f0749943ccb2..1eb08e7bae52 100644 --- a/Documentation/sound/designs/index.rst +++ b/Documentation/sound/designs/index.rst @@ -14,3 +14,4 @@ Designs and Implementations powersave oss-emulation seq-oss + jack-injection diff --git a/Documentation/sound/designs/jack-injection.rst b/Documentation/sound/designs/jack-injection.rst new file mode 100644 index 000000000000..f9790521523e --- /dev/null +++ b/Documentation/sound/designs/jack-injection.rst @@ -0,0 +1,166 @@ +============================ +ALSA Jack Software Injection +============================ + +Simple Introduction On Jack Injection +===================================== + +Here jack injection means users could inject plugin or plugout events +to the audio jacks through debugfs interface, it is helpful to +validate ALSA userspace changes. For example, we change the audio +profile switching code in the pulseaudio, and we want to verify if the +change works as expected and if the change introduce the regression, +in this case, we could inject plugin or plugout events to an audio +jack or to some audio jacks, we don't need to physically access the +machine and plug/unplug physical devices to the audio jack. + +In this design, an audio jack doesn't equal to a physical audio jack. +Sometimes a physical audio jack contains multi functions, and the +ALSA driver creates multi ``jack_kctl`` for a ``snd_jack``, here the +``snd_jack`` represents a physical audio jack and the ``jack_kctl`` +represents a function, for example a physical jack has two functions: +headphone and mic_in, the ALSA ASoC driver will build 2 ``jack_kctl`` +for this jack. The jack injection is implemented based on the +``jack_kctl`` instead of ``snd_jack``. + +To inject events to audio jacks, we need to enable the jack injection +via ``sw_inject_enable`` first, once it is enabled, this jack will not +change the state by hardware events anymore, we could inject plugin or +plugout events via ``jackin_inject`` and check the jack state via +``status``, after we finish our test, we need to disable the jack +injection via ``sw_inject_enable`` too, once it is disabled, the jack +state will be restored according to the last reported hardware events +and will change by future hardware events. + +The Layout of Jack Injection Interface +====================================== + +If users enable the SND_JACK_INJECTION_DEBUG in the kernel, the audio +jack injection interface will be created as below: +:: + + $debugfs_mount_dir/sound + |-- card0 + |-- |-- HDMI_DP_pcm_10_Jack + |-- |-- |-- jackin_inject + |-- |-- |-- kctl_id + |-- |-- |-- mask_bits + |-- |-- |-- status + |-- |-- |-- sw_inject_enable + |-- |-- |-- type + ... + |-- |-- HDMI_DP_pcm_9_Jack + |-- |-- jackin_inject + |-- |-- kctl_id + |-- |-- mask_bits + |-- |-- status + |-- |-- sw_inject_enable + |-- |-- type + |-- card1 + |-- HDMI_DP_pcm_5_Jack + |-- |-- jackin_inject + |-- |-- kctl_id + |-- |-- mask_bits + |-- |-- status + |-- |-- sw_inject_enable + |-- |-- type + ... + |-- Headphone_Jack + |-- |-- jackin_inject + |-- |-- kctl_id + |-- |-- mask_bits + |-- |-- status + |-- |-- sw_inject_enable + |-- |-- type + |-- Headset_Mic_Jack + |-- jackin_inject + |-- kctl_id + |-- mask_bits + |-- status + |-- sw_inject_enable + |-- type + +The Explanation Of The Nodes +====================================== + +kctl_id + read-only, get jack_kctl->kctl's id + :: + + sound/card1/Headphone_Jack# cat kctl_id + Headphone Jack + +mask_bits + read-only, get jack_kctl's supported events mask_bits + :: + + sound/card1/Headphone_Jack# cat mask_bits + 0x0001 HEADPHONE(0x0001) + +status + read-only, get jack_kctl's current status + +- headphone unplugged: + + :: + + sound/card1/Headphone_Jack# cat status + Unplugged + +- headphone plugged: + + :: + + sound/card1/Headphone_Jack# cat status + Plugged + +type + read-only, get snd_jack's supported events from type (all supported events on the physical audio jack) + :: + + sound/card1/Headphone_Jack# cat type + 0x7803 HEADPHONE(0x0001) MICROPHONE(0x0002) BTN_3(0x0800) BTN_2(0x1000) BTN_1(0x2000) BTN_0(0x4000) + +sw_inject_enable + read-write, enable or disable injection + +- injection disabled: + + :: + + sound/card1/Headphone_Jack# cat sw_inject_enable + Jack: Headphone Jack Inject Enabled: 0 + +- injection enabled: + + :: + + sound/card1/Headphone_Jack# cat sw_inject_enable + Jack: Headphone Jack Inject Enabled: 1 + +- to enable jack injection: + + :: + + sound/card1/Headphone_Jack# echo 1 > sw_inject_enable + +- to disable jack injection: + + :: + + sound/card1/Headphone_Jack# echo 0 > sw_inject_enable + +jackin_inject + write-only, inject plugin or plugout + +- to inject plugin: + + :: + + sound/card1/Headphone_Jack# echo 1 > jackin_inject + +- to inject plugout: + + :: + + sound/card1/Headphone_Jack# echo 0 > jackin_inject diff --git a/include/sound/core.h b/include/sound/core.h index 0462c577d7a3..2e24f194ef70 100644 --- a/include/sound/core.h +++ b/include/sound/core.h @@ -122,6 +122,9 @@ struct snd_card { size_t total_pcm_alloc_bytes; /* total amount of allocated buffers */ struct mutex memory_mutex; /* protection for the above */ +#ifdef CONFIG_SND_DEBUG + struct dentry *debugfs_root; /* debugfs root for card */ +#endif #ifdef CONFIG_PM unsigned int power_state; /* power state */ @@ -180,6 +183,9 @@ static inline struct device *snd_card_get_device_link(struct snd_card *card) extern int snd_major; extern int snd_ecards_limit; extern struct class *sound_class; +#ifdef CONFIG_SND_DEBUG +extern struct dentry *sound_debugfs_root; +#endif void snd_request_card(int card); diff --git a/include/sound/jack.h b/include/sound/jack.h index 9eb2b5ec1ec4..1181f536557e 100644 --- a/include/sound/jack.h +++ b/include/sound/jack.h @@ -67,6 +67,7 @@ struct snd_jack { char name[100]; unsigned int key[6]; /* Keep in sync with definitions above */ #endif /* CONFIG_SND_JACK_INPUT_DEV */ + int hw_status_cache; void *private_data; void (*private_free)(struct snd_jack *); }; diff --git a/sound/core/Kconfig b/sound/core/Kconfig index d4554f376160..a4050f87f230 100644 --- a/sound/core/Kconfig +++ b/sound/core/Kconfig @@ -187,6 +187,15 @@ config SND_CTL_VALIDATION from the driver are in the proper ranges or the check of the invalid access at out-of-array areas. +config SND_JACK_INJECTION_DEBUG + bool "Sound jack injection interface via debugfs" + depends on SND_JACK && SND_DEBUG && DEBUG_FS + help + This option can be used to enable or disable sound jack + software injection. + Say Y if you are debugging via jack injection interface. + If unsure select "N". + config SND_VMASTER bool diff --git a/sound/core/init.c b/sound/core/init.c index 56834febc7a4..d4e78b176793 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -161,6 +162,9 @@ int snd_card_new(struct device *parent, int idx, const char *xid, { struct snd_card *card; int err; +#ifdef CONFIG_SND_DEBUG + char name[8]; +#endif if (snd_BUG_ON(!card_ret)) return -EINVAL; @@ -244,6 +248,12 @@ int snd_card_new(struct device *parent, int idx, const char *xid, dev_err(parent, "unable to create card info\n"); goto __error_ctl; } + +#ifdef CONFIG_SND_DEBUG + sprintf(name, "card%d", idx); + card->debugfs_root = debugfs_create_dir(name, sound_debugfs_root); +#endif + *card_ret = card; return 0; @@ -526,6 +536,12 @@ int snd_card_free(struct snd_card *card) return ret; /* wait, until all devices are ready for the free operation */ wait_for_completion(&released); + +#ifdef CONFIG_SND_DEBUG + debugfs_remove(card->debugfs_root); + card->debugfs_root = NULL; +#endif + return 0; } EXPORT_SYMBOL(snd_card_free); diff --git a/sound/core/jack.c b/sound/core/jack.c index 503c8af79d55..32350c6aba84 100644 --- a/sound/core/jack.c +++ b/sound/core/jack.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -16,6 +19,11 @@ struct snd_jack_kctl { struct snd_kcontrol *kctl; struct list_head list; /* list of controls belong to the same jack */ unsigned int mask_bits; /* only masked status bits are reported via kctl */ + struct snd_jack *jack; /* pointer to struct snd_jack */ + bool sw_inject_enable; /* allow to inject plug event via debugfs */ +#ifdef CONFIG_SND_JACK_INJECTION_DEBUG + struct dentry *jack_debugfs_root; /* jack_kctl debugfs root */ +#endif }; #ifdef CONFIG_SND_JACK_INPUT_DEV @@ -109,12 +117,291 @@ static int snd_jack_dev_register(struct snd_device *device) } #endif /* CONFIG_SND_JACK_INPUT_DEV */ +#ifdef CONFIG_SND_JACK_INJECTION_DEBUG +static void snd_jack_inject_report(struct snd_jack_kctl *jack_kctl, int status) +{ + struct snd_jack *jack; +#ifdef CONFIG_SND_JACK_INPUT_DEV + int i; +#endif + if (!jack_kctl) + return; + + jack = jack_kctl->jack; + + if (jack_kctl->sw_inject_enable) + snd_kctl_jack_report(jack->card, jack_kctl->kctl, + status & jack_kctl->mask_bits); + +#ifdef CONFIG_SND_JACK_INPUT_DEV + if (!jack->input_dev) + return; + + for (i = 0; i < ARRAY_SIZE(jack->key); i++) { + int testbit = ((SND_JACK_BTN_0 >> i) & jack_kctl->mask_bits); + + if (jack->type & testbit) + input_report_key(jack->input_dev, jack->key[i], + status & testbit); + } + + for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) { + int testbit = ((1 << i) & jack_kctl->mask_bits); + + if (jack->type & testbit) + input_report_switch(jack->input_dev, + jack_switch_types[i], + status & testbit); + } + + input_sync(jack->input_dev); +#endif /* CONFIG_SND_JACK_INPUT_DEV */ +} + +static ssize_t sw_inject_enable_read(struct file *file, + char __user *to, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + int len, ret; + char buf[128]; + + len = scnprintf(buf, sizeof(buf), "%s: %s\t\t%s: %i\n", "Jack", jack_kctl->kctl->id.name, + "Inject Enabled", jack_kctl->sw_inject_enable); + ret = simple_read_from_buffer(to, count, ppos, buf, len); + + return ret; +} + +static ssize_t sw_inject_enable_write(struct file *file, + const char __user *from, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + int ret, err; + unsigned long enable; + char buf[8] = { 0 }; + + ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, from, count); + err = kstrtoul(buf, 0, &enable); + if (err) + return err; + + if (jack_kctl->sw_inject_enable == (!!enable)) + return ret; + + jack_kctl->sw_inject_enable = !!enable; + + if (!jack_kctl->sw_inject_enable) + snd_jack_report(jack_kctl->jack, jack_kctl->jack->hw_status_cache); + + return ret; +} + +static ssize_t jackin_inject_write(struct file *file, + const char __user *from, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + int ret, err; + unsigned long enable; + char buf[8] = { 0 }; + + if (!jack_kctl->sw_inject_enable) + return -EINVAL; + + ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, from, count); + err = kstrtoul(buf, 0, &enable); + if (err) + return err; + + snd_jack_inject_report(jack_kctl, !!enable ? jack_kctl->mask_bits : 0); + + return ret; +} + +static ssize_t jack_kctl_id_read(struct file *file, + char __user *to, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + char buf[64]; + int len, ret; + + len = scnprintf(buf, sizeof(buf), "%s\n", jack_kctl->kctl->id.name); + ret = simple_read_from_buffer(to, count, ppos, buf, len); + + return ret; +} + +/* the bit definition is aligned with snd_jack_types in jack.h */ +static const char * const jack_events_name[] = { + "HEADPHONE(0x0001)", "MICROPHONE(0x0002)", "LINEOUT(0x0004)", + "MECHANICAL(0x0008)", "VIDEOOUT(0x0010)", "LINEIN(0x0020)", + "", "", "", "BTN_5(0x0200)", "BTN_4(0x0400)", "BTN_3(0x0800)", + "BTN_2(0x1000)", "BTN_1(0x2000)", "BTN_0(0x4000)", "", +}; + +/* the recommended buffer size is 256 */ +static int parse_mask_bits(unsigned int mask_bits, char *buf, size_t buf_size) +{ + int i; + + scnprintf(buf, buf_size, "0x%04x", mask_bits); + + for (i = 0; i < ARRAY_SIZE(jack_events_name); i++) + if (mask_bits & (1 << i)) { + strlcat(buf, " ", buf_size); + strlcat(buf, jack_events_name[i], buf_size); + } + strlcat(buf, "\n", buf_size); + + return strlen(buf); +} + +static ssize_t jack_kctl_mask_bits_read(struct file *file, + char __user *to, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + char buf[256]; + int len, ret; + + len = parse_mask_bits(jack_kctl->mask_bits, buf, sizeof(buf)); + ret = simple_read_from_buffer(to, count, ppos, buf, len); + + return ret; +} + +static ssize_t jack_kctl_status_read(struct file *file, + char __user *to, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + char buf[16]; + int len, ret; + + len = scnprintf(buf, sizeof(buf), "%s\n", jack_kctl->kctl->private_value ? + "Plugged" : "Unplugged"); + ret = simple_read_from_buffer(to, count, ppos, buf, len); + + return ret; +} + +#ifdef CONFIG_SND_JACK_INPUT_DEV +static ssize_t jack_type_read(struct file *file, + char __user *to, size_t count, loff_t *ppos) +{ + struct snd_jack_kctl *jack_kctl = file->private_data; + char buf[256]; + int len, ret; + + len = parse_mask_bits(jack_kctl->jack->type, buf, sizeof(buf)); + ret = simple_read_from_buffer(to, count, ppos, buf, len); + + return ret; +} + +static const struct file_operations jack_type_fops = { + .open = simple_open, + .read = jack_type_read, + .llseek = default_llseek, +}; +#endif + +static const struct file_operations sw_inject_enable_fops = { + .open = simple_open, + .read = sw_inject_enable_read, + .write = sw_inject_enable_write, + .llseek = default_llseek, +}; + +static const struct file_operations jackin_inject_fops = { + .open = simple_open, + .write = jackin_inject_write, + .llseek = default_llseek, +}; + +static const struct file_operations jack_kctl_id_fops = { + .open = simple_open, + .read = jack_kctl_id_read, + .llseek = default_llseek, +}; + +static const struct file_operations jack_kctl_mask_bits_fops = { + .open = simple_open, + .read = jack_kctl_mask_bits_read, + .llseek = default_llseek, +}; + +static const struct file_operations jack_kctl_status_fops = { + .open = simple_open, + .read = jack_kctl_status_read, + .llseek = default_llseek, +}; + +static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack, + struct snd_jack_kctl *jack_kctl) +{ + char *tname; + int i; + + /* Don't create injection interface for Phantom jacks */ + if (strstr(jack_kctl->kctl->id.name, "Phantom")) + return 0; + + tname = kstrdup(jack_kctl->kctl->id.name, GFP_KERNEL); + if (!tname) + return -ENOMEM; + + /* replace the chars which are not suitable for folder's name with _ */ + for (i = 0; tname[i]; i++) + if (!isalnum(tname[i])) + tname[i] = '_'; + + jack_kctl->jack_debugfs_root = debugfs_create_dir(tname, jack->card->debugfs_root); + kfree(tname); + + debugfs_create_file("sw_inject_enable", 0644, jack_kctl->jack_debugfs_root, jack_kctl, + &sw_inject_enable_fops); + + debugfs_create_file("jackin_inject", 0200, jack_kctl->jack_debugfs_root, jack_kctl, + &jackin_inject_fops); + + debugfs_create_file("kctl_id", 0444, jack_kctl->jack_debugfs_root, jack_kctl, + &jack_kctl_id_fops); + + debugfs_create_file("mask_bits", 0444, jack_kctl->jack_debugfs_root, jack_kctl, + &jack_kctl_mask_bits_fops); + + debugfs_create_file("status", 0444, jack_kctl->jack_debugfs_root, jack_kctl, + &jack_kctl_status_fops); + +#ifdef CONFIG_SND_JACK_INPUT_DEV + debugfs_create_file("type", 0444, jack_kctl->jack_debugfs_root, jack_kctl, + &jack_type_fops); +#endif + return 0; +} + +static void snd_jack_debugfs_clear_inject_node(struct snd_jack_kctl *jack_kctl) +{ + debugfs_remove(jack_kctl->jack_debugfs_root); + jack_kctl->jack_debugfs_root = NULL; +} +#else /* CONFIG_SND_JACK_INJECTION_DEBUG */ +static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack, + struct snd_jack_kctl *jack_kctl) +{ + return 0; +} + +static void snd_jack_debugfs_clear_inject_node(struct snd_jack_kctl *jack_kctl) +{ +} +#endif /* CONFIG_SND_JACK_INJECTION_DEBUG */ + static void snd_jack_kctl_private_free(struct snd_kcontrol *kctl) { struct snd_jack_kctl *jack_kctl; jack_kctl = kctl->private_data; if (jack_kctl) { + snd_jack_debugfs_clear_inject_node(jack_kctl); list_del(&jack_kctl->list); kfree(jack_kctl); } @@ -122,7 +409,9 @@ static void snd_jack_kctl_private_free(struct snd_kcontrol *kctl) static void snd_jack_kctl_add(struct snd_jack *jack, struct snd_jack_kctl *jack_kctl) { + jack_kctl->jack = jack; list_add_tail(&jack_kctl->list, &jack->kctl_list); + snd_jack_debugfs_add_inject_node(jack, jack_kctl); } static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const char *name, unsigned int mask) @@ -340,6 +629,7 @@ EXPORT_SYMBOL(snd_jack_set_key); void snd_jack_report(struct snd_jack *jack, int status) { struct snd_jack_kctl *jack_kctl; + unsigned int mask_bits = 0; #ifdef CONFIG_SND_JACK_INPUT_DEV int i; #endif @@ -347,16 +637,21 @@ void snd_jack_report(struct snd_jack *jack, int status) if (!jack) return; + jack->hw_status_cache = status; + list_for_each_entry(jack_kctl, &jack->kctl_list, list) - snd_kctl_jack_report(jack->card, jack_kctl->kctl, - status & jack_kctl->mask_bits); + if (jack_kctl->sw_inject_enable) + mask_bits |= jack_kctl->mask_bits; + else + snd_kctl_jack_report(jack->card, jack_kctl->kctl, + status & jack_kctl->mask_bits); #ifdef CONFIG_SND_JACK_INPUT_DEV if (!jack->input_dev) return; for (i = 0; i < ARRAY_SIZE(jack->key); i++) { - int testbit = SND_JACK_BTN_0 >> i; + int testbit = ((SND_JACK_BTN_0 >> i) & ~mask_bits); if (jack->type & testbit) input_report_key(jack->input_dev, jack->key[i], @@ -364,7 +659,8 @@ void snd_jack_report(struct snd_jack *jack, int status) } for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) { - int testbit = 1 << i; + int testbit = ((1 << i) & ~mask_bits); + if (jack->type & testbit) input_report_switch(jack->input_dev, jack_switch_types[i], diff --git a/sound/core/sound.c b/sound/core/sound.c index b75f78f2c4b8..2f759febe365 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,11 @@ MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR); int snd_ecards_limit; EXPORT_SYMBOL(snd_ecards_limit); +#ifdef CONFIG_SND_DEBUG +struct dentry *sound_debugfs_root; +EXPORT_SYMBOL_GPL(sound_debugfs_root); +#endif + static struct snd_minor *snd_minors[SNDRV_OS_MINORS]; static DEFINE_MUTEX(sound_mutex); @@ -395,6 +401,10 @@ static int __init alsa_sound_init(void) unregister_chrdev(major, "alsa"); return -ENOMEM; } + +#ifdef CONFIG_SND_DEBUG + sound_debugfs_root = debugfs_create_dir("sound", NULL); +#endif #ifndef MODULE pr_info("Advanced Linux Sound Architecture Driver Initialized.\n"); #endif @@ -403,6 +413,9 @@ static int __init alsa_sound_init(void) static void __exit alsa_sound_exit(void) { +#ifdef CONFIG_SND_DEBUG + debugfs_remove(sound_debugfs_root); +#endif snd_info_done(); unregister_chrdev(major, "alsa"); } -- cgit v1.2.3 From 3b85f5fc75d564a9eb4171dcb6b8687b080cd4d5 Mon Sep 17 00:00:00 2001 From: Olivia Mackintosh Date: Tue, 2 Feb 2021 13:42:26 +0000 Subject: ALSA: usb-audio: Add DJM450 to Pioneer format quirk Like the DJM-750, ensure that the format control message is passed to the device when opening a stream. It seems as though fmt->sync_ep is not always set when this function is called hence the passing of the value at the call site. If this can be fixed, fmt->sync_up should be used as the wvalue. There doesn't seem to be a "cpu_to_le24" type function defined hence for the open code but I did see a similar thing done in Bluez lib. Perhaps we can get these definitions defined in byteorder.h. See hci_cpu_to_le24 in include/net/bluetooth/hci.h:2543 for similar usage. Signed-off-by: Olivia Mackintosh Link: https://lore.kernel.org/r/20210202134225.3217-2-livvy@base.nu Signed-off-by: Takashi Iwai --- sound/usb/quirks.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sound') diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index e196e364cef1..9ba4682ebc48 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -1470,6 +1470,23 @@ static void set_format_emu_quirk(struct snd_usb_substream *subs, subs->pkt_offset_adj = (emu_samplerate_id >= EMU_QUIRK_SR_176400HZ) ? 4 : 0; } +static int pioneer_djm_set_format_quirk(struct snd_usb_substream *subs, + u16 windex) +{ + unsigned int cur_rate = subs->data_endpoint->cur_rate; + u8 sr[3]; + // Convert to little endian + sr[0] = cur_rate & 0xff; + sr[1] = (cur_rate >> 8) & 0xff; + sr[2] = (cur_rate >> 16) & 0xff; + usb_set_interface(subs->dev, 0, 1); + // we should derive windex from fmt-sync_ep but it's not set + snd_usb_ctl_msg(subs->stream->chip->dev, + usb_rcvctrlpipe(subs->stream->chip->dev, 0), + 0x01, 0x22, 0x0100, windex, &sr, 0x0003); + return 0; +} + void snd_usb_set_format_quirk(struct snd_usb_substream *subs, const struct audioformat *fmt) { @@ -1483,6 +1500,9 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs, case USB_ID(0x534d, 0x2109): /* MacroSilicon MS2109 */ subs->stream_offset_adj = 2; break; + case USB_ID(0x2b73, 0x0013): /* Pioneer DJM-450 */ + pioneer_djm_set_format_quirk(subs, 0x0082); + break; } } -- cgit v1.2.3 From 9119e5661eab2c56a96b936cde49c6740dc49ff9 Mon Sep 17 00:00:00 2001 From: Olivia Mackintosh Date: Tue, 2 Feb 2021 13:42:28 +0000 Subject: ALSA: usb-audio: Add DJM-450 to the quirks table As with most Pioneer devices, the device descriptor is vendor specific and as such, the number of channels, the PCM format, endpoints and sample rate need to be specified. This device has 8 inputs and 8 outputs and a sample rate of 48000 only. The PCM format is S24_3LE like other devices. There seems to be an appetite for reducing duplication amongs these Pioneer patches but again, I feel this is a step to be taken after support has been added as it's not completely clear where the commonalities are. Signed-off-by: Olivia Mackintosh Link: https://lore.kernel.org/r/20210202134225.3217-3-livvy@base.nu Signed-off-by: Takashi Iwai --- sound/usb/quirks-table.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'sound') diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index 93d55cd1a5a4..1165a5ac60f2 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -3817,6 +3817,63 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"), } } }, +{ + /* + * Pioneer DJ DJM-450 + * PCM is 8 channels out @ 48 fixed (endpoint 0x01) + * and 8 channels in @ 48 fixed (endpoint 0x82). + */ + USB_DEVICE_VENDOR_SPEC(0x2b73, 0x0013), + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { + .ifnum = QUIRK_ANY_INTERFACE, + .type = QUIRK_COMPOSITE, + .data = (const struct snd_usb_audio_quirk[]) { + { + .ifnum = 0, + .type = QUIRK_AUDIO_FIXED_ENDPOINT, + .data = &(const struct audioformat) { + .formats = SNDRV_PCM_FMTBIT_S24_3LE, + .channels = 8, // outputs + .iface = 0, + .altsetting = 1, + .altset_idx = 1, + .endpoint = 0x01, + .ep_attr = USB_ENDPOINT_XFER_ISOC| + USB_ENDPOINT_SYNC_ASYNC, + .rates = SNDRV_PCM_RATE_48000, + .rate_min = 48000, + .rate_max = 48000, + .nr_rates = 1, + .rate_table = (unsigned int[]) { 48000 } + } + }, + { + .ifnum = 0, + .type = QUIRK_AUDIO_FIXED_ENDPOINT, + .data = &(const struct audioformat) { + .formats = SNDRV_PCM_FMTBIT_S24_3LE, + .channels = 8, // inputs + .iface = 0, + .altsetting = 1, + .altset_idx = 1, + .endpoint = 0x82, + .ep_idx = 1, + .ep_attr = USB_ENDPOINT_XFER_ISOC| + USB_ENDPOINT_SYNC_ASYNC| + USB_ENDPOINT_USAGE_IMPLICIT_FB, + .rates = SNDRV_PCM_RATE_48000, + .rate_min = 48000, + .rate_max = 48000, + .nr_rates = 1, + .rate_table = (unsigned int[]) { 48000 } + } + }, + { + .ifnum = -1 + } + } + } +}, #undef USB_DEVICE_VENDOR_SPEC #undef USB_AUDIO_DEVICE -- cgit v1.2.3 From 016f94feb57d73b2c375f1ccd665bb546d401162 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 2 Feb 2021 10:27:44 +0100 Subject: ALSA: hda: Drop power save deny list entry for Clevo W65_67SB As the runtime PM issue was addressed by the recent fix 4961167bf748 ("ALSA: hda/via: Apply the workaround generically for Clevo machines") for VIA codecs, we need no longer to keep the Clevo device off from the power saving as default. Drop the deny list entry accordingly. Depends: 4961167bf748 ("ALSA: hda/via: Apply the workaround generically for Clevo machines") Link: https://lore.kernel.org/r/20210202092744.20321-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_intel.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'sound') diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 6c439f377a7e..801c5dd25707 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -2217,8 +2217,6 @@ static const struct snd_pci_quirk power_save_denylist[] = { /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */ SND_PCI_QUIRK(0x1043, 0x8733, "Asus Prime X370-Pro", 0), /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */ - SND_PCI_QUIRK(0x1558, 0x6504, "Clevo W65_67SB", 0), - /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */ SND_PCI_QUIRK(0x1028, 0x0497, "Dell Precision T3600", 0), /* https://bugzilla.redhat.com/show_bug.cgi?id=1525104 */ /* Note the P55A-UD3 and Z87-D3HP share the subsys id for the HDA dev */ -- cgit v1.2.3 From 3c4ab49ec59b94651dea7c7b0104c781c79c62b5 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 2 Feb 2021 23:56:29 +0100 Subject: ALSA: core: Fix the debugfs removal at snd_card_free() The commit 2d670ea2bd53 ("ALSA: jack: implement software jack injection via debugfs") introduced a debugfs root for each sound card object. The debugfs entry gets removed at the card removal, too, but it turned out that debugfs_remove() is called at a wrong place; it's after the card object gets freed, hence it leads to use-after-free. Fix it by moving the debugfs_remove() at the right place, the destructor of the card device. Fixes: 2d670ea2bd53 ("ALSA: jack: implement software jack injection via debugfs") Reported-and-tested-by: Chris Wilson Link: https://lore.kernel.org/r/161228343605.1150.8862281636043446562@build.alporthouse.com Link: https://lore.kernel.org/r/20210202225629.1965-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/init.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'sound') diff --git a/sound/core/init.c b/sound/core/init.c index d4e78b176793..84b573e9c1f9 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -487,6 +487,10 @@ static int snd_card_do_free(struct snd_card *card) dev_warn(card->dev, "unable to free card info\n"); /* Not fatal error */ } +#ifdef CONFIG_SND_DEBUG + debugfs_remove(card->debugfs_root); + card->debugfs_root = NULL; +#endif if (card->release_completion) complete(card->release_completion); kfree(card); @@ -537,11 +541,6 @@ int snd_card_free(struct snd_card *card) /* wait, until all devices are ready for the free operation */ wait_for_completion(&released); -#ifdef CONFIG_SND_DEBUG - debugfs_remove(card->debugfs_root); - card->debugfs_root = NULL; -#endif - return 0; } EXPORT_SYMBOL(snd_card_free); -- cgit v1.2.3 From 036f90dd92bb0aac66fdeec8386401dd396c6079 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 5 Feb 2021 09:28:37 +0100 Subject: ALSA: usb-audio: Correct document for snd_usb_endpoint_free_all() The kerndoc comment for the new function snd_usb_endpoint_free_all() had a typo wrt the argument name. Fix it. Fixes: 00272c61827e ("ALSA: usb-audio: Avoid unnecessary interface re-setup") Reported-by: Pierre-Louis Bossart Cc: Link: https://lore.kernel.org/r/20210205082837.6327-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/endpoint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 8e568823c992..4d1c678a0d80 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -1451,7 +1451,7 @@ void snd_usb_endpoint_release(struct snd_usb_endpoint *ep) /** * snd_usb_endpoint_free_all: Free the resources of an snd_usb_endpoint - * @card: The chip + * @chip: The chip * * This free all endpoints and those resources */ -- cgit v1.2.3 From fb3c293b82c31a9a68fbcf4e7a45fadd8a47ea2b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 5 Feb 2021 15:45:59 +0100 Subject: ALSA: usb-audio: Fix PCM buffer allocation in non-vmalloc mode The commit f274baa49be6 ("ALSA: usb-audio: Allow non-vmalloc buffer for PCM buffers") introduced the mode to allocate coherent pages for PCM buffers, and it used bus->controller device as its DMA device. It turned out, however, that bus->sysdev is a more appropriate device to be used for DMA mapping in HCD code. This patch corrects the device reference accordingly. Note that, on most platforms, both point to the very same device, hence this patch doesn't change anything practically. But on platforms like xhcd-plat hcd, the change becomes effective. Fixes: f274baa49be6 ("ALSA: usb-audio: Allow non-vmalloc buffer for PCM buffers") Cc: Link: https://lore.kernel.org/r/20210205144559.29555-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 078bb4c94033..dcadf8f164b2 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1558,7 +1558,7 @@ void snd_usb_preallocate_buffer(struct snd_usb_substream *subs) { struct snd_pcm *pcm = subs->stream->pcm; struct snd_pcm_substream *s = pcm->streams[subs->direction].substream; - struct device *dev = subs->dev->bus->controller; + struct device *dev = subs->dev->bus->sysdev; if (snd_usb_use_vmalloc) snd_pcm_set_managed_buffer(s, SNDRV_DMA_TYPE_VMALLOC, -- cgit v1.2.3 From a07df82c799013236aa90a140785775eda9f9523 Mon Sep 17 00:00:00 2001 From: Olivia Mackintosh Date: Fri, 5 Feb 2021 18:42:56 +0000 Subject: ALSA: usb-audio: Add DJM750 to Pioneer mixer quirk This allows for N different devices to use the pioneer mixer quirk for setting capture/record type and recording level. The impementation has not changed much with the exception of an additional mask on private_value to allow storing of a device index: DEVICE MASK 0xff000000 GROUP_MASK 0x00ff0000 VALUE_MASK 0x0000ffff This could be improved by changing the arrays of wValues for each channel to contain named definitions (e.g. SND_DJM_CAP_LINE). It would improve readability and perhaps would allow using the same array for multiple channels. The channel number can be specified on the control next to the wIndex. Feedback is very much appreciated as I'm not the most proficient C programmer but am learning as I go. Signed-off-by: Olivia Mackintosh Link: https://lore.kernel.org/r/20210205184256.10201-2-livvy@base.nu Signed-off-by: Takashi Iwai --- sound/usb/mixer_quirks.c | 336 ++++++++++++++++++++++++++++++----------------- 1 file changed, 216 insertions(+), 120 deletions(-) (limited to 'sound') diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index abad1d61a536..9d0ac2aa9044 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -2603,141 +2603,221 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) } /* - * Pioneer DJ DJM-250MK2 and maybe other DJM models + * Pioneer DJ DJM Mixers * - * For playback, no duplicate mapping should be set. - * There are three mixer stereo channels (CH1, CH2, AUX) - * and three stereo sources (Playback 1-2, Playback 3-4, Playback 5-6). - * Each channel should be mapped just once to one source. - * If mapped multiple times, only one source will play on given channel - * (sources are not mixed together). + * These devices generally have options for soft-switching the playback and + * capture sources in addition to the recording level. Although different + * devices have different configurations, there seems to be canonical values + * for specific capture/playback types: See the definitions of these below. * - * For recording, duplicate mapping is OK. We will get the same signal multiple times. - * - * Channels 7-8 are in both directions fixed to FX SEND / FX RETURN. - * - * See also notes in the quirks-table.h file. + * The wValue is masked with the stereo channel number. e.g. Setting Ch2 to + * capture phono would be 0x0203. Capture, playback and capture level have + * different wIndexes. */ -struct snd_pioneer_djm_option { - const u16 wIndex; - const u16 wValue; +// Capture types +#define SND_DJM_CAP_LINE 0x00 +#define SND_DJM_CAP_CDLINE 0x01 +#define SND_DJM_CAP_PHONO 0x03 +#define SND_DJM_CAP_PFADER 0x06 +#define SND_DJM_CAP_XFADERA 0x07 +#define SND_DJM_CAP_XFADERB 0x08 +#define SND_DJM_CAP_MIC 0x09 +#define SND_DJM_CAP_AUX 0x0d +#define SND_DJM_CAP_RECOUT 0x0a +#define SND_DJM_CAP_NONE 0x0f +#define SND_DJM_CAP_CH1PFADER 0x11 +#define SND_DJM_CAP_CH2PFADER 0x12 + +// Playback types +#define SND_DJM_PB_CH1 0x00 +#define SND_DJM_PB_CH2 0x01 +#define SND_DJM_PB_AUX 0x04 + +#define SND_DJM_WINDEX_CAP 0x8002 +#define SND_DJM_WINDEX_CAPLVL 0x8003 +#define SND_DJM_WINDEX_PB 0x8016 + +// kcontrol->private_value layout +#define SND_DJM_VALUE_MASK 0x0000ffff +#define SND_DJM_GROUP_MASK 0x00ff0000 +#define SND_DJM_DEVICE_MASK 0xff000000 +#define SND_DJM_GROUP_SHIFT 16 +#define SND_DJM_DEVICE_SHIFT 24 + +// device table index +#define SND_DJM_250MK2_IDX 0x0 +#define SND_DJM_750_IDX 0x1 + + +#define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \ + .name = _name, \ + .options = snd_djm_opts_##suffix, \ + .noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \ + .default_value = _default_value, \ + .wIndex = _windex } + +#define SND_DJM_DEVICE(suffix) { \ + .controls = snd_djm_ctls_##suffix, \ + .ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) } + + +struct snd_djm_device { const char *name; + const struct snd_djm_ctl *controls; + size_t ncontrols; }; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_capture_level[] = { - { .name = "-5 dB", .wValue = 0x0300, .wIndex = 0x8003 }, - { .name = "-10 dB", .wValue = 0x0200, .wIndex = 0x8003 }, - { .name = "-15 dB", .wValue = 0x0100, .wIndex = 0x8003 }, - { .name = "-19 dB", .wValue = 0x0000, .wIndex = 0x8003 } +struct snd_djm_ctl { + const char *name; + const u16 *options; + size_t noptions; + u16 default_value; + u16 wIndex; }; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_capture_ch12[] = { - { .name = "CH1 Control Tone PHONO", .wValue = 0x0103, .wIndex = 0x8002 }, - { .name = "CH1 Control Tone LINE", .wValue = 0x0100, .wIndex = 0x8002 }, - { .name = "Post CH1 Fader", .wValue = 0x0106, .wIndex = 0x8002 }, - { .name = "Cross Fader A", .wValue = 0x0107, .wIndex = 0x8002 }, - { .name = "Cross Fader B", .wValue = 0x0108, .wIndex = 0x8002 }, - { .name = "MIC", .wValue = 0x0109, .wIndex = 0x8002 }, - { .name = "AUX", .wValue = 0x010d, .wIndex = 0x8002 }, - { .name = "REC OUT", .wValue = 0x010a, .wIndex = 0x8002 } +static const char *snd_djm_get_label_caplevel(u16 wvalue) +{ + switch (wvalue) { + case 0x0000: return "-19dB"; + case 0x0100: return "-15dB"; + case 0x0200: return "-10dB"; + case 0x0300: return "-5dB"; + default: return NULL; + } }; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_capture_ch34[] = { - { .name = "CH2 Control Tone PHONO", .wValue = 0x0203, .wIndex = 0x8002 }, - { .name = "CH2 Control Tone LINE", .wValue = 0x0200, .wIndex = 0x8002 }, - { .name = "Post CH2 Fader", .wValue = 0x0206, .wIndex = 0x8002 }, - { .name = "Cross Fader A", .wValue = 0x0207, .wIndex = 0x8002 }, - { .name = "Cross Fader B", .wValue = 0x0208, .wIndex = 0x8002 }, - { .name = "MIC", .wValue = 0x0209, .wIndex = 0x8002 }, - { .name = "AUX", .wValue = 0x020d, .wIndex = 0x8002 }, - { .name = "REC OUT", .wValue = 0x020a, .wIndex = 0x8002 } +static const char *snd_djm_get_label_cap(u16 wvalue) +{ + switch (wvalue & 0x00ff) { + case SND_DJM_CAP_LINE: return "Control Tone LINE"; + case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE"; + case SND_DJM_CAP_PHONO: return "Control Tone PHONO"; + case SND_DJM_CAP_PFADER: return "Post Fader"; + case SND_DJM_CAP_XFADERA: return "Cross Fader A"; + case SND_DJM_CAP_XFADERB: return "Cross Fader B"; + case SND_DJM_CAP_MIC: return "Mic"; + case SND_DJM_CAP_RECOUT: return "Rec Out"; + case SND_DJM_CAP_AUX: return "Aux"; + case SND_DJM_CAP_NONE: return "None"; + case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1"; + case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2"; + default: return NULL; + } }; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_capture_ch56[] = { - { .name = "REC OUT", .wValue = 0x030a, .wIndex = 0x8002 }, - { .name = "Post CH1 Fader", .wValue = 0x0311, .wIndex = 0x8002 }, - { .name = "Post CH2 Fader", .wValue = 0x0312, .wIndex = 0x8002 }, - { .name = "Cross Fader A", .wValue = 0x0307, .wIndex = 0x8002 }, - { .name = "Cross Fader B", .wValue = 0x0308, .wIndex = 0x8002 }, - { .name = "MIC", .wValue = 0x0309, .wIndex = 0x8002 }, - { .name = "AUX", .wValue = 0x030d, .wIndex = 0x8002 } +static const char *snd_djm_get_label_pb(u16 wvalue) +{ + switch (wvalue & 0x00ff) { + case SND_DJM_PB_CH1: return "Ch1"; + case SND_DJM_PB_CH2: return "Ch2"; + case SND_DJM_PB_AUX: return "Aux"; + default: return NULL; + } }; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_playback_12[] = { - { .name = "CH1", .wValue = 0x0100, .wIndex = 0x8016 }, - { .name = "CH2", .wValue = 0x0101, .wIndex = 0x8016 }, - { .name = "AUX", .wValue = 0x0104, .wIndex = 0x8016 } +static const char *snd_djm_get_label(u16 wvalue, u16 windex) +{ + switch (windex) { + case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(wvalue); + case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(wvalue); + case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue); + default: return NULL; + } }; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_playback_34[] = { - { .name = "CH1", .wValue = 0x0200, .wIndex = 0x8016 }, - { .name = "CH2", .wValue = 0x0201, .wIndex = 0x8016 }, - { .name = "AUX", .wValue = 0x0204, .wIndex = 0x8016 } -}; -static const struct snd_pioneer_djm_option snd_pioneer_djm_options_playback_56[] = { - { .name = "CH1", .wValue = 0x0300, .wIndex = 0x8016 }, - { .name = "CH2", .wValue = 0x0301, .wIndex = 0x8016 }, - { .name = "AUX", .wValue = 0x0304, .wIndex = 0x8016 } +// DJM-250MK2 +static const u16 snd_djm_opts_cap_level[] = { + 0x0000, 0x0100, 0x0200, 0x0300 }; + +static const u16 snd_djm_opts_250mk2_cap1[] = { + 0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a }; + +static const u16 snd_djm_opts_250mk2_cap2[] = { + 0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a }; + +static const u16 snd_djm_opts_250mk2_cap3[] = { + 0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d }; + +static const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 }; +static const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 }; +static const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 }; + +static const struct snd_djm_ctl snd_djm_ctls_250mk2[] = { + SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), + SND_DJM_CTL("Ch1 Input", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch2 Input", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch3 Input", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch1 Output", 250mk2_pb1, 0, SND_DJM_WINDEX_PB), + SND_DJM_CTL("Ch2 Output", 250mk2_pb2, 1, SND_DJM_WINDEX_PB), + SND_DJM_CTL("Ch3 Output", 250mk2_pb3, 2, SND_DJM_WINDEX_PB) }; -struct snd_pioneer_djm_option_group { - const char *name; - const struct snd_pioneer_djm_option *options; - const size_t count; - const u16 default_value; + +// DJM-750 +static const u16 snd_djm_opts_750_cap1[] = { + 0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f }; +static const u16 snd_djm_opts_750_cap2[] = { + 0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f }; +static const u16 snd_djm_opts_750_cap3[] = { + 0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f }; +static const u16 snd_djm_opts_750_cap4[] = { + 0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f }; + +static const struct snd_djm_ctl snd_djm_ctls_750[] = { + SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), + SND_DJM_CTL("Ch1 Input", 750_cap1, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch2 Input", 750_cap2, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch3 Input", 750_cap3, 0, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch4 Input", 750_cap4, 0, SND_DJM_WINDEX_CAP) }; -#define snd_pioneer_djm_option_group_item(_name, suffix, _default_value) { \ - .name = _name, \ - .options = snd_pioneer_djm_options_##suffix, \ - .count = ARRAY_SIZE(snd_pioneer_djm_options_##suffix), \ - .default_value = _default_value } - -static const struct snd_pioneer_djm_option_group snd_pioneer_djm_option_groups[] = { - snd_pioneer_djm_option_group_item("Master Capture Level Capture Switch", capture_level, 0), - snd_pioneer_djm_option_group_item("Capture 1-2 Capture Switch", capture_ch12, 2), - snd_pioneer_djm_option_group_item("Capture 3-4 Capture Switch", capture_ch34, 2), - snd_pioneer_djm_option_group_item("Capture 5-6 Capture Switch", capture_ch56, 0), - snd_pioneer_djm_option_group_item("Playback 1-2 Playback Switch", playback_12, 0), - snd_pioneer_djm_option_group_item("Playback 3-4 Playback Switch", playback_34, 1), - snd_pioneer_djm_option_group_item("Playback 5-6 Playback Switch", playback_56, 2) + +static const struct snd_djm_device snd_djm_devices[] = { + SND_DJM_DEVICE(250mk2), + SND_DJM_DEVICE(750) }; -// layout of the kcontrol->private_value: -#define SND_PIONEER_DJM_VALUE_MASK 0x0000ffff -#define SND_PIONEER_DJM_GROUP_MASK 0xffff0000 -#define SND_PIONEER_DJM_GROUP_SHIFT 16 -static int snd_pioneer_djm_controls_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *info) +static int snd_djm_controls_info(struct snd_kcontrol *kctl, + struct snd_ctl_elem_info *info) { - u16 group_index = kctl->private_value >> SND_PIONEER_DJM_GROUP_SHIFT; - size_t count; + unsigned long private_value = kctl->private_value; + u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; + u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; + const struct snd_djm_device *device = &snd_djm_devices[device_idx]; const char *name; - const struct snd_pioneer_djm_option_group *group; + const struct snd_djm_ctl *ctl; + size_t noptions; + + if (ctl_idx >= device->ncontrols) + return -EINVAL; + + ctl = &device->controls[ctl_idx]; + noptions = ctl->noptions; + if (info->value.enumerated.item >= noptions) + info->value.enumerated.item = noptions - 1; - if (group_index >= ARRAY_SIZE(snd_pioneer_djm_option_groups)) + name = snd_djm_get_label(ctl->options[info->value.enumerated.item], + ctl->wIndex); + if (!name) return -EINVAL; - group = &snd_pioneer_djm_option_groups[group_index]; - count = group->count; - if (info->value.enumerated.item >= count) - info->value.enumerated.item = count - 1; - name = group->options[info->value.enumerated.item].name; strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name)); info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; info->count = 1; - info->value.enumerated.items = count; + info->value.enumerated.items = noptions; return 0; } -static int snd_pioneer_djm_controls_update(struct usb_mixer_interface *mixer, u16 group, u16 value) +static int snd_djm_controls_update(struct usb_mixer_interface *mixer, + u8 device_idx, u8 group, u16 value) { int err; + const struct snd_djm_device *device = &snd_djm_devices[device_idx]; - if (group >= ARRAY_SIZE(snd_pioneer_djm_option_groups) - || value >= snd_pioneer_djm_option_groups[group].count) + if ((group >= device->ncontrols) || value >= device->controls[group].noptions) return -EINVAL; err = snd_usb_lock_shutdown(mixer->chip); @@ -2748,63 +2828,76 @@ static int snd_pioneer_djm_controls_update(struct usb_mixer_interface *mixer, u1 mixer->chip->dev, usb_sndctrlpipe(mixer->chip->dev, 0), USB_REQ_SET_FEATURE, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - snd_pioneer_djm_option_groups[group].options[value].wValue, - snd_pioneer_djm_option_groups[group].options[value].wIndex, + device->controls[group].options[value], + device->controls[group].wIndex, NULL, 0); snd_usb_unlock_shutdown(mixer->chip); return err; } -static int snd_pioneer_djm_controls_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem) +static int snd_djm_controls_get(struct snd_kcontrol *kctl, + struct snd_ctl_elem_value *elem) { - elem->value.enumerated.item[0] = kctl->private_value & SND_PIONEER_DJM_VALUE_MASK; + elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK; return 0; } -static int snd_pioneer_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem) +static int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem) { struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); struct usb_mixer_interface *mixer = list->mixer; unsigned long private_value = kctl->private_value; - u16 group = (private_value & SND_PIONEER_DJM_GROUP_MASK) >> SND_PIONEER_DJM_GROUP_SHIFT; + + u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; + u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; u16 value = elem->value.enumerated.item[0]; - kctl->private_value = (group << SND_PIONEER_DJM_GROUP_SHIFT) | value; + kctl->private_value = ((device << SND_DJM_DEVICE_SHIFT) | + (group << SND_DJM_GROUP_SHIFT) | + value); - return snd_pioneer_djm_controls_update(mixer, group, value); + return snd_djm_controls_update(mixer, device, group, value); } -static int snd_pioneer_djm_controls_resume(struct usb_mixer_elem_list *list) +static int snd_djm_controls_resume(struct usb_mixer_elem_list *list) { unsigned long private_value = list->kctl->private_value; - u16 group = (private_value & SND_PIONEER_DJM_GROUP_MASK) >> SND_PIONEER_DJM_GROUP_SHIFT; - u16 value = (private_value & SND_PIONEER_DJM_VALUE_MASK); + u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; + u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; + u16 value = (private_value & SND_DJM_VALUE_MASK); - return snd_pioneer_djm_controls_update(list->mixer, group, value); + return snd_djm_controls_update(list->mixer, device, group, value); } -static int snd_pioneer_djm_controls_create(struct usb_mixer_interface *mixer) +static int snd_djm_controls_create(struct usb_mixer_interface *mixer, + const u8 device_idx) { int err, i; - const struct snd_pioneer_djm_option_group *group; + u16 value; + + const struct snd_djm_device *device = &snd_djm_devices[device_idx]; + struct snd_kcontrol_new knew = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .index = 0, - .info = snd_pioneer_djm_controls_info, - .get = snd_pioneer_djm_controls_get, - .put = snd_pioneer_djm_controls_put + .info = snd_djm_controls_info, + .get = snd_djm_controls_get, + .put = snd_djm_controls_put }; - for (i = 0; i < ARRAY_SIZE(snd_pioneer_djm_option_groups); i++) { - group = &snd_pioneer_djm_option_groups[i]; - knew.name = group->name; - knew.private_value = (i << SND_PIONEER_DJM_GROUP_SHIFT) | group->default_value; - err = snd_pioneer_djm_controls_update(mixer, i, group->default_value); + for (i = 0; i < device->ncontrols; i++) { + value = device->controls[i].default_value; + knew.name = device->controls[i].name; + knew.private_value = ( + (device_idx << SND_DJM_DEVICE_SHIFT) | + (i << SND_DJM_GROUP_SHIFT) | + value); + err = snd_djm_controls_update(mixer, device_idx, i, value); if (err) return err; - err = add_single_ctl_with_resume(mixer, 0, snd_pioneer_djm_controls_resume, + err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume, &knew, NULL); if (err) return err; @@ -2917,7 +3010,10 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) err = snd_bbfpro_controls_create(mixer); break; case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */ - err = snd_pioneer_djm_controls_create(mixer); + err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX); + break; + case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */ + err = snd_djm_controls_create(mixer, SND_DJM_750_IDX); break; } -- cgit v1.2.3 From fee03efc69345344c8851596d74d93199b175bfe Mon Sep 17 00:00:00 2001 From: Fabian Lesniak Date: Fri, 5 Feb 2021 22:51:16 +0100 Subject: ALSA: usb-audio: add mixer quirks for Pioneer DJM-900NXS2 This commit adds mixer quirks for the Pioneer DJM-900NXS2 mixer. This device has 6 capture channels, 5 of them allow setting the signal source. This adds controls for these, similar to the DJM-250Mk2. However, playpack channels are not controllable via software like on the 250Mk2, as they can only be set manually on the mixing console. Read-only controls showing the currently selected playback channels are omitted. Signed-off-by: Fabian Lesniak Link: https://lore.kernel.org/r/20210205215116.258724-2-fabian@lesniak-it.de Signed-off-by: Takashi Iwai --- sound/usb/mixer_quirks.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 9d0ac2aa9044..08873d2afe4d 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -2618,6 +2618,7 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) // Capture types #define SND_DJM_CAP_LINE 0x00 #define SND_DJM_CAP_CDLINE 0x01 +#define SND_DJM_CAP_DIGITAL 0x02 #define SND_DJM_CAP_PHONO 0x03 #define SND_DJM_CAP_PFADER 0x06 #define SND_DJM_CAP_XFADERA 0x07 @@ -2628,6 +2629,8 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) #define SND_DJM_CAP_NONE 0x0f #define SND_DJM_CAP_CH1PFADER 0x11 #define SND_DJM_CAP_CH2PFADER 0x12 +#define SND_DJM_CAP_CH3PFADER 0x13 +#define SND_DJM_CAP_CH4PFADER 0x14 // Playback types #define SND_DJM_PB_CH1 0x00 @@ -2648,6 +2651,7 @@ static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) // device table index #define SND_DJM_250MK2_IDX 0x0 #define SND_DJM_750_IDX 0x1 +#define SND_DJM_900NXS2_IDX 0x2 #define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \ @@ -2692,6 +2696,7 @@ static const char *snd_djm_get_label_cap(u16 wvalue) switch (wvalue & 0x00ff) { case SND_DJM_CAP_LINE: return "Control Tone LINE"; case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE"; + case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL"; case SND_DJM_CAP_PHONO: return "Control Tone PHONO"; case SND_DJM_CAP_PFADER: return "Post Fader"; case SND_DJM_CAP_XFADERA: return "Cross Fader A"; @@ -2702,6 +2707,8 @@ static const char *snd_djm_get_label_cap(u16 wvalue) case SND_DJM_CAP_NONE: return "None"; case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1"; case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2"; + case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3"; + case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4"; default: return NULL; } }; @@ -2774,9 +2781,32 @@ static const struct snd_djm_ctl snd_djm_ctls_750[] = { }; +// DJM-900NXS2 +static const u16 snd_djm_opts_900nxs2_cap1[] = { + 0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a }; +static const u16 snd_djm_opts_900nxs2_cap2[] = { + 0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a }; +static const u16 snd_djm_opts_900nxs2_cap3[] = { + 0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a }; +static const u16 snd_djm_opts_900nxs2_cap4[] = { + 0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a }; +static const u16 snd_djm_opts_900nxs2_cap5[] = { + 0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 }; + +static const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = { + SND_DJM_CTL("Capture Level", cap_level, 0, SND_DJM_WINDEX_CAPLVL), + SND_DJM_CTL("Ch1 Input", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch2 Input", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch3 Input", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch4 Input", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP), + SND_DJM_CTL("Ch5 Input", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP) +}; + + static const struct snd_djm_device snd_djm_devices[] = { SND_DJM_DEVICE(250mk2), - SND_DJM_DEVICE(750) + SND_DJM_DEVICE(750), + SND_DJM_DEVICE(900nxs2) }; @@ -3015,6 +3045,9 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */ err = snd_djm_controls_create(mixer, SND_DJM_750_IDX); break; + case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */ + err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX); + break; } return err; -- cgit v1.2.3 From c237813e3a1039331cf3d0bffba895b0ab52710a Mon Sep 17 00:00:00 2001 From: Jiapeng Chong Date: Sun, 7 Feb 2021 15:02:41 +0800 Subject: ALSA: azt3328: Assign boolean values to a bool variable Fix the following coccicheck warnings: ./sound/pci/azt3328.c:2451:2-16: WARNING: Assignment of 0/1 to bool variable. Reported-by: Abaci Robot Signed-off-by: Jiapeng Chong Link: https://lore.kernel.org/r/1612681361-63404-1-git-send-email-jiapeng.chong@linux.alibaba.com Signed-off-by: Takashi Iwai --- sound/pci/azt3328.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index e3ea72a2116b..2ac594dcf21c 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c @@ -2447,7 +2447,7 @@ snd_azf3328_create(struct snd_card *card, /* shutdown codecs to reduce power / noise */ /* have ...ctrl_codec_activity() act properly */ - codec->running = 1; + codec->running = true; snd_azf3328_ctrl_codec_activity(chip, codec_type, 0); spin_lock_irq(codec->lock); -- cgit v1.2.3 From f9e5fd1b666e9d34c94b91808bda02c2d4d00776 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 5 Feb 2021 20:46:28 +0200 Subject: ALSA: hda: add link_power op to hdac_bus_ops The extended HDA bus (hdac_ext) provides interfaces for more fine-grained control of individual links than what plain HDA provides for. Links can be powered off when they are not used and if all links are released, controller can shut down the command DMA. These interfaces are currently not used by common HDA codec drivers. When a HDA codec is runtime suspended, it calls snd_hdac_codec_link_down(), but there is no link to the HDA extended bus, and on controller side the links are shut down only when all codecs are suspended. This patch adds link_power() to hdac_bus ops. Controllers using the HDA extended core, can use this to plug in snd_hdac_ext_bus_link_power() to implement more fine-grained control of link power. No change is needed for plain HDA controllers nor to existing HDA codec drivers. Co-developed-by: Ranjani Sridharan Signed-off-by: Ranjani Sridharan Signed-off-by: Kai Vehmanen Acked-by: Mark Brown Link: https://lore.kernel.org/r/20210205184630.1938761-2-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai --- include/sound/hdaudio.h | 14 +++++--------- include/sound/hdaudio_ext.h | 2 ++ sound/hda/ext/hdac_ext_controller.c | 37 +++++++++++++++++++++++++++++++++++++ sound/hda/hdac_bus.c | 23 +++++++++++++++++++++++ sound/hda/hdac_controller.c | 14 ++++++++++++++ 5 files changed, 81 insertions(+), 9 deletions(-) (limited to 'sound') diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 6eed61e6cf8a..22af68b01426 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -241,6 +241,8 @@ struct hdac_bus_ops { /* get a response from the last command */ int (*get_response)(struct hdac_bus *bus, unsigned int addr, unsigned int *res); + /* notify of codec link power-up/down */ + void (*link_power)(struct hdac_device *hdev, bool enable); }; /* @@ -378,15 +380,8 @@ void snd_hdac_bus_exit(struct hdac_bus *bus); int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, unsigned int cmd, unsigned int *res); -static inline void snd_hdac_codec_link_up(struct hdac_device *codec) -{ - set_bit(codec->addr, &codec->bus->codec_powered); -} - -static inline void snd_hdac_codec_link_down(struct hdac_device *codec) -{ - clear_bit(codec->addr, &codec->bus->codec_powered); -} +void snd_hdac_codec_link_up(struct hdac_device *codec); +void snd_hdac_codec_link_down(struct hdac_device *codec); int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val); int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, @@ -400,6 +395,7 @@ void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus); void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus); void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus); int snd_hdac_bus_reset_link(struct hdac_bus *bus, bool full_reset); +void snd_hdac_bus_link_power(struct hdac_device *hdev, bool enable); void snd_hdac_bus_update_rirb(struct hdac_bus *bus); int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, diff --git a/include/sound/hdaudio_ext.h b/include/sound/hdaudio_ext.h index 7abf74c1c474..a125e3814b58 100644 --- a/include/sound/hdaudio_ext.h +++ b/include/sound/hdaudio_ext.h @@ -131,6 +131,8 @@ void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link, int snd_hdac_ext_bus_link_get(struct hdac_bus *bus, struct hdac_ext_link *link); int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, struct hdac_ext_link *link); +void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable); + /* update register macro */ #define snd_hdac_updatel(addr, reg, mask, val) \ writel(((readl(addr + reg) & ~(mask)) | (val)), \ diff --git a/sound/hda/ext/hdac_ext_controller.c b/sound/hda/ext/hdac_ext_controller.c index b0c0ef824d7d..a9bd39b93697 100644 --- a/sound/hda/ext/hdac_ext_controller.c +++ b/sound/hda/ext/hdac_ext_controller.c @@ -332,3 +332,40 @@ int snd_hdac_ext_bus_link_put(struct hdac_bus *bus, return ret; } EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_link_put); + +static void hdac_ext_codec_link_up(struct hdac_device *codec) +{ + const char *devname = dev_name(&codec->dev); + struct hdac_ext_link *hlink = + snd_hdac_ext_bus_get_link(codec->bus, devname); + + if (hlink) + snd_hdac_ext_bus_link_get(codec->bus, hlink); +} + +static void hdac_ext_codec_link_down(struct hdac_device *codec) +{ + const char *devname = dev_name(&codec->dev); + struct hdac_ext_link *hlink = + snd_hdac_ext_bus_get_link(codec->bus, devname); + + if (hlink) + snd_hdac_ext_bus_link_put(codec->bus, hlink); +} + +void snd_hdac_ext_bus_link_power(struct hdac_device *codec, bool enable) +{ + struct hdac_bus *bus = codec->bus; + bool oldstate = test_bit(codec->addr, &bus->codec_powered); + + if (enable == oldstate) + return; + + snd_hdac_bus_link_power(codec, enable); + + if (enable) + hdac_ext_codec_link_up(codec); + else + hdac_ext_codec_link_down(codec); +} +EXPORT_SYMBOL_GPL(snd_hdac_ext_bus_link_power); diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c index 9766f6af8743..71db8592b33d 100644 --- a/sound/hda/hdac_bus.c +++ b/sound/hda/hdac_bus.c @@ -17,6 +17,7 @@ static void snd_hdac_bus_process_unsol_events(struct work_struct *work); static const struct hdac_bus_ops default_ops = { .command = snd_hdac_bus_send_cmd, .get_response = snd_hdac_bus_get_response, + .link_power = snd_hdac_bus_link_power, }; /** @@ -264,3 +265,25 @@ void snd_hdac_aligned_write(unsigned int val, void __iomem *addr, } EXPORT_SYMBOL_GPL(snd_hdac_aligned_write); #endif /* CONFIG_SND_HDA_ALIGNED_MMIO */ + +void snd_hdac_codec_link_up(struct hdac_device *codec) +{ + struct hdac_bus *bus = codec->bus; + + if (bus->ops->link_power) + bus->ops->link_power(codec, true); + else + snd_hdac_bus_link_power(codec, true); +} +EXPORT_SYMBOL_GPL(snd_hdac_codec_link_up); + +void snd_hdac_codec_link_down(struct hdac_device *codec) +{ + struct hdac_bus *bus = codec->bus; + + if (bus->ops->link_power) + bus->ops->link_power(codec, false); + else + snd_hdac_bus_link_power(codec, false); +} +EXPORT_SYMBOL_GPL(snd_hdac_codec_link_down); diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c index b98449fd92f3..062da7a7a586 100644 --- a/sound/hda/hdac_controller.c +++ b/sound/hda/hdac_controller.c @@ -648,3 +648,17 @@ void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus) snd_dma_free_pages(&bus->posbuf); } EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages); + +/** + * snd_hdac_bus_link_power - power up/down codec link + * @codec: HD-audio device + * @enable: whether to power-up the link + */ +void snd_hdac_bus_link_power(struct hdac_device *codec, bool enable) +{ + if (enable) + set_bit(codec->addr, &codec->bus->codec_powered); + else + clear_bit(codec->addr, &codec->bus->codec_powered); +} +EXPORT_SYMBOL_GPL(snd_hdac_bus_link_power); -- cgit v1.2.3 From 87fc20e4a0cbc01fdfc23aeba93f8ce2fc3dccda Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 5 Feb 2021 20:46:29 +0200 Subject: ASoC: SOF: Intel: hda: use hdac_ext fine-grained link management Opt-in to use snd_hdac_ext_bus_link_power() to manage HDA link power up/down events. This allows to reduce power consumption in cases where some HDA codecs are suspended, but other child devices (HDA or non-HDA codecs) remain active and controller itself remains in active state. By using snd_hdac_ext_bus_link_power(), the individual HDA links can be powered off and if all HDA codecs are powered down, the command DMA can also be shut down. Signed-off-by: Kai Vehmanen Acked-by: Mark Brown Link: https://lore.kernel.org/r/20210205184630.1938761-3-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai --- sound/soc/sof/intel/hda-bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/soc/sof/intel/hda-bus.c b/sound/soc/sof/intel/hda-bus.c index 789148e5584b..1ac6e79d7e62 100644 --- a/sound/soc/sof/intel/hda-bus.c +++ b/sound/soc/sof/intel/hda-bus.c @@ -19,13 +19,21 @@ #define sof_hda_ext_ops NULL #endif +#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) +static const struct hdac_bus_ops bus_core_ops = { + .command = snd_hdac_bus_send_cmd, + .get_response = snd_hdac_bus_get_response, + .link_power = snd_hdac_ext_bus_link_power, +}; +#endif + /* * This can be used for both with/without hda link support. */ void sof_hda_bus_init(struct hdac_bus *bus, struct device *dev) { #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) - snd_hdac_ext_bus_init(bus, dev, NULL, sof_hda_ext_ops); + snd_hdac_ext_bus_init(bus, dev, &bus_core_ops, sof_hda_ext_ops); #else /* CONFIG_SND_SOC_SOF_HDA */ memset(bus, 0, sizeof(*bus)); bus->dev = dev; -- cgit v1.2.3 From c99fafdfccd75cb9bd91666a23ae022232afa3d5 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 5 Feb 2021 20:46:30 +0200 Subject: ASoC: SOF: Intel: hda: release display power at link_power The i915 display power is requested both by controller (for init and link reset) as well as by codec driver (for codec control). There's an additional constraint that on some platforms frequent changes to display power state may cause visible flicker. To avoid this, the SOF hda controller requests display power whenever it is active and only releases it when runtime suspended. This patch utilizes the new hdac_bus link_power op to plug into HDA link state changes. By monitoring link state changes, we can keep the controller side display power wakeref until the codec driver has completed its work, and only release the wakeref when codec driver is suspended. Signed-off-by: Kai Vehmanen Acked-by: Mark Brown Link: https://lore.kernel.org/r/20210205184630.1938761-4-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai --- sound/soc/sof/intel/hda-bus.c | 25 ++++++++++++++++++++++++- sound/soc/sof/intel/hda.h | 3 ++- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/soc/sof/intel/hda-bus.c b/sound/soc/sof/intel/hda-bus.c index 1ac6e79d7e62..30025d3c16b6 100644 --- a/sound/soc/sof/intel/hda-bus.c +++ b/sound/soc/sof/intel/hda-bus.c @@ -9,6 +9,7 @@ #include #include +#include #include "../sof-priv.h" #include "hda.h" @@ -20,10 +21,32 @@ #endif #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) +static void sof_hda_bus_link_power(struct hdac_device *codec, bool enable) +{ + struct hdac_bus *bus = codec->bus; + bool oldstate = test_bit(codec->addr, &bus->codec_powered); + + snd_hdac_ext_bus_link_power(codec, enable); + + if (enable == oldstate) + return; + + /* + * Both codec driver and controller can hold references to + * display power. To avoid unnecessary power-up/down cycles, + * controller doesn't immediately release its reference. + * + * If the codec driver powers down the link, release + * the controller reference as well. + */ + if (codec->addr == HDA_IDISP_ADDR && !enable) + snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false); +} + static const struct hdac_bus_ops bus_core_ops = { .command = snd_hdac_bus_send_cmd, .get_response = snd_hdac_bus_get_response, - .link_power = snd_hdac_ext_bus_link_power, + .link_power = sof_hda_bus_link_power, }; #endif diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h index a3b6f3e9121c..1d9b38e6ed40 100644 --- a/sound/soc/sof/intel/hda.h +++ b/sound/soc/sof/intel/hda.h @@ -388,7 +388,8 @@ #define SSP_SET_SFRM_SLAVE BIT(24) #define SSP_SET_SLAVE (SSP_SET_SCLK_SLAVE | SSP_SET_SFRM_SLAVE) -#define HDA_IDISP_CODEC(x) ((x) & BIT(2)) +#define HDA_IDISP_ADDR 2 +#define HDA_IDISP_CODEC(x) ((x) & BIT(HDA_IDISP_ADDR)) struct sof_intel_dsp_bdl { __le32 addr_l; -- cgit v1.2.3 From c50bfc8a6866775be39d7e747e83e8a5a9051e2e Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 8 Feb 2021 00:47:36 +0900 Subject: ALSA: fireface: fix to parse sync status register of latter protocol Fireface UCX, UFX, and FF802 are categorized for latter protocol of the series. Current support for FF802 (and UFX) includes failure to parse sync status register and results in EIO. Further investigation figures out that the content of register differs depending on models. This commit adds tables specific to FF802 and UFX to fix it. Fixes: 062bb452b078b ("ALSA: fireface: add support for RME FireFace 802") Cc: Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20210207154736.229551-1-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/fireface/ff-protocol-latter.c | 118 +++++++++++++++++++++++---- 1 file changed, 100 insertions(+), 18 deletions(-) (limited to 'sound') diff --git a/sound/firewire/fireface/ff-protocol-latter.c b/sound/firewire/fireface/ff-protocol-latter.c index 8d3b23778eb2..7ddb7b97f02d 100644 --- a/sound/firewire/fireface/ff-protocol-latter.c +++ b/sound/firewire/fireface/ff-protocol-latter.c @@ -15,6 +15,61 @@ #define LATTER_FETCH_MODE 0xffff00000010ULL #define LATTER_SYNC_STATUS 0x0000801c0000ULL +// The content of sync status register differs between models. +// +// Fireface UCX: +// 0xf0000000: (unidentified) +// 0x0f000000: effective rate of sampling clock +// 0x00f00000: detected rate of word clock on BNC interface +// 0x000f0000: detected rate of ADAT or S/PDIF on optical interface +// 0x0000f000: detected rate of S/PDIF on coaxial interface +// 0x00000e00: effective source of sampling clock +// 0x00000e00: Internal +// 0x00000800: (unidentified) +// 0x00000600: Word clock on BNC interface +// 0x00000400: ADAT on optical interface +// 0x00000200: S/PDIF on coaxial or optical interface +// 0x00000100: Optical interface is used for ADAT signal +// 0x00000080: (unidentified) +// 0x00000040: Synchronized to word clock on BNC interface +// 0x00000020: Synchronized to ADAT or S/PDIF on optical interface +// 0x00000010: Synchronized to S/PDIF on coaxial interface +// 0x00000008: (unidentified) +// 0x00000004: Lock word clock on BNC interface +// 0x00000002: Lock ADAT or S/PDIF on optical interface +// 0x00000001: Lock S/PDIF on coaxial interface +// +// Fireface 802 (and perhaps UFX): +// 0xf0000000: effective rate of sampling clock +// 0x0f000000: detected rate of ADAT-B on 2nd optical interface +// 0x00f00000: detected rate of ADAT-A on 1st optical interface +// 0x000f0000: detected rate of AES/EBU on XLR or coaxial interface +// 0x0000f000: detected rate of word clock on BNC interface +// 0x00000e00: effective source of sampling clock +// 0x00000e00: internal +// 0x00000800: ADAT-B +// 0x00000600: ADAT-A +// 0x00000400: AES/EBU +// 0x00000200: Word clock +// 0x00000080: Synchronized to ADAT-B on 2nd optical interface +// 0x00000040: Synchronized to ADAT-A on 1st optical interface +// 0x00000020: Synchronized to AES/EBU on XLR or 2nd optical interface +// 0x00000010: Synchronized to word clock on BNC interface +// 0x00000008: Lock ADAT-B on 2nd optical interface +// 0x00000004: Lock ADAT-A on 1st optical interface +// 0x00000002: Lock AES/EBU on XLR or 2nd optical interface +// 0x00000001: Lock word clock on BNC interface +// +// The pattern for rate bits: +// 0x00: 32.0 kHz +// 0x01: 44.1 kHz +// 0x02: 48.0 kHz +// 0x04: 64.0 kHz +// 0x05: 88.2 kHz +// 0x06: 96.0 kHz +// 0x08: 128.0 kHz +// 0x09: 176.4 kHz +// 0x0a: 192.0 kHz static int parse_clock_bits(u32 data, unsigned int *rate, enum snd_ff_clock_src *src, enum snd_ff_unit_version unit_version) @@ -23,35 +78,48 @@ static int parse_clock_bits(u32 data, unsigned int *rate, unsigned int rate; u32 flag; } *rate_entry, rate_entries[] = { - { 32000, 0x00000000, }, - { 44100, 0x01000000, }, - { 48000, 0x02000000, }, - { 64000, 0x04000000, }, - { 88200, 0x05000000, }, - { 96000, 0x06000000, }, - { 128000, 0x08000000, }, - { 176400, 0x09000000, }, - { 192000, 0x0a000000, }, + { 32000, 0x00, }, + { 44100, 0x01, }, + { 48000, 0x02, }, + { 64000, 0x04, }, + { 88200, 0x05, }, + { 96000, 0x06, }, + { 128000, 0x08, }, + { 176400, 0x09, }, + { 192000, 0x0a, }, }; static const struct { enum snd_ff_clock_src src; u32 flag; - } *clk_entry, clk_entries[] = { + } *clk_entry, *clk_entries, ucx_clk_entries[] = { { SND_FF_CLOCK_SRC_SPDIF, 0x00000200, }, { SND_FF_CLOCK_SRC_ADAT1, 0x00000400, }, { SND_FF_CLOCK_SRC_WORD, 0x00000600, }, { SND_FF_CLOCK_SRC_INTERNAL, 0x00000e00, }, + }, ufx_ff802_clk_entries[] = { + { SND_FF_CLOCK_SRC_WORD, 0x00000200, }, + { SND_FF_CLOCK_SRC_SPDIF, 0x00000400, }, + { SND_FF_CLOCK_SRC_ADAT1, 0x00000600, }, + { SND_FF_CLOCK_SRC_ADAT2, 0x00000800, }, + { SND_FF_CLOCK_SRC_INTERNAL, 0x00000e00, }, }; + u32 rate_bits; + unsigned int clk_entry_count; int i; - if (unit_version != SND_FF_UNIT_VERSION_UCX) { - // e.g. 0x00fe0f20 but expected 0x00eff002. - data = ((data & 0xf0f0f0f0) >> 4) | ((data & 0x0f0f0f0f) << 4); + if (unit_version == SND_FF_UNIT_VERSION_UCX) { + rate_bits = (data & 0x0f000000) >> 24; + clk_entries = ucx_clk_entries; + clk_entry_count = ARRAY_SIZE(ucx_clk_entries); + } else { + rate_bits = (data & 0xf0000000) >> 28; + clk_entries = ufx_ff802_clk_entries; + clk_entry_count = ARRAY_SIZE(ufx_ff802_clk_entries); } for (i = 0; i < ARRAY_SIZE(rate_entries); ++i) { rate_entry = rate_entries + i; - if ((data & 0x0f000000) == rate_entry->flag) { + if (rate_bits == rate_entry->flag) { *rate = rate_entry->rate; break; } @@ -59,14 +127,14 @@ static int parse_clock_bits(u32 data, unsigned int *rate, if (i == ARRAY_SIZE(rate_entries)) return -EIO; - for (i = 0; i < ARRAY_SIZE(clk_entries); ++i) { + for (i = 0; i < clk_entry_count; ++i) { clk_entry = clk_entries + i; if ((data & 0x000e00) == clk_entry->flag) { *src = clk_entry->src; break; } } - if (i == ARRAY_SIZE(clk_entries)) + if (i == clk_entry_count) return -EIO; return 0; @@ -249,16 +317,22 @@ static void latter_dump_status(struct snd_ff *ff, struct snd_info_buffer *buffer char *const label; u32 locked_mask; u32 synced_mask; - } *clk_entry, clk_entries[] = { + } *clk_entry, *clk_entries, ucx_clk_entries[] = { { "S/PDIF", 0x00000001, 0x00000010, }, { "ADAT", 0x00000002, 0x00000020, }, { "WDClk", 0x00000004, 0x00000040, }, + }, ufx_ff802_clk_entries[] = { + { "WDClk", 0x00000001, 0x00000010, }, + { "AES/EBU", 0x00000002, 0x00000020, }, + { "ADAT-A", 0x00000004, 0x00000040, }, + { "ADAT-B", 0x00000008, 0x00000080, }, }; __le32 reg; u32 data; unsigned int rate; enum snd_ff_clock_src src; const char *label; + unsigned int clk_entry_count; int i; int err; @@ -270,7 +344,15 @@ static void latter_dump_status(struct snd_ff *ff, struct snd_info_buffer *buffer snd_iprintf(buffer, "External source detection:\n"); - for (i = 0; i < ARRAY_SIZE(clk_entries); ++i) { + if (ff->unit_version == SND_FF_UNIT_VERSION_UCX) { + clk_entries = ucx_clk_entries; + clk_entry_count = ARRAY_SIZE(ucx_clk_entries); + } else { + clk_entries = ufx_ff802_clk_entries; + clk_entry_count = ARRAY_SIZE(ufx_ff802_clk_entries); + } + + for (i = 0; i < clk_entry_count; ++i) { clk_entry = clk_entries + i; snd_iprintf(buffer, "%s: ", clk_entry->label); if (data & clk_entry->locked_mask) { -- cgit v1.2.3 From d6cda4655e2a7612a1e48c49795a5330abc01c5a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:30:50 +0100 Subject: ALSA: usb-audio: Handle invalid running state at releasing EP When we stop an endpoint in release_urbs(), it ignores the inconsistent endpoint state and tries to release the resources. This shouldn't happen in theory, but it's still safer to abort the release and let the caller proper error handling. Also, stop_and_unlink_urbs() called from release_urbs() does two step works, and it's more straightforward to split this to two functions again, so that the call from the PCM trigger won't take the path with sleeping. This patch modifies the EP management code to adapt two points above. Fixes: d0f09d1e4a88 ("ALSA: usb-audio: Refactoring endpoint URB deactivation") Cc: Link: https://lore.kernel.org/r/20210206203052.15606-2-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/endpoint.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'sound') diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 4d1c678a0d80..e102c024c21f 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -868,24 +868,22 @@ void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep) } /* - * Stop and unlink active urbs. + * Stop active urbs * - * This function checks and clears EP_FLAG_RUNNING state. - * When @wait_sync is set, it waits until all pending URBs are killed. + * This function moves the EP to STOPPING state if it's being RUNNING. */ -static int stop_and_unlink_urbs(struct snd_usb_endpoint *ep, bool force, - bool wait_sync) +static int stop_urbs(struct snd_usb_endpoint *ep, bool force) { unsigned int i; if (!force && atomic_read(&ep->chip->shutdown)) /* to be sure... */ return -EBADFD; - if (atomic_read(&ep->running)) + if (!force && atomic_read(&ep->running)) return -EBUSY; if (!test_and_clear_bit(EP_FLAG_RUNNING, &ep->flags)) - goto out; + return 0; set_bit(EP_FLAG_STOPPING, &ep->flags); INIT_LIST_HEAD(&ep->ready_playback_urbs); @@ -901,24 +899,25 @@ static int stop_and_unlink_urbs(struct snd_usb_endpoint *ep, bool force, } } - out: - if (wait_sync) - return wait_clear_urbs(ep); return 0; } /* * release an endpoint's urbs */ -static void release_urbs(struct snd_usb_endpoint *ep, int force) +static int release_urbs(struct snd_usb_endpoint *ep, bool force) { - int i; + int i, err; /* route incoming urbs to nirvana */ snd_usb_endpoint_set_callback(ep, NULL, NULL, NULL); - /* stop urbs */ - stop_and_unlink_urbs(ep, force, true); + /* stop and unlink urbs */ + err = stop_urbs(ep, force); + if (err) + return err; + + wait_clear_urbs(ep); for (i = 0; i < ep->nurbs; i++) release_urb_ctx(&ep->urb[i]); @@ -928,6 +927,7 @@ static void release_urbs(struct snd_usb_endpoint *ep, int force) ep->syncbuf = NULL; ep->nurbs = 0; + return 0; } /* @@ -1118,7 +1118,7 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep) return 0; out_of_memory: - release_urbs(ep, 0); + release_urbs(ep, false); return -ENOMEM; } @@ -1162,7 +1162,7 @@ static int sync_ep_set_params(struct snd_usb_endpoint *ep) return 0; out_of_memory: - release_urbs(ep, 0); + release_urbs(ep, false); return -ENOMEM; } @@ -1180,7 +1180,9 @@ static int snd_usb_endpoint_set_params(struct snd_usb_audio *chip, int err; /* release old buffers, if any */ - release_urbs(ep, 0); + err = release_urbs(ep, false); + if (err < 0) + return err; ep->datainterval = fmt->datainterval; ep->maxpacksize = fmt->maxpacksize; @@ -1433,7 +1435,7 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep) WRITE_ONCE(ep->sync_source->sync_sink, NULL); if (!atomic_dec_return(&ep->running)) - stop_and_unlink_urbs(ep, false, false); + stop_urbs(ep, false); } /** @@ -1446,7 +1448,7 @@ void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep) */ void snd_usb_endpoint_release(struct snd_usb_endpoint *ep) { - release_urbs(ep, 1); + release_urbs(ep, true); } /** -- cgit v1.2.3 From 5c2b301476ec493be15546f05e23414e2aa9d472 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:30:51 +0100 Subject: ALSA: usb-audio: More strict state change in EP The endpoint management has bit flags to indicate the current state, and we're dealing two things: the running bit and the stopping bit. There is a thin window in transition from the running to the stopping in stop_urbs(), and as long as the bit flags are used, it's difficult to plug. This patch modifies the state management code to use the atomic int and follow the explicit three states, STOPPED, RUNNING and STOPPING. The state change is done via atomic_cmpxhg() for avoiding possible races, and check the state change more strictly. The unexpected state change is now handled as an error. Fixes: d0f09d1e4a88 ("ALSA: usb-audio: Refactoring endpoint URB deactivation") Cc: Link: https://lore.kernel.org/r/20210206203052.15606-3-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/card.h | 2 +- sound/usb/endpoint.c | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'sound') diff --git a/sound/usb/card.h b/sound/usb/card.h index 37091b117614..a741e7da83a2 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -71,7 +71,7 @@ struct snd_usb_endpoint { unsigned char altsetting; /* corresponding alternate setting */ unsigned char ep_idx; /* endpoint array index */ - unsigned long flags; /* running bit flags */ + atomic_t state; /* running state */ void (*prepare_data_urb) (struct snd_usb_substream *subs, struct urb *urb); diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index e102c024c21f..4390075b2c6f 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -21,8 +21,11 @@ #include "clock.h" #include "quirks.h" -#define EP_FLAG_RUNNING 1 -#define EP_FLAG_STOPPING 2 +enum { + EP_STATE_STOPPED, + EP_STATE_RUNNING, + EP_STATE_STOPPING, +}; /* interface refcounting */ struct snd_usb_iface_ref { @@ -115,6 +118,16 @@ static const char *usb_error_string(int err) } } +static inline bool ep_state_running(struct snd_usb_endpoint *ep) +{ + return atomic_read(&ep->state) == EP_STATE_RUNNING; +} + +static inline bool ep_state_update(struct snd_usb_endpoint *ep, int old, int new) +{ + return atomic_cmpxchg(&ep->state, old, new) == old; +} + /** * snd_usb_endpoint_implicit_feedback_sink: Report endpoint usage type * @@ -393,7 +406,7 @@ next_packet_fifo_dequeue(struct snd_usb_endpoint *ep) */ static void queue_pending_output_urbs(struct snd_usb_endpoint *ep) { - while (test_bit(EP_FLAG_RUNNING, &ep->flags)) { + while (ep_state_running(ep)) { unsigned long flags; struct snd_usb_packet_info *packet; @@ -454,13 +467,13 @@ static void snd_complete_urb(struct urb *urb) if (unlikely(atomic_read(&ep->chip->shutdown))) goto exit_clear; - if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) + if (unlikely(!ep_state_running(ep))) goto exit_clear; if (usb_pipeout(ep->pipe)) { retire_outbound_urb(ep, ctx); /* can be stopped during retire callback */ - if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) + if (unlikely(!ep_state_running(ep))) goto exit_clear; if (snd_usb_endpoint_implicit_feedback_sink(ep)) { @@ -474,12 +487,12 @@ static void snd_complete_urb(struct urb *urb) prepare_outbound_urb(ep, ctx); /* can be stopped during prepare callback */ - if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) + if (unlikely(!ep_state_running(ep))) goto exit_clear; } else { retire_inbound_urb(ep, ctx); /* can be stopped during retire callback */ - if (unlikely(!test_bit(EP_FLAG_RUNNING, &ep->flags))) + if (unlikely(!ep_state_running(ep))) goto exit_clear; prepare_inbound_urb(ep, ctx); @@ -835,7 +848,7 @@ static int wait_clear_urbs(struct snd_usb_endpoint *ep) unsigned long end_time = jiffies + msecs_to_jiffies(1000); int alive; - if (!test_bit(EP_FLAG_STOPPING, &ep->flags)) + if (atomic_read(&ep->state) != EP_STATE_STOPPING) return 0; do { @@ -850,10 +863,11 @@ static int wait_clear_urbs(struct snd_usb_endpoint *ep) usb_audio_err(ep->chip, "timeout: still %d active urbs on EP #%x\n", alive, ep->ep_num); - clear_bit(EP_FLAG_STOPPING, &ep->flags); - ep->sync_sink = NULL; - snd_usb_endpoint_set_callback(ep, NULL, NULL, NULL); + if (ep_state_update(ep, EP_STATE_STOPPING, EP_STATE_STOPPED)) { + ep->sync_sink = NULL; + snd_usb_endpoint_set_callback(ep, NULL, NULL, NULL); + } return 0; } @@ -882,10 +896,9 @@ static int stop_urbs(struct snd_usb_endpoint *ep, bool force) if (!force && atomic_read(&ep->running)) return -EBUSY; - if (!test_and_clear_bit(EP_FLAG_RUNNING, &ep->flags)) + if (!ep_state_update(ep, EP_STATE_RUNNING, EP_STATE_STOPPING)) return 0; - set_bit(EP_FLAG_STOPPING, &ep->flags); INIT_LIST_HEAD(&ep->ready_playback_urbs); ep->next_packet_head = 0; ep->next_packet_queued = 0; @@ -1362,7 +1375,8 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep) * from that context. */ - set_bit(EP_FLAG_RUNNING, &ep->flags); + if (!ep_state_update(ep, EP_STATE_STOPPED, EP_STATE_RUNNING)) + goto __error; if (snd_usb_endpoint_implicit_feedback_sink(ep)) { for (i = 0; i < ep->nurbs; i++) { -- cgit v1.2.3 From 257d2d7e9e798305d65825cb82b0a7d1c0511e89 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:30:52 +0100 Subject: ALSA: usb-audio: Don't avoid stopping the stream at disconnection In the later patch, we're going to issue the PCM sync_stop calls at disconnection. But currently the USB-audio driver can't handle it because it has a check of shutdown flag for stopping the URBs. This is basically superfluous (the stopping URBs are safe at disconnection state), so let's drop the check. Fixes: dc5eafe7787c ("ALSA: usb-audio: Support PCM sync_stop") Cc: Link: https://lore.kernel.org/r/20210206203052.15606-4-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/endpoint.c | 3 --- sound/usb/pcm.c | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'sound') diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 4390075b2c6f..102d53515a76 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -890,9 +890,6 @@ static int stop_urbs(struct snd_usb_endpoint *ep, bool force) { unsigned int i; - if (!force && atomic_read(&ep->chip->shutdown)) /* to be sure... */ - return -EBADFD; - if (!force && atomic_read(&ep->running)) return -EBUSY; diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index dcadf8f164b2..bf5a0f3c1fad 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -270,10 +270,7 @@ static int snd_usb_pcm_sync_stop(struct snd_pcm_substream *substream) { struct snd_usb_substream *subs = substream->runtime->private_data; - if (!snd_usb_lock_shutdown(subs->stream->chip)) { - sync_pending_stops(subs); - snd_usb_unlock_shutdown(subs->stream->chip); - } + sync_pending_stops(subs); return 0; } -- cgit v1.2.3 From 29bb274e94974669acb5186a75538f20df1508b6 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:36:53 +0100 Subject: ALSA: pcm: Call sync_stop at disconnection The PCM core should perform the sync for the pending stop operations at disconnection. Otherwise it may lead to unexpected access. Currently the old user of sync_stop, USB-audio driver, has its own sync, so this isn't needed, but it's better to guarantee the sync in the PCM core level. This patch adds the missing sync_stop call at PCM disconnection callback. It also assures the IRQ sync if it's specified in the card. snd_pcm_sync_stop() is slightly modified to be called also for any PCM substream object now. Fixes: 1e850beea278 ("ALSA: pcm: Add the support for sync-stop operation") Cc: Link: https://lore.kernel.org/r/20210206203656.15959-2-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/init.c | 4 ++++ sound/core/pcm.c | 4 ++++ sound/core/pcm_local.h | 1 + sound/core/pcm_native.c | 16 ++++++++-------- 4 files changed, 17 insertions(+), 8 deletions(-) (limited to 'sound') diff --git a/sound/core/init.c b/sound/core/init.c index 84b573e9c1f9..45f4b01de23f 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -426,6 +427,9 @@ int snd_card_disconnect(struct snd_card *card) /* notify all devices that we are disconnected */ snd_device_disconnect_all(card); + if (card->sync_irq > 0) + synchronize_irq(card->sync_irq); + snd_info_card_disconnect(card); if (card->registered) { device_del(&card->card_dev); diff --git a/sound/core/pcm.c b/sound/core/pcm.c index e5947281e5fc..50eb29fcdfe7 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1111,6 +1111,10 @@ static int snd_pcm_dev_disconnect(struct snd_device *device) } } + for (cidx = 0; cidx < 2; cidx++) + for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) + snd_pcm_sync_stop(substream, false); + pcm_call_notify(pcm, n_disconnect); for (cidx = 0; cidx < 2; cidx++) { snd_unregister_device(&pcm->streams[cidx].dev); diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h index 17a1a5d87098..b3e8be5aeafb 100644 --- a/sound/core/pcm_local.h +++ b/sound/core/pcm_local.h @@ -63,6 +63,7 @@ static inline void snd_pcm_timer_done(struct snd_pcm_substream *substream) {} void __snd_pcm_xrun(struct snd_pcm_substream *substream); void snd_pcm_group_init(struct snd_pcm_group *group); +void snd_pcm_sync_stop(struct snd_pcm_substream *substream, bool sync_irq); #ifdef CONFIG_SND_DMA_SGBUF struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 893c2abb2f63..1f5acf08cdcd 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -583,13 +583,13 @@ static inline void snd_pcm_timer_notify(struct snd_pcm_substream *substream, #endif } -static void snd_pcm_sync_stop(struct snd_pcm_substream *substream) +void snd_pcm_sync_stop(struct snd_pcm_substream *substream, bool sync_irq) { - if (substream->runtime->stop_operating) { + if (substream->runtime && substream->runtime->stop_operating) { substream->runtime->stop_operating = false; - if (substream->ops->sync_stop) + if (substream->ops && substream->ops->sync_stop) substream->ops->sync_stop(substream); - else if (substream->pcm->card->sync_irq > 0) + else if (sync_irq && substream->pcm->card->sync_irq > 0) synchronize_irq(substream->pcm->card->sync_irq); } } @@ -686,7 +686,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, if (atomic_read(&substream->mmap_count)) return -EBADFD; - snd_pcm_sync_stop(substream); + snd_pcm_sync_stop(substream, true); params->rmask = ~0U; err = snd_pcm_hw_refine(substream, params); @@ -809,7 +809,7 @@ static int do_hw_free(struct snd_pcm_substream *substream) { int result = 0; - snd_pcm_sync_stop(substream); + snd_pcm_sync_stop(substream, true); if (substream->ops->hw_free) result = substream->ops->hw_free(substream); if (substream->managed_buffer_alloc) @@ -1736,7 +1736,7 @@ static void snd_pcm_post_resume(struct snd_pcm_substream *substream, snd_pcm_trigger_tstamp(substream); runtime->status->state = runtime->status->suspended_state; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MRESUME); - snd_pcm_sync_stop(substream); + snd_pcm_sync_stop(substream, true); } static const struct action_ops snd_pcm_action_resume = { @@ -1866,7 +1866,7 @@ static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { int err; - snd_pcm_sync_stop(substream); + snd_pcm_sync_stop(substream, true); err = substream->ops->prepare(substream); if (err < 0) return err; -- cgit v1.2.3 From 2c87c1a49c9d113a9f3e8e951d7d64be5ff50ac1 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:36:54 +0100 Subject: ALSA: pcm: Assure sync with the pending stop operation at suspend The current PCM code calls the sync_stop at the resume action due to the analogy to the PCM prepare call pattern. But, it makes little sense, as the sync should have been done rather at the suspend time, not at the resume time. This patch corrects the sync_stop call at suspend/resume to assure the sync before finishing the suspend. Fixes: 1e850beea278 ("ALSA: pcm: Add the support for sync-stop operation") Cc: Link: https://lore.kernel.org/r/20210206203656.15959-3-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/pcm_native.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'sound') diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 1f5acf08cdcd..cbbdb75c66ea 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1615,6 +1615,7 @@ static int snd_pcm_do_suspend(struct snd_pcm_substream *substream, if (! snd_pcm_running(substream)) return 0; substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); + runtime->stop_operating = true; return 0; /* suspend unconditionally */ } @@ -1691,6 +1692,12 @@ int snd_pcm_suspend_all(struct snd_pcm *pcm) return err; } } + + for (stream = 0; stream < 2; stream++) + for (substream = pcm->streams[stream].substream; + substream; substream = substream->next) + snd_pcm_sync_stop(substream, false); + return 0; } EXPORT_SYMBOL(snd_pcm_suspend_all); @@ -1736,7 +1743,6 @@ static void snd_pcm_post_resume(struct snd_pcm_substream *substream, snd_pcm_trigger_tstamp(substream); runtime->status->state = runtime->status->suspended_state; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MRESUME); - snd_pcm_sync_stop(substream, true); } static const struct action_ops snd_pcm_action_resume = { -- cgit v1.2.3 From 700cb70730777c159a988e01daa93f20a1ae9b58 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:36:55 +0100 Subject: ALSA: pcm: Don't call sync_stop if it hasn't been stopped The PCM stop operation sets the stop_operating flag for indicating the sync_stop post-process. This flag is, however, set unconditionally even if the PCM trigger weren't issued. This may lead to inconsistency in the driver side. Correct the code to set stop_operating flag only after the trigger STOP is actually called. Fixes: 1e850beea278 ("ALSA: pcm: Add the support for sync-stop operation") Cc: Link: https://lore.kernel.org/r/20210206203656.15959-4-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/pcm_native.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sound') diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index cbbdb75c66ea..0ae2475465ab 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1421,8 +1421,10 @@ static int snd_pcm_do_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream && - snd_pcm_running(substream)) + snd_pcm_running(substream)) { substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); + substream->runtime->stop_operating = true; + } return 0; /* unconditonally stop all substreams */ } @@ -1435,7 +1437,6 @@ static void snd_pcm_post_stop(struct snd_pcm_substream *substream, runtime->status->state = state; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTOP); } - runtime->stop_operating = true; wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } -- cgit v1.2.3 From 8d19b4e0b377e226b98f26ded5f0c6463976e4fb Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 6 Feb 2021 21:36:56 +0100 Subject: ALSA: pcm: Use for_each_pcm_substream() macro There are a few places doing the same loop iterating all PCM substreams belonging to the PCM object. Introduce a local helper macro, for_each_pcm_substream(), to simplify the code. Link: https://lore.kernel.org/r/20210206203656.15959-5-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/core/pcm.c | 29 +++++++++++++---------------- sound/core/pcm_local.h | 6 ++++++ sound/core/pcm_memory.c | 12 ++++-------- sound/core/pcm_native.c | 35 +++++++++++++++-------------------- 4 files changed, 38 insertions(+), 44 deletions(-) (limited to 'sound') diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 50eb29fcdfe7..b163164a83ec 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1095,25 +1095,22 @@ static int snd_pcm_dev_disconnect(struct snd_device *device) mutex_lock(&pcm->open_mutex); wake_up(&pcm->open_wait); list_del_init(&pcm->list); - for (cidx = 0; cidx < 2; cidx++) { - for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) { - snd_pcm_stream_lock_irq(substream); - if (substream->runtime) { - if (snd_pcm_running(substream)) - snd_pcm_stop(substream, - SNDRV_PCM_STATE_DISCONNECTED); - /* to be sure, set the state unconditionally */ - substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED; - wake_up(&substream->runtime->sleep); - wake_up(&substream->runtime->tsleep); - } - snd_pcm_stream_unlock_irq(substream); + + for_each_pcm_substream(pcm, cidx, substream) { + snd_pcm_stream_lock_irq(substream); + if (substream->runtime) { + if (snd_pcm_running(substream)) + snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED); + /* to be sure, set the state unconditionally */ + substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED; + wake_up(&substream->runtime->sleep); + wake_up(&substream->runtime->tsleep); } + snd_pcm_stream_unlock_irq(substream); } - for (cidx = 0; cidx < 2; cidx++) - for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) - snd_pcm_sync_stop(substream, false); + for_each_pcm_substream(pcm, cidx, substream) + snd_pcm_sync_stop(substream, false); pcm_call_notify(pcm, n_disconnect); for (cidx = 0; cidx < 2; cidx++) { diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h index b3e8be5aeafb..e3b3558aeab6 100644 --- a/sound/core/pcm_local.h +++ b/sound/core/pcm_local.h @@ -72,4 +72,10 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime) +/* loop over all PCM substreams */ +#define for_each_pcm_substream(pcm, str, subs) \ + for ((str) = 0; (str) < 2; (str)++) \ + for ((subs) = (pcm)->streams[str].substream; (subs); \ + (subs) = (subs)->next) + #endif /* __SOUND_CORE_PCM_LOCAL_H */ diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c index ee6e9c5eec45..289dd1fd8fe7 100644 --- a/sound/core/pcm_memory.c +++ b/sound/core/pcm_memory.c @@ -111,9 +111,8 @@ void snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm) struct snd_pcm_substream *substream; int stream; - for (stream = 0; stream < 2; stream++) - for (substream = pcm->streams[stream].substream; substream; substream = substream->next) - snd_pcm_lib_preallocate_free(substream); + for_each_pcm_substream(pcm, stream, substream) + snd_pcm_lib_preallocate_free(substream); } EXPORT_SYMBOL(snd_pcm_lib_preallocate_free_for_all); @@ -246,11 +245,8 @@ static void preallocate_pages_for_all(struct snd_pcm *pcm, int type, struct snd_pcm_substream *substream; int stream; - for (stream = 0; stream < 2; stream++) - for (substream = pcm->streams[stream].substream; substream; - substream = substream->next) - preallocate_pages(substream, type, data, size, max, - managed); + for_each_pcm_substream(pcm, stream, substream) + preallocate_pages(substream, type, data, size, max, managed); } /** diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 0ae2475465ab..17a85f4815d5 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1674,30 +1674,25 @@ int snd_pcm_suspend_all(struct snd_pcm *pcm) if (! pcm) return 0; - for (stream = 0; stream < 2; stream++) { - for (substream = pcm->streams[stream].substream; - substream; substream = substream->next) { - /* FIXME: the open/close code should lock this as well */ - if (substream->runtime == NULL) - continue; + for_each_pcm_substream(pcm, stream, substream) { + /* FIXME: the open/close code should lock this as well */ + if (!substream->runtime) + continue; - /* - * Skip BE dai link PCM's that are internal and may - * not have their substream ops set. - */ - if (!substream->ops) - continue; + /* + * Skip BE dai link PCM's that are internal and may + * not have their substream ops set. + */ + if (!substream->ops) + continue; - err = snd_pcm_suspend(substream); - if (err < 0 && err != -EBUSY) - return err; - } + err = snd_pcm_suspend(substream); + if (err < 0 && err != -EBUSY) + return err; } - for (stream = 0; stream < 2; stream++) - for (substream = pcm->streams[stream].substream; - substream; substream = substream->next) - snd_pcm_sync_stop(substream, false); + for_each_pcm_substream(pcm, stream, substream) + snd_pcm_sync_stop(substream, false); return 0; } -- cgit v1.2.3 From 5427c7d6296ee574037c4a6649ac45a9474d1f13 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 8 Feb 2021 14:59:19 +0100 Subject: ALSA: hda: intel-dsp-config: Add SND_INTEL_BYT_PREFER_SOF Kconfig option The kernel has 2 drivers for the Low Power Engine audio-block on Bay- and Cherry-Trail SoCs. The old SST driver and the new SOF driver. If both drivers are enabled then the kernel will default to using the old SST driver, unless told otherwise through the snd_intel_dspcfg.dsp_driver module-parameter. Add a boolean SND_INTEL_BYT_PREFER_SOF Kconfig option, which when set to Y will make the kernel default to the new SOF driver instead. The option defaults to n, preserving the current behavior. Making this configurable will help distributions such as Fedora: https://fedoraproject.org/w/index.php?title=Changes/SofDefaultForIntelLpe to test using SOF on BYT/CHT during the transition phase where we have both drivers (eventually the old driver and this option will be removed). Note that this drops the acpi_config_table[] containing 2 entries per ACPI hardware-id if both drivers are enabled. snd_intel_acpi_dsp_find_config() will always return the first hit, so we only need a single entry with the flags value set depending on the Kconfig settings. Suggested-by: Takashi Iwai Signed-off-by: Hans de Goede Reviewed-by: Pierre-Louis Bossart Link: https://lore.kernel.org/r/20210208135919.135600-1-hdegoede@redhat.com Signed-off-by: Takashi Iwai --- sound/hda/Kconfig | 14 ++++++++++++++ sound/hda/intel-dsp-config.c | 29 ++++++++++++----------------- 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'sound') diff --git a/sound/hda/Kconfig b/sound/hda/Kconfig index 3bc9224d5e4f..9ed5cfa3c18c 100644 --- a/sound/hda/Kconfig +++ b/sound/hda/Kconfig @@ -46,3 +46,17 @@ config SND_INTEL_DSP_CONFIG select SND_INTEL_NHLT if ACPI # this config should be selected only for Intel DSP platforms. # A fallback is provided so that the code compiles in all cases. + +config SND_INTEL_BYT_PREFER_SOF + bool "Prefer SOF driver over SST on BY/CHT platforms" + depends on SND_SST_ATOM_HIFI2_PLATFORM_ACPI && SND_SOC_SOF_BAYTRAIL + default n + help + The kernel has 2 drivers for the Low Power Engine audio-block on + Bay- and Cherry-Trail SoCs. The old SST driver and the new SOF + driver. If both drivers are enabled then the kernel will default + to using the old SST driver, unless told otherwise through the + snd_intel_dspcfg.dsp_driver module-parameter. + + Set this option to Y to make the kernel default to the new SOF + driver instead. diff --git a/sound/hda/intel-dsp-config.c b/sound/hda/intel-dsp-config.c index c45686172517..68bb977c6a37 100644 --- a/sound/hda/intel-dsp-config.c +++ b/sound/hda/intel-dsp-config.c @@ -452,35 +452,30 @@ int snd_intel_dsp_driver_probe(struct pci_dev *pci) } EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe); +/* Should we default to SOF or SST for BYT/CHT ? */ +#if IS_ENABLED(CONFIG_SND_INTEL_BYT_PREFER_SOF) || \ + !IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) +#define FLAG_SST_OR_SOF_BYT FLAG_SOF +#else +#define FLAG_SST_OR_SOF_BYT FLAG_SST +#endif + /* * configuration table * - the order of similar ACPI ID entries is important! * - the first successful match will win */ static const struct config_entry acpi_config_table[] = { +#if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) || \ + IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) /* BayTrail */ -#if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) - { - .flags = FLAG_SST, - .acpi_hid = "80860F28", - }, -#endif -#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) { - .flags = FLAG_SOF, + .flags = FLAG_SST_OR_SOF_BYT, .acpi_hid = "80860F28", }, -#endif /* CherryTrail */ -#if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) - { - .flags = FLAG_SST, - .acpi_hid = "808622A8", - }, -#endif -#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) { - .flags = FLAG_SOF, + .flags = FLAG_SST_OR_SOF_BYT, .acpi_hid = "808622A8", }, #endif -- cgit v1.2.3 From 2c28156d88aa36ee8d45a3e68cc7eaa7d919dd96 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 10 Feb 2021 09:37:13 +0100 Subject: ALSA: core - add missing compress device type to /proc/asound/devices Signed-off-by: Jaroslav Kysela Acked-by: Vinod Koul Link: https://lore.kernel.org/r/20210210083713.1034201-1-perex@perex.cz Signed-off-by: Takashi Iwai --- sound/core/sound.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound') diff --git a/sound/core/sound.c b/sound/core/sound.c index 2f759febe365..af89e51dd44a 100644 --- a/sound/core/sound.c +++ b/sound/core/sound.c @@ -343,6 +343,8 @@ static const char *snd_device_type_name(int type) return "sequencer"; case SNDRV_DEVICE_TYPE_TIMER: return "timer"; + case SNDRV_DEVICE_TYPE_COMPRESS: + return "compress"; default: return "?"; } -- cgit v1.2.3 From 15447b64789d9ade71eb374d5ae1f37d0bbce0bd Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sun, 14 Feb 2021 16:42:51 +0100 Subject: ALSA: usb-audio: Add implicit fb quirk for BOSS GP-10 BOSS GP-10 with 0582:0185 requires the similar quirk to make the implicit feedback working like other BOSS devices. Reported-by: Keith Milner Cc: Link: https://lore.kernel.org/r/20210214154251.10750-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/usb/implicit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound') diff --git a/sound/usb/implicit.c b/sound/usb/implicit.c index e7216d0b860d..11a85e66aa96 100644 --- a/sound/usb/implicit.c +++ b/sound/usb/implicit.c @@ -73,6 +73,7 @@ static const struct snd_usb_implicit_fb_match playback_implicit_fb_quirks[] = { /* No quirk for playback but with capture quirk (see below) */ IMPLICIT_FB_SKIP_DEV(0x0582, 0x0130), /* BOSS BR-80 */ IMPLICIT_FB_SKIP_DEV(0x0582, 0x0171), /* BOSS RC-505 */ + IMPLICIT_FB_SKIP_DEV(0x0582, 0x0185), /* BOSS GP-10 */ IMPLICIT_FB_SKIP_DEV(0x0582, 0x0189), /* BOSS GT-100v2 */ IMPLICIT_FB_SKIP_DEV(0x0582, 0x01d6), /* BOSS GT-1 */ IMPLICIT_FB_SKIP_DEV(0x0582, 0x01d8), /* BOSS Katana */ @@ -86,6 +87,7 @@ static const struct snd_usb_implicit_fb_match playback_implicit_fb_quirks[] = { static const struct snd_usb_implicit_fb_match capture_implicit_fb_quirks[] = { IMPLICIT_FB_FIXED_DEV(0x0582, 0x0130, 0x0d, 0x01), /* BOSS BR-80 */ IMPLICIT_FB_FIXED_DEV(0x0582, 0x0171, 0x0d, 0x01), /* BOSS RC-505 */ + IMPLICIT_FB_FIXED_DEV(0x0582, 0x0185, 0x0d, 0x01), /* BOSS GP-10 */ IMPLICIT_FB_FIXED_DEV(0x0582, 0x0189, 0x0d, 0x01), /* BOSS GT-100v2 */ IMPLICIT_FB_FIXED_DEV(0x0582, 0x01d6, 0x0d, 0x01), /* BOSS GT-1 */ IMPLICIT_FB_FIXED_DEV(0x0582, 0x01d8, 0x0d, 0x01), /* BOSS Katana */ -- cgit v1.2.3