diff options
Diffstat (limited to 'sound/pci/echoaudio/echoaudio.c')
| -rw-r--r-- | sound/pci/echoaudio/echoaudio.c | 170 |
1 files changed, 61 insertions, 109 deletions
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index c70c3ac4e99a..f2c8602a1ad7 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -6,6 +6,7 @@ */ #include <linux/module.h> +#include <linux/string.h> MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>"); MODULE_LICENSE("GPL v2"); @@ -34,7 +35,6 @@ static int get_firmware(const struct firmware **fw_entry, int err; char name[30]; -#ifdef CONFIG_PM_SLEEP if (chip->fw_cache[fw_index]) { dev_dbg(chip->card->dev, "firmware requested: %s is cached\n", @@ -42,7 +42,6 @@ static int get_firmware(const struct firmware **fw_entry, *fw_entry = chip->fw_cache[fw_index]; return 0; } -#endif dev_dbg(chip->card->dev, "firmware requested: %s\n", card_fw[fw_index].data); @@ -51,10 +50,8 @@ static int get_firmware(const struct firmware **fw_entry, if (err < 0) dev_err(chip->card->dev, "get_firmware(): Firmware not available (%d)\n", err); -#ifdef CONFIG_PM_SLEEP else chip->fw_cache[fw_index] = *fw_entry; -#endif return err; } @@ -63,18 +60,13 @@ static int get_firmware(const struct firmware **fw_entry, static void free_firmware(const struct firmware *fw_entry, struct echoaudio *chip) { -#ifdef CONFIG_PM_SLEEP dev_dbg(chip->card->dev, "firmware not released (kept in cache)\n"); -#else - release_firmware(fw_entry); -#endif } static void free_firmware_cache(struct echoaudio *chip) { -#ifdef CONFIG_PM_SLEEP int i; for (i = 0; i < 8 ; i++) @@ -82,8 +74,6 @@ static void free_firmware_cache(struct echoaudio *chip) release_firmware(chip->fw_cache[i]); dev_dbg(chip->card->dev, "release_firmware(%d)\n", i); } - -#endif } @@ -247,7 +237,7 @@ static int hw_rule_sample_rate(struct snd_pcm_hw_params *params, struct snd_interval fixed; int err; - mutex_lock(&chip->mode_mutex); + guard(mutex)(&chip->mode_mutex); if (chip->can_set_rate) { err = 0; @@ -257,7 +247,6 @@ static int hw_rule_sample_rate(struct snd_pcm_hw_params *params, err = snd_interval_refine(rate, &fixed); } - mutex_unlock(&chip->mode_mutex); return err; } @@ -425,7 +414,7 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream) int err, max_channels; max_channels = num_digital_busses_in(chip) - substream->number; - mutex_lock(&chip->mode_mutex); + guard(mutex)(&chip->mode_mutex); if (chip->digital_mode == DIGITAL_MODE_ADAT) err = pcm_open(substream, max_channels); else /* If the card has ADAT, subtract the 6 channels @@ -434,24 +423,22 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream) err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT); if (err < 0) - goto din_exit; + return err; err = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, hw_rule_capture_channels_by_format, NULL, SNDRV_PCM_HW_PARAM_FORMAT, -1); if (err < 0) - goto din_exit; + return err; err = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, hw_rule_capture_format_by_channels, NULL, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) - goto din_exit; + return err; -din_exit: - mutex_unlock(&chip->mode_mutex); - return err; + return 0; } @@ -464,7 +451,7 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream) int err, max_channels; max_channels = num_digital_busses_out(chip) - substream->number; - mutex_lock(&chip->mode_mutex); + guard(mutex)(&chip->mode_mutex); if (chip->digital_mode == DIGITAL_MODE_ADAT) err = pcm_open(substream, max_channels); else /* If the card has ADAT, subtract the 6 channels @@ -473,7 +460,7 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream) err = pcm_open(substream, max_channels - ECHOCARD_HAS_ADAT); if (err < 0) - goto dout_exit; + return err; err = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, @@ -481,18 +468,16 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream) NULL, SNDRV_PCM_HW_PARAM_FORMAT, -1); if (err < 0) - goto dout_exit; + return err; err = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, hw_rule_playback_format_by_channels, NULL, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) - goto dout_exit; + return err; -dout_exit: - mutex_unlock(&chip->mode_mutex); - return err; + return 0; } #endif /* !ECHOCARD_HAS_VMIXER */ @@ -509,7 +494,7 @@ static int pcm_close(struct snd_pcm_substream *substream) * freed by its callback */ - mutex_lock(&chip->mode_mutex); + guard(mutex)(&chip->mode_mutex); dev_dbg(chip->card->dev, "pcm_open opencount=%d can_set_rate=%d, rate_set=%d", chip->opencount, chip->can_set_rate, chip->rate_set); @@ -526,7 +511,6 @@ static int pcm_close(struct snd_pcm_substream *substream) break; } - mutex_unlock(&chip->mode_mutex); return 0; } @@ -547,22 +531,21 @@ static int init_engine(struct snd_pcm_substream *substream, /* Sets up che hardware. If it's already initialized, reset and * redo with the new parameters */ - spin_lock_irq(&chip->lock); - if (pipe->index >= 0) { - dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index); - err = free_pipes(chip, pipe); - snd_BUG_ON(err); - chip->substream[pipe->index] = NULL; - } + scoped_guard(spinlock_irq, &chip->lock) { + if (pipe->index >= 0) { + dev_dbg(chip->card->dev, "hwp_ie free(%d)\n", pipe->index); + err = free_pipes(chip, pipe); + snd_BUG_ON(err); + chip->substream[pipe->index] = NULL; + } - err = allocate_pipes(chip, pipe, pipe_index, interleave); - if (err < 0) { - spin_unlock_irq(&chip->lock); - dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n", - pipe_index, err); - return err; + err = allocate_pipes(chip, pipe, pipe_index, interleave); + if (err < 0) { + dev_err(chip->card->dev, "allocate_pipes(%d) err=%d\n", + pipe_index, err); + return err; + } } - spin_unlock_irq(&chip->lock); dev_dbg(chip->card->dev, "allocate_pipes()=%d\n", pipe_index); dev_dbg(chip->card->dev, @@ -610,9 +593,8 @@ static int init_engine(struct snd_pcm_substream *substream, smp_wmb(); chip->substream[pipe_index] = substream; chip->rate_set = 1; - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); set_sample_rate(chip, hw_params->rate_num / hw_params->rate_den); - spin_unlock_irq(&chip->lock); return 0; } @@ -674,14 +656,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream) chip = snd_pcm_substream_chip(substream); pipe = (struct audiopipe *) substream->runtime->private_data; - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); if (pipe->index >= 0) { dev_dbg(chip->card->dev, "pcm_hw_free(%d)\n", pipe->index); free_pipes(chip, pipe); chip->substream[pipe->index] = NULL; pipe->index = -1; } - spin_unlock_irq(&chip->lock); return 0; } @@ -731,15 +712,12 @@ static int pcm_prepare(struct snd_pcm_substream *substream) * exclusive control */ - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); - if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index))) { - spin_unlock_irq(&chip->lock); + if (snd_BUG_ON(!is_pipe_allocated(chip, pipe_index))) return -EINVAL; - } set_audio_format(chip, pipe_index, &format); - spin_unlock_irq(&chip->lock); return 0; } @@ -763,7 +741,7 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) } } - spin_lock(&chip->lock); + guard(spinlock)(&chip->lock); switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_START: @@ -811,7 +789,6 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd) default: err = -EINVAL; } - spin_unlock(&chip->lock); return err; } @@ -927,7 +904,7 @@ static int snd_echo_new_pcm(struct echoaudio *chip) return err; pcm->private_data = chip; chip->analog_pcm = pcm; - strcpy(pcm->name, chip->card->shortname); + strscpy(pcm->name, chip->card->shortname); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops); snd_echo_preallocate_pages(pcm, &chip->pci->dev); @@ -940,7 +917,7 @@ static int snd_echo_new_pcm(struct echoaudio *chip) return err; pcm->private_data = chip; chip->digital_pcm = pcm; - strcpy(pcm->name, chip->card->shortname); + strscpy(pcm->name, chip->card->shortname); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops); snd_echo_preallocate_pages(pcm, &chip->pci->dev); #endif /* ECHOCARD_HAS_DIGITAL_IO */ @@ -960,7 +937,7 @@ static int snd_echo_new_pcm(struct echoaudio *chip) return err; pcm->private_data = chip; chip->analog_pcm = pcm; - strcpy(pcm->name, chip->card->shortname); + strscpy(pcm->name, chip->card->shortname); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &analog_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &analog_capture_ops); snd_echo_preallocate_pages(pcm, &chip->pci->dev); @@ -974,7 +951,7 @@ static int snd_echo_new_pcm(struct echoaudio *chip) return err; pcm->private_data = chip; chip->digital_pcm = pcm; - strcpy(pcm->name, chip->card->shortname); + strscpy(pcm->name, chip->card->shortname); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &digital_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &digital_capture_ops); snd_echo_preallocate_pages(pcm, &chip->pci->dev); @@ -1028,7 +1005,7 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol, changed = 0; chip = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); for (c = 0; c < num_busses_out(chip); c++) { gain = ucontrol->value.integer.value[c]; /* Ignore out of range values */ @@ -1041,7 +1018,6 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol, } if (changed) update_output_line_level(chip); - spin_unlock_irq(&chip->lock); return changed; } @@ -1109,7 +1085,7 @@ static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol, changed = 0; chip = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); for (c = 0; c < num_analog_busses_in(chip); c++) { gain = ucontrol->value.integer.value[c]; /* Ignore out of range values */ @@ -1122,7 +1098,6 @@ static int snd_echo_input_gain_put(struct snd_kcontrol *kcontrol, } if (changed) update_input_line_level(chip); - spin_unlock_irq(&chip->lock); return changed; } @@ -1178,7 +1153,7 @@ static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol, changed = 0; chip = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); for (c = 0; c < num_analog_busses_out(chip); c++) { if (chip->nominal_level[c] != ucontrol->value.integer.value[c]) { set_nominal_level(chip, c, @@ -1188,7 +1163,6 @@ static int snd_echo_output_nominal_put(struct snd_kcontrol *kcontrol, } if (changed) update_output_line_level(chip); - spin_unlock_irq(&chip->lock); return changed; } @@ -1241,7 +1215,7 @@ static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol, changed = 0; chip = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); for (c = 0; c < num_analog_busses_in(chip); c++) { if (chip->nominal_level[bx_analog_in(chip) + c] != ucontrol->value.integer.value[c]) { @@ -1254,7 +1228,6 @@ static int snd_echo_input_nominal_put(struct snd_kcontrol *kcontrol, update_output_line_level(chip); /* "Output" is not a mistake * here. */ - spin_unlock_irq(&chip->lock); return changed; } @@ -1314,10 +1287,9 @@ static int snd_echo_mixer_put(struct snd_kcontrol *kcontrol, if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) return -EINVAL; if (chip->monitor_gain[out][in] != gain) { - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); set_monitor_gain(chip, out, in, gain); update_output_line_level(chip); - spin_unlock_irq(&chip->lock); changed = 1; } return changed; @@ -1377,10 +1349,9 @@ static int snd_echo_vmixer_put(struct snd_kcontrol *kcontrol, if (gain < ECHOGAIN_MINOUT || gain > ECHOGAIN_MAXOUT) return -EINVAL; if (chip->vmixer_gain[out][vch] != ucontrol->value.integer.value[0]) { - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); set_vmixer_gain(chip, out, vch, ucontrol->value.integer.value[0]); update_vmixer_level(chip); - spin_unlock_irq(&chip->lock); changed = 1; } return changed; @@ -1450,7 +1421,7 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol, if (dmode != chip->digital_mode) { /* mode_mutex is required to make this operation atomic wrt pcm_digital_*_open() and set_input_clock() functions. */ - mutex_lock(&chip->mode_mutex); + guard(mutex)(&chip->mode_mutex); /* Do not allow the user to change the digital mode when a pcm device is open because it also changes the number of channels @@ -1470,7 +1441,6 @@ static int snd_echo_digital_mode_put(struct snd_kcontrol *kcontrol, if (changed >= 0) changed = 1; /* No errors */ } - mutex_unlock(&chip->mode_mutex); } return changed; } @@ -1517,9 +1487,8 @@ static int snd_echo_spdif_mode_put(struct snd_kcontrol *kcontrol, chip = snd_kcontrol_chip(kcontrol); mode = !!ucontrol->value.enumerated.item[0]; if (mode != chip->professional_spdif) { - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); set_professional_spdif(chip, mode); - spin_unlock_irq(&chip->lock); return 1; } return 0; @@ -1583,13 +1552,11 @@ static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol, return -EINVAL; dclock = chip->clock_source_list[eclock]; if (chip->input_clock != dclock) { - mutex_lock(&chip->mode_mutex); - spin_lock_irq(&chip->lock); + guard(mutex)(&chip->mode_mutex); + guard(spinlock_irq)(&chip->lock); changed = set_input_clock(chip, dclock); if (!changed) changed = 1; /* no errors */ - spin_unlock_irq(&chip->lock); - mutex_unlock(&chip->mode_mutex); } if (changed < 0) @@ -1633,9 +1600,8 @@ static int snd_echo_phantom_power_put(struct snd_kcontrol *kcontrol, power = !!ucontrol->value.integer.value[0]; if (chip->phantom_power != power) { - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); changed = set_phantom_power(chip, power); - spin_unlock_irq(&chip->lock); if (changed == 0) changed = 1; /* no errors */ } @@ -1676,9 +1642,8 @@ static int snd_echo_automute_put(struct snd_kcontrol *kcontrol, automute = !!ucontrol->value.integer.value[0]; if (chip->digital_in_automute != automute) { - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); changed = set_input_auto_mute(chip, automute); - spin_unlock_irq(&chip->lock); if (changed == 0) changed = 1; /* no errors */ } @@ -1706,9 +1671,8 @@ static int snd_echo_vumeters_switch_put(struct snd_kcontrol *kcontrol, struct echoaudio *chip; chip = snd_kcontrol_chip(kcontrol); - spin_lock_irq(&chip->lock); + guard(spinlock_irq)(&chip->lock); set_meters_on(chip, ucontrol->value.integer.value[0]); - spin_unlock_irq(&chip->lock); return 1; } @@ -1921,7 +1885,7 @@ static int snd_echo_create(struct snd_card *card, chip->can_set_rate = 1; /* PCI resource allocation */ - err = pci_request_regions(pci, ECHOCARD_NAME); + err = pcim_request_all_regions(pci, ECHOCARD_NAME); if (err < 0) return err; @@ -1977,7 +1941,6 @@ static int __snd_echo_probe(struct pci_dev *pci, struct snd_card *card; struct echoaudio *chip; char *dsp; - __maybe_unused int i; int err; if (dev >= SNDRV_CARDS) @@ -1987,7 +1950,6 @@ static int __snd_echo_probe(struct pci_dev *pci, return -ENOENT; } - i = 0; err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*chip), &card); if (err < 0) @@ -1998,8 +1960,8 @@ static int __snd_echo_probe(struct pci_dev *pci, if (err < 0) return err; - strcpy(card->driver, "Echo_" ECHOCARD_NAME); - strcpy(card->shortname, chip->card_name); + strscpy(card->driver, "Echo_" ECHOCARD_NAME); + strscpy(card->shortname, chip->card_name); dsp = "56301"; if (pci_id->device == 0x3410) @@ -2091,7 +2053,7 @@ static int __snd_echo_probe(struct pci_dev *pci, #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH /* Creates a list of available digital modes */ chip->num_digital_modes = 0; - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) if (chip->digital_modes & (1 << i)) chip->digital_mode_list[chip->num_digital_modes++] = i; @@ -2103,7 +2065,7 @@ static int __snd_echo_probe(struct pci_dev *pci, #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK /* Creates a list of available clock sources */ chip->num_clock_sources = 0; - for (i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) if (chip->input_clock_types & (1 << i)) chip->clock_source_list[chip->num_clock_sources++] = i; @@ -2146,8 +2108,6 @@ static int snd_echo_probe(struct pci_dev *pci, } -#if defined(CONFIG_PM_SLEEP) - static int snd_echo_suspend(struct device *dev) { struct echoaudio *chip = dev_get_drvdata(dev); @@ -2157,17 +2117,13 @@ static int snd_echo_suspend(struct device *dev) if (chip->midi_out) snd_echo_midi_output_trigger(chip->midi_out, 0); #endif - spin_lock_irq(&chip->lock); - if (wait_handshake(chip)) { - spin_unlock_irq(&chip->lock); - return -EIO; - } - clear_handshake(chip); - if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) { - spin_unlock_irq(&chip->lock); - return -EIO; + scoped_guard(spinlock_irq, &chip->lock) { + if (wait_handshake(chip)) + return -EIO; + clear_handshake(chip); + if (send_vector(chip, DSP_VC_GO_COMATOSE) < 0) + return -EIO; } - spin_unlock_irq(&chip->lock); chip->dsp_code = NULL; free_irq(chip->irq, chip); @@ -2237,11 +2193,7 @@ static int snd_echo_resume(struct device *dev) return 0; } -static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume); -#define SND_ECHO_PM_OPS &snd_echo_pm -#else -#define SND_ECHO_PM_OPS NULL -#endif /* CONFIG_PM_SLEEP */ +static DEFINE_SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume); /****************************************************************************** Everything starts and ends here @@ -2253,7 +2205,7 @@ static struct pci_driver echo_driver = { .id_table = snd_echo_ids, .probe = snd_echo_probe, .driver = { - .pm = SND_ECHO_PM_OPS, + .pm = &snd_echo_pm, }, }; |
