diff options
Diffstat (limited to 'sound/pci/echoaudio/echoaudio.c')
-rw-r--r-- | sound/pci/echoaudio/echoaudio.c | 403 |
1 files changed, 178 insertions, 225 deletions
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index a20b2bb5c898..7484de255a3e 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -10,7 +10,6 @@ MODULE_AUTHOR("Giuliano Pochini <pochini@shiny.it>"); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Echoaudio " ECHOCARD_NAME " soundcards driver"); -MODULE_SUPPORTED_DEVICE("{{Echoaudio," ECHOCARD_NAME "}}"); MODULE_DEVICE_TABLE(pci, snd_echo_ids); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; @@ -35,7 +34,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", @@ -43,7 +41,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); @@ -52,10 +49,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; } @@ -64,18 +59,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++) @@ -83,8 +73,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 } @@ -302,38 +290,42 @@ static int pcm_open(struct snd_pcm_substream *substream, snd_pcm_set_sync(substream); /* Only mono and any even number of channels are allowed */ - if ((err = snd_pcm_hw_constraint_list(runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - &pipe->constr)) < 0) + err = snd_pcm_hw_constraint_list(runtime, 0, + SNDRV_PCM_HW_PARAM_CHANNELS, + &pipe->constr); + if (err < 0) return err; /* All periods should have the same size */ - if ((err = snd_pcm_hw_constraint_integer(runtime, - SNDRV_PCM_HW_PARAM_PERIODS)) < 0) + err = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (err < 0) return err; /* The hw accesses memory in chunks 32 frames long and they should be 32-bytes-aligned. It's not a requirement, but it seems that IRQs are generated with a resolution of 32 frames. Thus we need the following */ - if ((err = snd_pcm_hw_constraint_step(runtime, 0, - SNDRV_PCM_HW_PARAM_PERIOD_SIZE, - 32)) < 0) + err = snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32); + if (err < 0) return err; - if ((err = snd_pcm_hw_constraint_step(runtime, 0, - SNDRV_PCM_HW_PARAM_BUFFER_SIZE, - 32)) < 0) + err = snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32); + if (err < 0) return err; - if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - hw_rule_sample_rate, chip, - SNDRV_PCM_HW_PARAM_RATE, -1)) < 0) + err = snd_pcm_hw_rule_add(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, + hw_rule_sample_rate, chip, + SNDRV_PCM_HW_PARAM_RATE, -1); + if (err < 0) return err; /* Allocate a page for the scatter-gather list */ - if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, - &chip->pci->dev, - PAGE_SIZE, &pipe->sgpage)) < 0) { + err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, + &chip->pci->dev, + PAGE_SIZE, &pipe->sgpage); + if (err < 0) { dev_err(chip->card->dev, "s-g list allocation failed\n"); return err; } @@ -359,18 +351,21 @@ static int pcm_analog_in_open(struct snd_pcm_substream *substream) struct echoaudio *chip = snd_pcm_substream_chip(substream); int err; - if ((err = pcm_open(substream, num_analog_busses_in(chip) - - substream->number)) < 0) + err = pcm_open(substream, + num_analog_busses_in(chip) - substream->number); + if (err < 0) return err; - if ((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)) < 0) + 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) return err; - if ((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)) < 0) + 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) return err; return 0; @@ -388,19 +383,22 @@ static int pcm_analog_out_open(struct snd_pcm_substream *substream) #else max_channels = num_analog_busses_out(chip); #endif - if ((err = pcm_open(substream, max_channels - substream->number)) < 0) + err = pcm_open(substream, max_channels - substream->number); + if (err < 0) return err; - if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - hw_rule_playback_channels_by_format, - NULL, - SNDRV_PCM_HW_PARAM_FORMAT, -1)) < 0) + err = snd_pcm_hw_rule_add(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_CHANNELS, + hw_rule_playback_channels_by_format, + NULL, + SNDRV_PCM_HW_PARAM_FORMAT, -1); + if (err < 0) return err; - if ((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)) < 0) + 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) return err; return 0; @@ -427,15 +425,17 @@ static int pcm_digital_in_open(struct snd_pcm_substream *substream) if (err < 0) goto din_exit; - if ((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)) < 0) + 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; - if ((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)) < 0) + 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; din_exit: @@ -464,17 +464,19 @@ static int pcm_digital_out_open(struct snd_pcm_substream *substream) if (err < 0) goto dout_exit; - if ((err = snd_pcm_hw_rule_add(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_CHANNELS, - hw_rule_playback_channels_by_format, - NULL, SNDRV_PCM_HW_PARAM_FORMAT, - -1)) < 0) + err = snd_pcm_hw_rule_add(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_CHANNELS, + hw_rule_playback_channels_by_format, + NULL, SNDRV_PCM_HW_PARAM_FORMAT, + -1); + if (err < 0) goto dout_exit; - if ((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)) < 0) + 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; dout_exit: @@ -908,8 +910,9 @@ static int snd_echo_new_pcm(struct echoaudio *chip) separated */ /* PCM#0 Virtual outputs and analog inputs */ - if ((err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip), - num_analog_busses_in(chip), &pcm)) < 0) + err = snd_pcm_new(chip->card, "PCM", 0, num_pipes_out(chip), + num_analog_busses_in(chip), &pcm); + if (err < 0) return err; pcm->private_data = chip; chip->analog_pcm = pcm; @@ -920,8 +923,9 @@ static int snd_echo_new_pcm(struct echoaudio *chip) #ifdef ECHOCARD_HAS_DIGITAL_IO /* PCM#1 Digital inputs, no outputs */ - if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, 0, - num_digital_busses_in(chip), &pcm)) < 0) + err = snd_pcm_new(chip->card, "Digital PCM", 1, 0, + num_digital_busses_in(chip), &pcm); + if (err < 0) return err; pcm->private_data = chip; chip->digital_pcm = pcm; @@ -938,9 +942,10 @@ static int snd_echo_new_pcm(struct echoaudio *chip) register two PCM devices: */ /* PCM#0 Analog i/o */ - if ((err = snd_pcm_new(chip->card, "Analog PCM", 0, - num_analog_busses_out(chip), - num_analog_busses_in(chip), &pcm)) < 0) + err = snd_pcm_new(chip->card, "Analog PCM", 0, + num_analog_busses_out(chip), + num_analog_busses_in(chip), &pcm); + if (err < 0) return err; pcm->private_data = chip; chip->analog_pcm = pcm; @@ -951,9 +956,10 @@ static int snd_echo_new_pcm(struct echoaudio *chip) #ifdef ECHOCARD_HAS_DIGITAL_IO /* PCM#1 Digital i/o */ - if ((err = snd_pcm_new(chip->card, "Digital PCM", 1, - num_digital_busses_out(chip), - num_digital_busses_in(chip), &pcm)) < 0) + err = snd_pcm_new(chip->card, "Digital PCM", 1, + num_digital_busses_out(chip), + num_digital_busses_in(chip), &pcm); + if (err < 0) return err; pcm->private_data = chip; chip->digital_pcm = pcm; @@ -1568,7 +1574,8 @@ static int snd_echo_clock_source_put(struct snd_kcontrol *kcontrol, if (chip->input_clock != dclock) { mutex_lock(&chip->mode_mutex); spin_lock_irq(&chip->lock); - if ((changed = set_input_clock(chip, dclock)) == 0) + changed = set_input_clock(chip, dclock); + if (!changed) changed = 1; /* no errors */ spin_unlock_irq(&chip->lock); mutex_unlock(&chip->mode_mutex); @@ -1864,103 +1871,63 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id) Module construction / destruction ******************************************************************************/ -static int snd_echo_free(struct echoaudio *chip) +static void snd_echo_free(struct snd_card *card) { + struct echoaudio *chip = card->private_data; + if (chip->comm_page) rest_in_peace(chip); if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->comm_page) - snd_dma_free_pages(&chip->commpage_dma_buf); - - iounmap(chip->dsp_registers); - release_and_free_resource(chip->iores); - pci_disable_device(chip->pci); - /* release chip data */ free_firmware_cache(chip); - kfree(chip); - return 0; -} - - - -static int snd_echo_dev_free(struct snd_device *device) -{ - struct echoaudio *chip = device->device_data; - - return snd_echo_free(chip); } - - /* <--snd_echo_probe() */ static int snd_echo_create(struct snd_card *card, - struct pci_dev *pci, - struct echoaudio **rchip) + struct pci_dev *pci) { - struct echoaudio *chip; + struct echoaudio *chip = card->private_data; int err; size_t sz; - static const struct snd_device_ops ops = { - .dev_free = snd_echo_dev_free, - }; - - *rchip = NULL; pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0); - if ((err = pci_enable_device(pci)) < 0) + err = pcim_enable_device(pci); + if (err < 0) return err; pci_set_master(pci); /* Allocate chip if needed */ - if (!*rchip) { - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (!chip) { - pci_disable_device(pci); - return -ENOMEM; - } - dev_dbg(card->dev, "chip=%p\n", chip); - spin_lock_init(&chip->lock); - chip->card = card; - chip->pci = pci; - chip->irq = -1; - chip->opencount = 0; - mutex_init(&chip->mode_mutex); - chip->can_set_rate = 1; - } else { - /* If this was called from the resume function, chip is - * already allocated and it contains current card settings. - */ - chip = *rchip; - } + spin_lock_init(&chip->lock); + chip->card = card; + chip->pci = pci; + chip->irq = -1; + chip->opencount = 0; + mutex_init(&chip->mode_mutex); + chip->can_set_rate = 1; /* PCI resource allocation */ + err = pci_request_regions(pci, ECHOCARD_NAME); + if (err < 0) + return err; + chip->dsp_registers_phys = pci_resource_start(pci, 0); sz = pci_resource_len(pci, 0); if (sz > PAGE_SIZE) sz = PAGE_SIZE; /* We map only the required part */ - if ((chip->iores = request_mem_region(chip->dsp_registers_phys, sz, - ECHOCARD_NAME)) == NULL) { - dev_err(chip->card->dev, "cannot get memory region\n"); - snd_echo_free(chip); - return -EBUSY; - } - chip->dsp_registers = ioremap(chip->dsp_registers_phys, sz); + chip->dsp_registers = devm_ioremap(&pci->dev, chip->dsp_registers_phys, sz); if (!chip->dsp_registers) { dev_err(chip->card->dev, "ioremap failed\n"); - snd_echo_free(chip); return -ENOMEM; } if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "cannot grab irq\n"); - snd_echo_free(chip); return -EBUSY; } chip->irq = pci->irq; @@ -1968,41 +1935,32 @@ static int snd_echo_create(struct snd_card *card, dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n", chip->pci, chip->irq, chip->pci->subsystem_device); + card->private_free = snd_echo_free; + /* Create the DSP comm page - this is the area of memory used for most of the communication with the DSP, which accesses it via bus mastering */ - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, - sizeof(struct comm_page), - &chip->commpage_dma_buf) < 0) { - dev_err(chip->card->dev, "cannot allocate the comm page\n"); - snd_echo_free(chip); + chip->commpage_dma_buf = + snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, + sizeof(struct comm_page)); + if (!chip->commpage_dma_buf) return -ENOMEM; - } - chip->comm_page_phys = chip->commpage_dma_buf.addr; - chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; + chip->comm_page_phys = chip->commpage_dma_buf->addr; + chip->comm_page = (struct comm_page *)chip->commpage_dma_buf->area; err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); if (err >= 0) err = set_mixer_defaults(chip); if (err < 0) { dev_err(card->dev, "init_hw err=%d\n", err); - snd_echo_free(chip); return err; } - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { - snd_echo_free(chip); - return err; - } - *rchip = chip; - /* Init done ! */ return 0; } - - /* constructor */ -static int snd_echo_probe(struct pci_dev *pci, - const struct pci_device_id *pci_id) +static int __snd_echo_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; @@ -2019,16 +1977,15 @@ static int snd_echo_probe(struct pci_dev *pci, } i = 0; - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - 0, &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; - chip = NULL; /* Tells snd_echo_create to allocate chip */ - if ((err = snd_echo_create(card, pci, &chip)) < 0) { - snd_card_free(card); + err = snd_echo_create(card, pci); + if (err < 0) return err; - } strcpy(card->driver, "Echo_" ECHOCARD_NAME); strcpy(card->shortname, chip->card_name); @@ -2041,17 +1998,17 @@ static int snd_echo_probe(struct pci_dev *pci, card->shortname, pci_id->subdevice & 0x000f, dsp, chip->dsp_registers_phys, chip->irq); - if ((err = snd_echo_new_pcm(chip)) < 0) { + err = snd_echo_new_pcm(chip); + if (err < 0) { dev_err(chip->card->dev, "new pcm error %d\n", err); - snd_card_free(card); return err; } #ifdef ECHOCARD_HAS_MIDI if (chip->has_midi) { /* Some Mia's do not have midi */ - if ((err = snd_echo_midi_create(card, chip)) < 0) { + err = snd_echo_midi_create(card, chip); + if (err < 0) { dev_err(chip->card->dev, "new midi error %d\n", err); - snd_card_free(card); return err; } } @@ -2059,56 +2016,66 @@ static int snd_echo_probe(struct pci_dev *pci, #ifdef ECHOCARD_HAS_VMIXER snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip); - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip)); + if (err < 0) + return err; #ifdef ECHOCARD_HAS_LINE_OUT_GAIN err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip)); if (err < 0) - goto ctl_error; + return err; #endif #else /* ECHOCARD_HAS_VMIXER */ err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip)); if (err < 0) - goto ctl_error; + return err; #endif /* ECHOCARD_HAS_VMIXER */ #ifdef ECHOCARD_HAS_INPUT_GAIN - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip)); + if (err < 0) + return err; #endif #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL - if (!chip->hasnt_input_nominal_level) - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip))) < 0) - goto ctl_error; + if (!chip->hasnt_input_nominal_level) { + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip)); + if (err < 0) + return err; + } #endif #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip)); + if (err < 0) + return err; #endif - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip)); + if (err < 0) + return err; - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip)); + if (err < 0) + return err; #ifdef ECHOCARD_HAS_MONITOR snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip); - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip)); + if (err < 0) + return err; #endif #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip)); + if (err < 0) + return err; #endif - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip)); + if (err < 0) + return err; #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH /* Creates a list of available digital modes */ @@ -2117,8 +2084,9 @@ static int snd_echo_probe(struct pci_dev *pci, if (chip->digital_modes & (1 << i)) chip->digital_mode_list[chip->num_digital_modes++] = i; - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip)); + if (err < 0) + return err; #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */ #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK @@ -2130,41 +2098,43 @@ static int snd_echo_probe(struct pci_dev *pci, if (chip->num_clock_sources > 1) { chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip); - if ((err = snd_ctl_add(chip->card, chip->clock_src_ctl)) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, chip->clock_src_ctl); + if (err < 0) + return err; } #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */ #ifdef ECHOCARD_HAS_DIGITAL_IO - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip))) < 0) - goto ctl_error; + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip)); + if (err < 0) + return err; #endif #ifdef ECHOCARD_HAS_PHANTOM_POWER - if (chip->has_phantom_power) - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip))) < 0) - goto ctl_error; + if (chip->has_phantom_power) { + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip)); + if (err < 0) + return err; + } #endif err = snd_card_register(card); if (err < 0) - goto ctl_error; + return err; dev_info(card->dev, "Card registered: %s\n", card->longname); pci_set_drvdata(pci, chip); dev++; return 0; - -ctl_error: - dev_err(card->dev, "new control error %d\n", err); - snd_card_free(card); - return err; } +static int snd_echo_probe(struct pci_dev *pci, + const struct pci_device_id *pci_id) +{ + return snd_card_free_on_error(&pci->dev, __snd_echo_probe(pci, pci_id)); +} -#if defined(CONFIG_PM_SLEEP) - static int snd_echo_suspend(struct device *dev) { struct echoaudio *chip = dev_get_drvdata(dev); @@ -2254,23 +2224,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 void snd_echo_remove(struct pci_dev *pci) -{ - struct echoaudio *chip; - - chip = pci_get_drvdata(pci); - if (chip) - snd_card_free(chip->card); -} - - +static DEFINE_SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume); /****************************************************************************** Everything starts and ends here @@ -2281,9 +2235,8 @@ static struct pci_driver echo_driver = { .name = KBUILD_MODNAME, .id_table = snd_echo_ids, .probe = snd_echo_probe, - .remove = snd_echo_remove, .driver = { - .pm = SND_ECHO_PM_OPS, + .pm = &snd_echo_pm, }, }; |