ALSA: es1968: Fine-tuning for seven function implementations
Subsystems (2)
cover ALSA: es1968: Fine-tuning for seven function implementations
From: Markus Elfring <[email protected]>
Date: Wed, 15 Nov 2017 10:23:45 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Adjust 16 function calls together with a variable assignment Use common error handling code in two functions Use common error handling code in snd_es1968_capture_open()
sound/pci/es1968.c | 163 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 71 deletions(-)
Signature · 1 line
2.15.0
PATCH 1/3 ALSA: es1968: Adjust 16 function calls together with a variable assignment
From: Markus Elfring <[email protected]>
Date: Tue, 14 Nov 2017 22:45:01 +0100
The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code places.
--- sound/pci/es1968.c | 78 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 31 deletions(-)
sound/pci/es1968.c +47 -31
@@ -1620,7 +1620,8 @@ static int snd_es1968_capture_open(struct snd_pcm_substream *substream) es->mode =ESM_MODE_CAPTURE ;/* get mixbuffer */ -if ((es->mixbuf =snd_es1968_new_memory (chip,ESM_MIXBUF_SIZE )) =NULL ) { + es->mixbuf =snd_es1968_new_memory (chip,ESM_MIXBUF_SIZE ); +if (!es->mixbuf) {snd_es1968_free_apu_pair (chip, apu1);snd_es1968_free_apu_pair (chip, apu2);kfree (es);
@@ -1717,11 +1718,14 @@ static void es1968_measure_clock(struct es1968 *chip) chip->clock =48000 ;/* default clock value */ /* search 2 APUs (although one apu is enough) */ -if ((apu =snd_es1968_alloc_apu_pair (chip,ESM_APU_PCM_PLAY )) <0 ) { + apu =snd_es1968_alloc_apu_pair (chip,ESM_APU_PCM_PLAY ); +if (apu <0 ) {dev_err (chip->card->dev,"Hmm, cannot find empty APU pair!?\n" );return ; } -if ((memory =snd_es1968_new_memory (chip,CLOCK_MEASURE_BUFSIZE )) =NULL ) { + + memory =snd_es1968_new_memory (chip,CLOCK_MEASURE_BUFSIZE ); +if (!memory) {dev_warn (chip->card->dev,"cannot allocate dma buffer - using default clock %d\n" , chip->clock);
@@ -1813,7 +1817,8 @@ snd_es1968_pcm(struct es1968 *chip, int device)int err;/* get DMA buffer */ -if ((err =snd_es1968_init_dmabuf (chip)) <0 ) + err =snd_es1968_init_dmabuf (chip); +if (err <0 )return err;/* set PCMBAR */
@@ -1822,9 +1827,10 @@ snd_es1968_pcm(struct es1968 *chip, int device)wave_set_register (chip,0x01FE , chip->dma.addr >>12 );wave_set_register (chip,0x01FF , chip->dma.addr >>12 ); -if ((err =snd_pcm_new (chip->card,"ESS Maestro" , device, - chip->playback_streams, - chip->capture_streams, &pcm)) <0 ) + err =snd_pcm_new (chip->card,"ESS Maestro" , device, + chip->playback_streams, + chip->capture_streams, &pcm); +if (err <0 )return err; pcm->private_data = chip;
@@ -1973,9 +1979,9 @@ static void es1968_update_hw_volume(struct work_struct *work)static irqreturn_t snd_es1968_interrupt (int irq,void *dev_id) {struct es1968 *chip = dev_id; -u32 event; +u32 event =inb (chip->io_port +0x1A ); -if (!(event =inb (chip->io_port +0x1A ))) +if (!event)return IRQ_NONE ;outw (inw (chip->io_port +4 ) &1 , chip->io_port +4 );
@@ -2030,13 +2036,15 @@ snd_es1968_mixer(struct es1968 *chip) .read = snd_es1968_ac97_read, }; -if ((err =snd_ac97_bus (chip->card,0 , &ops,NULL , &pbus)) <0 ) + err =snd_ac97_bus (chip->card,0 , &ops,NULL , &pbus); +if (err <0 )return err; pbus->no_vra =1 ;/* ES1968 doesn't need VRA */ memset (&ac97,0 ,sizeof (ac97)); ac97.private_data = chip; -if ((err =snd_ac97_mixer (pbus, &ac97, &chip->ac97)) <0 ) + err =snd_ac97_mixer (pbus, &ac97, &chip->ac97); +if (err <0 )return err;#ifndef CONFIG_SND_ES1968_INPUT
@@ -2686,7 +2694,8 @@ static int snd_es1968_create(struct snd_card *card, *chip_ret =NULL ;/* enable PCI device */ -if ((err =pci_enable_device (pci)) <0 ) + err =pci_enable_device (pci); +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 ||
@@ -2718,7 +2727,8 @@ static int snd_es1968_create(struct snd_card *card, chip->playback_streams = play_streams; chip->capture_streams = capt_streams; -if ((err =pci_request_regions (pci,"ESS Maestro" )) <0 ) { + err =pci_request_regions (pci,"ESS Maestro" ); +if (err <0 ) {kfree (chip);pci_disable_device (pci);return err;
@@ -2764,7 +2774,8 @@ static int snd_es1968_create(struct snd_card *card,snd_es1968_chip_init (chip); -if ((err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , chip, &ops)) <0 ) { + err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , chip, &ops); +if (err <0 ) {snd_es1968_free (chip);return err; }
@@ -2829,14 +2840,16 @@ static int snd_es1968_probe(struct pci_dev *pci, total_bufsize[dev] =128 ;if (total_bufsize[dev] >4096 ) total_bufsize[dev] =4096 ; -if ((err =snd_es1968_create (card, pci, - total_bufsize[dev] *1024 ,/* in bytes */ - pcm_substreams_p[dev], - pcm_substreams_c[dev], - pci_id->driver_data, - use_pm[dev], - radio_nr[dev], - &chip)) <0 ) { + + err =snd_es1968_create (card, pci, + total_bufsize[dev] *1024 ,/* in bytes */ + pcm_substreams_p[dev], + pcm_substreams_c[dev], + pci_id->driver_data, + use_pm[dev], + radio_nr[dev], + &chip); +if (err <0 ) {snd_card_free (card);return err; }
@@ -2857,12 +2870,14 @@ static int snd_es1968_probe(struct pci_dev *pci,break ; } -if ((err =snd_es1968_pcm (chip,0 )) <0 ) { + err =snd_es1968_pcm (chip,0 ); +if (err <0 ) {snd_card_free (card);return err; } -if ((err =snd_es1968_mixer (chip)) <0 ) { + err =snd_es1968_mixer (chip); +if (err <0 ) {snd_card_free (card);return err; }
@@ -2880,13 +2895,13 @@ static int snd_es1968_probe(struct pci_dev *pci, } }if (enable_mpu[dev]) { -if ((err =snd_mpu401_uart_new (card,0 ,MPU401_HW_MPU401 , - chip->io_port +ESM_MPU401_PORT , -MPU401_INFO_INTEGRATED | -MPU401_INFO_IRQ_HOOK , --1 , &chip->rmidi)) <0 ) { + err =snd_mpu401_uart_new (card,0 ,MPU401_HW_MPU401 , + chip->io_port +ESM_MPU401_PORT , +MPU401_INFO_INTEGRATED | +MPU401_INFO_IRQ_HOOK , +-1 , &chip->rmidi); +if (err <0 )dev_warn (card->dev,"skipping MPU-401 MIDI support..\n" ); - } }snd_es1968_create_gameport (chip, dev);
@@ -2907,7 +2922,8 @@ static int snd_es1968_probe(struct pci_dev *pci,sprintf (card->longname,"%s at 0x%lx, irq %i" , card->shortname, chip->io_port, chip->irq); -if ((err =snd_card_register (card)) <0 ) { + err =snd_card_register (card); +if (err <0 ) {snd_card_free (card);return err; }
Signature · 1 line
2.15.0
PATCH 2/3 ALSA: es1968: Use common error handling code in two functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 15 Nov 2017 09:04:41 +0100
Add jump targets so that a bit of exception handling can be better reused at the end of these functions.
This issue was detected by using the Coccinelle software.
--- sound/pci/es1968.c | 66 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 32 deletions(-)
sound/pci/es1968.c +34 -32
@@ -2702,14 +2702,14 @@ static int snd_es1968_create(struct snd_card *card, dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(28)) < 0) {dev_err (card->dev,"architecture does not support 28bit PCI busmaster DMA\n" ); -pci_disable_device (pci); -return -ENXIO ; + err = -ENXIO ; + goto disable_device; } chip =kzalloc (sizeof (*chip),GFP_KERNEL );if (! chip) { -pci_disable_device (pci); -return -ENOMEM ; + err = -ENOMEM ; + goto disable_device; }/* Set Vars */
@@ -2730,15 +2730,14 @@ static int snd_es1968_create(struct snd_card *card, err =pci_request_regions (pci,"ESS Maestro" );if (err <0 ) {kfree (chip); -pci_disable_device (pci); -return err; + goto disable_device; } chip->io_port =pci_resource_start (pci,0 );if (request_irq (pci->irq, snd_es1968_interrupt,IRQF_SHARED ,KBUILD_MODNAME , chip)) {dev_err (card->dev,"unable to grab IRQ %d\n" , pci->irq); -snd_es1968_free (chip); -return -EBUSY ; + err = -EBUSY ; + goto free_sound_chip; } chip->irq = pci->irq;
@@ -2775,20 +2774,17 @@ static int snd_es1968_create(struct snd_card *card,snd_es1968_chip_init (chip); err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , chip, &ops); -if (err <0 ) { -snd_es1968_free (chip); -return err; - } +if (err <0 ) + goto free_sound_chip;#ifdef CONFIG_SND_ES1968_RADIO /* don't play with GPIOs on laptops */ if (chip->pci->subsystem_vendor !=0x125d ) goto no_radio; err =v4l2_device_register (&pci->dev, &chip->v4l2_dev); -if (err <0 ) { -snd_es1968_free (chip); -return err; - } +if (err <0 ) + goto free_sound_chip; + chip->tea.v4l2_dev = &chip->v4l2_dev; chip->tea.private_data = chip; chip->tea.radio_nr = radio_nr;
@@ -2810,6 +2806,14 @@ static int snd_es1968_create(struct snd_card *card, *chip_ret = chip;return 0 ; + +disable_device: +pci_disable_device (pci); +return err; + +free_sound_chip: +snd_es1968_free (chip); +return err; }
@@ -2849,10 +2853,9 @@ static int snd_es1968_probe(struct pci_dev *pci, use_pm[dev], radio_nr[dev], &chip); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card; + card->private_data = chip;switch (chip->type) {
@@ -2871,16 +2874,12 @@ static int snd_es1968_probe(struct pci_dev *pci, } err =snd_es1968_pcm (chip,0 ); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card; err =snd_es1968_mixer (chip); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card;if (enable_mpu[dev] =2 ) {/* check the black list */
@@ -2923,13 +2922,16 @@ static int snd_es1968_probe(struct pci_dev *pci, card->shortname, chip->io_port, chip->irq); err =snd_card_register (card); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card; +pci_set_drvdata (pci, card); dev++;return 0 ; + +free_card: +snd_card_free (card); +return err; }static void snd_es1968_remove (struct pci_dev *pci)
Signature · 1 line
2.15.0
PATCH 3/3 ALSA: es1968: Use common error handling code in snd_es1968_capture_open()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 15 Nov 2017 09:30:00 +0100
Add jump targets so that a bit of exception handling can be better reused at the end of this function.
--- sound/pci/es1968.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
sound/pci/es1968.c +17 -14
@@ -1589,23 +1589,20 @@ static int snd_es1968_capture_open(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;struct es1968 *chip =snd_pcm_substream_chip (substream);struct esschan *es; -int apu1, apu2; +int apu1, apu2, rc; apu1 =snd_es1968_alloc_apu_pair (chip,ESM_APU_PCM_CAPTURE );if (apu1 <0 )return apu1; apu2 =snd_es1968_alloc_apu_pair (chip,ESM_APU_PCM_RATECONV );if (apu2 <0 ) { -snd_es1968_free_apu_pair (chip, apu1); -return apu2; + rc = apu2; + goto free_first_pair; } es =kzalloc (sizeof (*es),GFP_KERNEL ); -if (!es) { -snd_es1968_free_apu_pair (chip, apu1); -snd_es1968_free_apu_pair (chip, apu2); -return -ENOMEM ; - } +if (!es) + goto e_nomem; es->apu[0 ] = apu1; es->apu[1 ] = apu1 +1 ;
@@ -1621,12 +1618,9 @@ static int snd_es1968_capture_open(struct snd_pcm_substream *substream)/* get mixbuffer */ es->mixbuf =snd_es1968_new_memory (chip,ESM_MIXBUF_SIZE ); -if (!es->mixbuf) { -snd_es1968_free_apu_pair (chip, apu1); -snd_es1968_free_apu_pair (chip, apu2); -kfree (es); -return -ENOMEM ; - } +if (!es->mixbuf) + goto free_data; +memset (es->mixbuf->buf.area,0 ,ESM_MIXBUF_SIZE ); runtime->private_data = es;
@@ -1640,6 +1634,15 @@ static int snd_es1968_capture_open(struct snd_pcm_substream *substream)spin_unlock_irq (&chip->substream_lock);return 0 ; + +free_data: +kfree (es); +e_nomem: + rc = -ENOMEM ; +snd_es1968_free_apu_pair (chip, apu2); +free_first_pair: +snd_es1968_free_apu_pair (chip, apu1); +return rc; }static int snd_es1968_playback_close (struct snd_pcm_substream *substream)
Signature · 1 line
2.15.0