[alsa-devel] [PATCH 0/2] ALSA-miXart: Fine-tuning for seven function implementations
From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 16 Nov 2017 16:27:32 +0100
Two update suggestions were taken into account from static source code analysis.
Markus Elfring (2): Adjust 23 function calls together with a variable assignment Use common error handling code in snd_mixart_probe()
sound/pci/mixart/mixart.c | 88 ++++++++++++++++++++++------------------- sound/pci/mixart/mixart_hwdep.c | 17 +++++--- sound/pci/mixart/mixart_mixer.c | 44 +++++++++++++++------ 3 files changed, 93 insertions(+), 56 deletions(-)
From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 16 Nov 2017 15:26:12 +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.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/pci/mixart/mixart.c | 29 ++++++++++++++++----------- sound/pci/mixart/mixart_hwdep.c | 17 +++++++++++----- sound/pci/mixart/mixart_mixer.c | 44 ++++++++++++++++++++++++++++++----------- 3 files changed, 63 insertions(+), 27 deletions(-)
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c index a74f1ad7e7b8..ff90a06f775e 100644 --- a/sound/pci/mixart/mixart.c +++ b/sound/pci/mixart/mixart.c @@ -972,9 +972,10 @@ static int snd_mixart_pcm_analog(struct snd_mixart *chip) char name[32];
sprintf(name, "miXart analog %d", chip->chip_idx); - if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_ANALOG, - MIXART_PLAYBACK_STREAMS, - MIXART_CAPTURE_STREAMS, &pcm)) < 0) { + err = snd_pcm_new(chip->card, name, MIXART_PCM_ANALOG, + MIXART_PLAYBACK_STREAMS, + MIXART_CAPTURE_STREAMS, &pcm); + if (err < 0) { dev_err(chip->card->dev, "cannot create the analog pcm %d\n", chip->chip_idx); return err; @@ -1005,9 +1006,10 @@ static int snd_mixart_pcm_digital(struct snd_mixart *chip) char name[32];
sprintf(name, "miXart AES/EBU %d", chip->chip_idx); - if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_DIGITAL, - MIXART_PLAYBACK_STREAMS, - MIXART_CAPTURE_STREAMS, &pcm)) < 0) { + err = snd_pcm_new(chip->card, name, MIXART_PCM_DIGITAL, + MIXART_PLAYBACK_STREAMS, + MIXART_CAPTURE_STREAMS, &pcm); + if (err < 0) { dev_err(chip->card->dev, "cannot create the digital pcm %d\n", chip->chip_idx); return err; @@ -1059,7 +1061,8 @@ static int snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *card, int chip->chip_idx = idx; chip->mgr = mgr;
- 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_mixart_chip_free(chip); return err; } @@ -1262,7 +1265,8 @@ static int snd_mixart_probe(struct pci_dev *pci, }
/* enable PCI device */ - if ((err = pci_enable_device(pci)) < 0) + err = pci_enable_device(pci); + if (err < 0) return err; pci_set_master(pci);
@@ -1286,7 +1290,8 @@ static int snd_mixart_probe(struct pci_dev *pci, mgr->irq = -1;
/* resource assignment */ - if ((err = pci_request_regions(pci, CARD_NAME)) < 0) { + err = pci_request_regions(pci, CARD_NAME); + if (err < 0) { kfree(mgr); pci_disable_device(pci); return err; @@ -1351,7 +1356,8 @@ static int snd_mixart_probe(struct pci_dev *pci, "Digigram miXart at 0x%lx & 0x%lx, irq %i [PCM #%d]", mgr->mem[0].phys, mgr->mem[1].phys, mgr->irq, i);
- if ((err = snd_mixart_create(mgr, card, i)) < 0) { + err = snd_mixart_create(mgr, card, i); + if (err < 0) { snd_card_free(card); snd_mixart_free(mgr); return err; @@ -1362,7 +1368,8 @@ static int snd_mixart_probe(struct pci_dev *pci, snd_mixart_proc_init(mgr->chip[i]); }
- if ((err = snd_card_register(card)) < 0) { + err = snd_card_register(card); + if (err < 0) { snd_mixart_free(mgr); return err; } diff --git a/sound/pci/mixart/mixart_hwdep.c b/sound/pci/mixart/mixart_hwdep.c index 5bfd3ac80db5..61ad356a249d 100644 --- a/sound/pci/mixart/mixart_hwdep.c +++ b/sound/pci/mixart/mixart_hwdep.c @@ -318,9 +318,13 @@ static int mixart_first_init(struct mixart_mgr *mgr) int err; struct mixart_msg request;
- if((err = mixart_enum_connectors(mgr)) < 0) return err; + err = mixart_enum_connectors(mgr); + if (err < 0) + return err;
- if((err = mixart_enum_physio(mgr)) < 0) return err; + err = mixart_enum_physio(mgr); + if (err < 0) + return err;
/* send a synchro command to card (necessary to do this before first MSG_STREAM_START_STREAM_GRP_PACKET) */ /* though why not here */ @@ -540,15 +544,18 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw for (card_index = 0; card_index < mgr->num_cards; card_index++) { struct snd_mixart *chip = mgr->chip[card_index];
- if ((err = snd_mixart_create_pcm(chip)) < 0) + err = snd_mixart_create_pcm(chip); + if (err < 0) return err;
if (card_index == 0) { - if ((err = snd_mixart_create_mixer(chip->mgr)) < 0) + err = snd_mixart_create_mixer(chip->mgr); + if (err < 0) return err; }
- if ((err = snd_card_register(chip->card)) < 0) + err = snd_card_register(chip->card); + if (err < 0) return err; }
diff --git a/sound/pci/mixart/mixart_mixer.c b/sound/pci/mixart/mixart_mixer.c index 2b9496a66c77..4b3043ffbb43 100644 --- a/sound/pci/mixart/mixart_mixer.c +++ b/sound/pci/mixart/mixart_mixer.c @@ -1127,10 +1127,14 @@ int snd_mixart_create_mixer(struct mixart_mgr *mgr) temp = mixart_control_analog_level; temp.name = "Master Playback Volume"; temp.private_value = 0; /* playback */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); + if (err < 0) return err; /* output mute controls */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixart_control_output_switch, chip))) < 0) + err = snd_ctl_add(chip->card, + snd_ctl_new1(&mixart_control_output_switch, + chip)); + if (err < 0) return err;
/* analog input level control only on first two chips !*/ @@ -1138,7 +1142,9 @@ int snd_mixart_create_mixer(struct mixart_mgr *mgr) temp = mixart_control_analog_level; temp.name = "Master Capture Volume"; temp.private_value = 1; /* capture */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, + snd_ctl_new1(&temp, chip)); + if (err < 0) return err; }
@@ -1146,45 +1152,61 @@ int snd_mixart_create_mixer(struct mixart_mgr *mgr) temp.name = "PCM Playback Volume"; temp.count = MIXART_PLAYBACK_STREAMS; temp.private_value = 0; /* playback analog */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); + if (err < 0) return err;
temp.name = "PCM Capture Volume"; temp.count = 1; temp.private_value = MIXART_VOL_REC_MASK; /* capture analog */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); + if (err < 0) return err;
if(mgr->board_type == MIXART_DAUGHTER_TYPE_AES) { temp.name = "AES Playback Volume"; temp.count = MIXART_PLAYBACK_STREAMS; temp.private_value = MIXART_VOL_AES_MASK; /* playback AES/EBU */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, + snd_ctl_new1(&temp, chip)); + if (err < 0) return err;
temp.name = "AES Capture Volume"; temp.count = 0; temp.private_value = MIXART_VOL_REC_MASK | MIXART_VOL_AES_MASK; /* capture AES/EBU */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, + snd_ctl_new1(&temp, chip)); + if (err < 0) return err; } temp = mixart_control_pcm_switch; temp.name = "PCM Playback Switch"; temp.private_value = 0; /* playback analog */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); + if (err < 0) return err;
if(mgr->board_type == MIXART_DAUGHTER_TYPE_AES) { temp.name = "AES Playback Switch"; temp.private_value = MIXART_VOL_AES_MASK; /* playback AES/EBU */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip))) < 0) + err = snd_ctl_add(chip->card, + snd_ctl_new1(&temp, chip)); + if (err < 0) return err; }
/* monitoring */ - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixart_control_monitor_vol, chip))) < 0) + err = snd_ctl_add(chip->card, + snd_ctl_new1(&mixart_control_monitor_vol, + chip)); + if (err < 0) return err; - if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixart_control_monitor_sw, chip))) < 0) + + err = snd_ctl_add(chip->card, + snd_ctl_new1(&mixart_control_monitor_sw, + chip)); + if (err < 0) return err;
/* init all mixer data and program the master volumes/switches */
From: Markus Elfring elfring@users.sourceforge.net Date: Thu, 16 Nov 2017 16:18:38 +0100
Add jump targets 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.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/pci/mixart/mixart.c | 61 ++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 30 deletions(-)
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c index ff90a06f775e..928079520502 100644 --- a/sound/pci/mixart/mixart.c +++ b/sound/pci/mixart/mixart.c @@ -1274,16 +1274,16 @@ static int snd_mixart_probe(struct pci_dev *pci, if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { dev_err(&pci->dev, "architecture does not support 32bit PCI busmaster DMA\n"); - pci_disable_device(pci); - return -ENXIO; + err = -ENXIO; + goto disable_device; }
/* */ mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); if (! mgr) { - pci_disable_device(pci); - return -ENOMEM; + err = -ENOMEM; + goto disable_device; }
mgr->pci = pci; @@ -1293,8 +1293,7 @@ static int snd_mixart_probe(struct pci_dev *pci, err = pci_request_regions(pci, CARD_NAME); if (err < 0) { kfree(mgr); - pci_disable_device(pci); - return err; + goto disable_device; } for (i = 0; i < 2; i++) { mgr->mem[i].phys = pci_resource_start(pci, i); @@ -1302,8 +1301,8 @@ static int snd_mixart_probe(struct pci_dev *pci, if (!mgr->mem[i].virt) { dev_err(&pci->dev, "unable to remap resource 0x%lx\n", mgr->mem[i].phys); - snd_mixart_free(mgr); - return -EBUSY; + err = -EBUSY; + goto free_sound_chip; } }
@@ -1311,8 +1310,8 @@ static int snd_mixart_probe(struct pci_dev *pci, snd_mixart_threaded_irq, IRQF_SHARED, KBUILD_MODNAME, mgr)) { dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq); - snd_mixart_free(mgr); - return -EBUSY; + err = -EBUSY; + goto free_sound_chip; } mgr->irq = pci->irq;
@@ -1345,8 +1344,7 @@ static int snd_mixart_probe(struct pci_dev *pci,
if (err < 0) { dev_err(&pci->dev, "cannot allocate the card %d\n", i); - snd_mixart_free(mgr); - return err; + goto free_sound_chip; }
strcpy(card->driver, CARD_NAME); @@ -1359,8 +1357,7 @@ static int snd_mixart_probe(struct pci_dev *pci, err = snd_mixart_create(mgr, card, i); if (err < 0) { snd_card_free(card); - snd_mixart_free(mgr); - return err; + goto free_sound_chip; }
if(i==0) { @@ -1369,10 +1366,8 @@ static int snd_mixart_probe(struct pci_dev *pci, }
err = snd_card_register(card); - if (err < 0) { - snd_mixart_free(mgr); - return err; - } + if (err < 0) + goto free_sound_chip; }
/* init firmware status (mgr->dsp_loaded reset in hwdep_new) */ @@ -1382,10 +1377,9 @@ static int snd_mixart_probe(struct pci_dev *pci, size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS * sizeof(struct mixart_flowinfo)) ); if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), - size, &mgr->flowinfo) < 0) { - snd_mixart_free(mgr); - return -ENOMEM; - } + size, &mgr->flowinfo) < 0) + goto e_nomem; + /* init streaminfo_array */ memset(mgr->flowinfo.area, 0, size);
@@ -1393,23 +1387,30 @@ static int snd_mixart_probe(struct pci_dev *pci, size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS * sizeof(struct mixart_bufferinfo)) ); if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), - size, &mgr->bufferinfo) < 0) { - snd_mixart_free(mgr); - return -ENOMEM; - } + size, &mgr->bufferinfo) < 0) + goto e_nomem; + /* init bufferinfo_array */ memset(mgr->bufferinfo.area, 0, size);
/* set up firmware */ err = snd_mixart_setup_firmware(mgr); - if (err < 0) { - snd_mixart_free(mgr); - return err; - } + if (err < 0) + goto free_sound_chip;
pci_set_drvdata(pci, mgr); dev++; return 0; + +disable_device: + pci_disable_device(pci); + return err; + +e_nomem: + err = -ENOMEM; +free_sound_chip: + snd_mixart_free(mgr); + return err; }
static void snd_mixart_remove(struct pci_dev *pci)
participants (1)
-
SF Markus Elfring