ALSA: ens1370: Fine-tuning for six function implementations
Subsystems (2)
cover ALSA: ens1370: Fine-tuning for six function implementations
From: Markus Elfring <[email protected]>
Date: Tue, 14 Nov 2017 18:38:28 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Adjust 15 function calls together with a variable assignment Use common error handling code in snd_audiopci_probe() Use common error handling code in snd_ensoniq_create()
sound/pci/ens1370.c | 110 +++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 49 deletions(-)
Signature · 1 line
2.15.0
PATCH 1/3 ALSA: ens1370: Adjust 15 function calls together with a variable assignment
From: Markus Elfring <[email protected]>
Date: Tue, 14 Nov 2017 18:08:57 +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/ens1370.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-)
sound/pci/ens1370.c +31 -17
@@ -694,7 +694,8 @@ static unsigned short snd_es1371_codec_read(struct snd_ac97 *ac97, }/* now wait for the stinkin' data (RDY) */ for (t =0 ; t <POLL_COUNT ; t++) { - if ((x = inl(ES_REG(ensoniq, 1371_CODEC))) & ES_1371_CODEC_RDY) { + x = inl(ES_REG(ensoniq, 1371_CODEC)); +if (x &ES_1371_CODEC_RDY ) {if (is_ev1938 (ensoniq)) {for (t =0 ; t <100 ; t++)inl (ES_REG (ensoniq,CONTROL ));
@@ -1636,7 +1637,8 @@ static int snd_ensoniq_1371_mixer(struct ensoniq *ensoniq, .wait = snd_es1371_codec_wait, }; -if ((err =snd_ac97_bus (card,0 , &ops,NULL , &pbus)) <0 ) + err =snd_ac97_bus (card,0 , &ops,NULL , &pbus); +if (err <0 )return err;memset (&ac97,0 ,sizeof (ac97));
@@ -1644,7 +1646,8 @@ static int snd_ensoniq_1371_mixer(struct ensoniq *ensoniq, ac97.private_free = snd_ensoniq_mixer_free_ac97; ac97.pci = ensoniq->pci; ac97.scaps =AC97_SCAP_AUDIO ; -if ((err =snd_ac97_mixer (pbus, &ac97, &ensoniq->u.es1371.ac97)) <0 ) + err =snd_ac97_mixer (pbus, &ac97, &ensoniq->u.es1371.ac97); +if (err <0 )return err;if (has_spdif >0 || (!has_spdif &&es1371_quirk_lookup (ensoniq, es1371_spdif_present))) {
@@ -1764,7 +1767,8 @@ static int snd_ensoniq_1370_mixer(struct ensoniq *ensoniq) ak4531.write = snd_es1370_codec_write; ak4531.private_data = ensoniq; ak4531.private_free = snd_ensoniq_mixer_free_ak4531; -if ((err =snd_ak4531_mixer (card, &ak4531, &ensoniq->u.es1370.ak4531)) <0 ) + err =snd_ak4531_mixer (card, &ak4531, &ensoniq->u.es1370.ak4531); +if (err <0 )return err;for (idx =0 ; idx <ES1370_CONTROLS ; idx++) { err =snd_ctl_add (card,snd_ctl_new1 (&snd_es1370_controls[idx], ensoniq));
@@ -2088,7 +2092,8 @@ static int snd_ensoniq_create(struct snd_card *card, }; *rensoniq =NULL ; -if ((err =pci_enable_device (pci)) <0 ) + err =pci_enable_device (pci); +if (err <0 )return err; ensoniq =kzalloc (sizeof (*ensoniq),GFP_KERNEL );if (ensoniq =NULL ) {
@@ -2100,7 +2105,8 @@ static int snd_ensoniq_create(struct snd_card *card, ensoniq->card = card; ensoniq->pci = pci; ensoniq->irq =-1 ; -if ((err =pci_request_regions (pci,"Ensoniq AudioPCI" )) <0 ) { + err =pci_request_regions (pci,"Ensoniq AudioPCI" ); +if (err <0 ) {kfree (ensoniq);pci_disable_device (pci);return err;
@@ -2143,8 +2149,8 @@ static int snd_ensoniq_create(struct snd_card *card,#endif snd_ensoniq_chip_init (ensoniq); - -if ((err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , ensoniq, &ops)) <0 ) { + err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , ensoniq, &ops); +if (err <0 ) {snd_ensoniq_free (ensoniq);return err; }
@@ -2333,9 +2339,10 @@ static const struct snd_rawmidi_ops snd_ensoniq_midi_input static int snd_ensoniq_midi(struct ensoniq *ensoniq, int device) {struct snd_rawmidi *rmidi; -int err; +int err =snd_rawmidi_new (ensoniq->card,"ES1370/1" , + device,1 ,1 , &rmidi); -if ((err =snd_rawmidi_new (ensoniq->card,"ES1370/1" , device,1 ,1 , &rmidi)) <0 ) +if (err <0 )return err;strcpy (rmidi->name,CHIP_NAME );snd_rawmidi_set_ops (rmidi,SNDRV_RAWMIDI_STREAM_OUTPUT , &snd_ensoniq_midi_output);
@@ -2406,7 +2413,8 @@ static int snd_audiopci_probe(struct pci_dev *pci,if (err <0 )return err; -if ((err =snd_ensoniq_create (card, pci, &ensoniq)) <0 ) { + err =snd_ensoniq_create (card, pci, &ensoniq); +if (err <0 ) {snd_card_free (card);return err; }
@@ -2414,26 +2422,31 @@ static int snd_audiopci_probe(struct pci_dev *pci, pcm_devs[0 ] =0 ; pcm_devs[1 ] =1 ;#ifdef CHIP1370 -if ((err =snd_ensoniq_1370_mixer (ensoniq)) <0 ) { + err =snd_ensoniq_1370_mixer (ensoniq); +if (err <0 ) {snd_card_free (card);return err; }#endif #ifdef CHIP1371 -if ((err =snd_ensoniq_1371_mixer (ensoniq, spdif[dev], lineio[dev])) <0 ) { + err =snd_ensoniq_1371_mixer (ensoniq, spdif[dev], lineio[dev]); +if (err <0 ) {snd_card_free (card);return err; }#endif -if ((err =snd_ensoniq_pcm (ensoniq,0 )) <0 ) { + err =snd_ensoniq_pcm (ensoniq,0 ); +if (err <0 ) {snd_card_free (card);return err; } -if ((err =snd_ensoniq_pcm2 (ensoniq,1 )) <0 ) { + err =snd_ensoniq_pcm2 (ensoniq,1 ); +if (err <0 ) {snd_card_free (card);return err; } -if ((err =snd_ensoniq_midi (ensoniq,0 )) <0 ) { + err =snd_ensoniq_midi (ensoniq,0 ); +if (err <0 ) {snd_card_free (card);return err; }
@@ -2449,7 +2462,8 @@ static int snd_audiopci_probe(struct pci_dev *pci, ensoniq->port, ensoniq->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: ens1370: Use common error handling code in snd_audiopci_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 14 Nov 2017 18:15:36 +0100
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
This issue was detected by using the Coccinelle software.
--- sound/pci/ens1370.c | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-)
sound/pci/ens1370.c +21 -28
@@ -2414,42 +2414,33 @@ static int snd_audiopci_probe(struct pci_dev *pci,return err; err =snd_ensoniq_create (card, pci, &ensoniq); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card; + card->private_data = ensoniq; pcm_devs[0 ] =0 ; pcm_devs[1 ] =1 ;#ifdef CHIP1370 err =snd_ensoniq_1370_mixer (ensoniq); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card;#endif #ifdef CHIP1371 err =snd_ensoniq_1371_mixer (ensoniq, spdif[dev], lineio[dev]); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card;#endif err =snd_ensoniq_pcm (ensoniq,0 ); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card; + err =snd_ensoniq_pcm2 (ensoniq,1 ); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card; + err =snd_ensoniq_midi (ensoniq,0 ); -if (err <0 ) { -snd_card_free (card); -return err; - } +if (err <0 ) + goto free_card;snd_ensoniq_create_gameport (ensoniq, dev);
@@ -2463,14 +2454,16 @@ static int snd_audiopci_probe(struct pci_dev *pci, ensoniq->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_audiopci_remove (struct pci_dev *pci)
Signature · 1 line
2.15.0
PATCH 3/3 ALSA: ens1370: Use common error handling code in snd_ensoniq_create()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 14 Nov 2017 18:28:30 +0100
Add jump targets so that a bit of exception handling can be better reused at the end of this function.
--- sound/pci/ens1370.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
sound/pci/ens1370.c +17 -12
@@ -2097,8 +2097,8 @@ static int snd_ensoniq_create(struct snd_card *card,return err; ensoniq =kzalloc (sizeof (*ensoniq),GFP_KERNEL );if (ensoniq =NULL ) { -pci_disable_device (pci); -return -ENOMEM ; + err = -ENOMEM ; + goto disable_device; }spin_lock_init (&ensoniq->reg_lock);mutex_init (&ensoniq->src_mutex);
@@ -2108,23 +2108,20 @@ static int snd_ensoniq_create(struct snd_card *card, err =pci_request_regions (pci,"Ensoniq AudioPCI" );if (err <0 ) {kfree (ensoniq); -pci_disable_device (pci); -return err; + goto disable_device; } ensoniq->port =pci_resource_start (pci,0 );if (request_irq (pci->irq, snd_audiopci_interrupt,IRQF_SHARED ,KBUILD_MODNAME , ensoniq)) {dev_err (card->dev,"unable to grab IRQ %d\n" , pci->irq); -snd_ensoniq_free (ensoniq); -return -EBUSY ; + goto e_busy; } ensoniq->irq = pci->irq;#ifdef CHIP1370 if (snd_dma_alloc_pages (SNDRV_DMA_TYPE_DEV ,snd_dma_pci_data (pci),16 , &ensoniq->dma_bug) <0 ) {dev_err (card->dev,"unable to allocate space for phantom area - dma_bug\n" ); -snd_ensoniq_free (ensoniq); -return -EBUSY ; + goto e_busy; }#endif pci_set_master (pci);
@@ -2150,15 +2147,23 @@ static int snd_ensoniq_create(struct snd_card *card,snd_ensoniq_chip_init (ensoniq); err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , ensoniq, &ops); -if (err <0 ) { -snd_ensoniq_free (ensoniq); -return err; - } +if (err <0 ) + goto free_sound_chip;snd_ensoniq_proc_init (ensoniq); *rensoniq = ensoniq;return 0 ; + +disable_device: +pci_disable_device (pci); +return err; + +e_busy: + err = -EBUSY ; +free_sound_chip: +snd_ensoniq_free (ensoniq); +return err; }/*
Signature · 1 line
2.15.0