[alsa-devel] [PATCH 0/3] ALSA: fm801: Fine-tuning for seven function implementations
From: Markus Elfring elfring@users.sourceforge.net Date: Wed, 15 Nov 2017 13:40:43 +0100
A few update suggestions were taken into account from static source code analysis.
Markus Elfring (3): Adjust 17 function calls together with a variable assignment Use common error handling code in two functions Rename a jump label in snd_card_fm801_probe()
sound/pci/fm801.c | 140 +++++++++++++++++++++++++++++------------------------- 1 file changed, 76 insertions(+), 64 deletions(-)
From: Markus Elfring elfring@users.sourceforge.net Date: Wed, 15 Nov 2017 13:20:49 +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/fm801.c | 75 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 30 deletions(-)
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index 73a67bc3586b..3648af4581a0 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -655,9 +655,10 @@ static int snd_fm801_playback_open(struct snd_pcm_substream *substream) SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels); } - if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) - return err; - return 0; + + err = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + return (err < 0) ? err : 0; }
static int snd_fm801_capture_open(struct snd_pcm_substream *substream) @@ -670,9 +671,9 @@ static int snd_fm801_capture_open(struct snd_pcm_substream *substream) runtime->hw = snd_fm801_capture; snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); - if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) - return err; - return 0; + err = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + return (err < 0) ? err : 0; }
static int snd_fm801_playback_close(struct snd_pcm_substream *substream) @@ -717,9 +718,9 @@ static int snd_fm801_pcm(struct fm801 *chip, int device) { struct pci_dev *pdev = to_pci_dev(chip->dev); struct snd_pcm *pcm; - int err; + int err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm);
- if ((err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm)) < 0) + if (err < 0) return err;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_fm801_playback_ops); @@ -986,10 +987,10 @@ static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct fm801 *chip = snd_kcontrol_chip(kcontrol); - unsigned short val; + unsigned short val = ucontrol->value.enumerated.item[0];
- if ((val = ucontrol->value.enumerated.item[0]) > 4) - return -EINVAL; + if (val > 4) + return -EINVAL; return snd_fm801_update_bits(chip, FM801_REC_SRC, 7, val); }
@@ -1053,19 +1054,22 @@ static int snd_fm801_mixer(struct fm801 *chip) .read = snd_fm801_codec_read, };
- if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) + err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); + if (err < 0) return err; chip->ac97_bus->private_free = snd_fm801_mixer_free_ac97_bus;
memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; ac97.private_free = snd_fm801_mixer_free_ac97; - if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) + err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); + if (err < 0) return err; if (chip->secondary) { ac97.num = 1; ac97.addr = chip->secondary_addr; - if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_sec)) < 0) + err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_sec); + if (err < 0) return err; } for (i = 0; i < FM801_CONTROLS; i++) @@ -1208,7 +1212,8 @@ static int snd_fm801_create(struct snd_card *card, };
*rchip = NULL; - if ((err = pcim_enable_device(pci)) < 0) + err = pcim_enable_device(pci); + if (err < 0) return err; chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL); if (chip == NULL) @@ -1218,7 +1223,8 @@ static int snd_fm801_create(struct snd_card *card, chip->dev = &pci->dev; chip->irq = -1; chip->tea575x_tuner = tea575x_tuner; - if ((err = pci_request_regions(pci, "FM801")) < 0) + err = pci_request_regions(pci, "FM801"); + if (err < 0) return err; chip->port = pci_resource_start(pci, 0);
@@ -1248,7 +1254,8 @@ static int snd_fm801_create(struct snd_card *card,
snd_fm801_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_fm801_free(chip); return err; } @@ -1321,7 +1328,10 @@ static int snd_card_fm801_probe(struct pci_dev *pci, 0, &card); if (err < 0) return err; - if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) { + + err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], + &chip); + if (err < 0) { snd_card_free(card); return err; } @@ -1336,35 +1346,40 @@ static int snd_card_fm801_probe(struct pci_dev *pci, if (chip->tea575x_tuner & TUNER_ONLY) goto __fm801_tuner_only;
- if ((err = snd_fm801_pcm(chip, 0)) < 0) { + err = snd_fm801_pcm(chip, 0); + if (err < 0) { snd_card_free(card); return err; } - if ((err = snd_fm801_mixer(chip)) < 0) { + err = snd_fm801_mixer(chip); + if (err < 0) { snd_card_free(card); return err; } - if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, - chip->port + FM801_MPU401_DATA, - MPU401_INFO_INTEGRATED | - MPU401_INFO_IRQ_HOOK, - -1, &chip->rmidi)) < 0) { + err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, + chip->port + FM801_MPU401_DATA, + MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, + -1, &chip->rmidi); + if (err < 0) { snd_card_free(card); return err; } - if ((err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0, - chip->port + FM801_OPL3_BANK1, - OPL3_HW_OPL3_FM801, 1, &opl3)) < 0) { + err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0, + chip->port + FM801_OPL3_BANK1, + OPL3_HW_OPL3_FM801, 1, &opl3); + if (err < 0) { snd_card_free(card); return err; } - if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { + err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); + if (err < 0) { snd_card_free(card); return err; }
__fm801_tuner_only: - if ((err = snd_card_register(card)) < 0) { + err = snd_card_register(card); + if (err < 0) { snd_card_free(card); return err; }
From: Markus Elfring elfring@users.sourceforge.net Date: Wed, 15 Nov 2017 13:27:57 +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.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/pci/fm801.c | 77 ++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 40 deletions(-)
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index 3648af4581a0..e4c0fa8db5f6 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -1245,8 +1245,8 @@ static int snd_fm801_create(struct snd_card *card, if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_fm801_free(chip); - return -EBUSY; + err = -EBUSY; + goto free_sound_chip; } chip->irq = pci->irq; pci_set_master(pci); @@ -1255,17 +1255,14 @@ static int snd_fm801_create(struct snd_card *card, snd_fm801_chip_init(chip);
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_fm801_free(chip); - return err; - } + if (err < 0) + goto free_sound_chip;
#ifdef CONFIG_SND_FM801_TEA575X_BOOL err = v4l2_device_register(&pci->dev, &chip->v4l2_dev); - if (err < 0) { - snd_fm801_free(chip); - return err; - } + if (err < 0) + goto free_sound_chip; + chip->tea.v4l2_dev = &chip->v4l2_dev; chip->tea.radio_nr = radio_nr; chip->tea.private_data = chip; @@ -1275,8 +1272,8 @@ static int snd_fm801_create(struct snd_card *card, (chip->tea575x_tuner & TUNER_TYPE_MASK) < 4) { if (snd_tea575x_init(&chip->tea, THIS_MODULE)) { dev_err(card->dev, "TEA575x radio not found\n"); - snd_fm801_free(chip); - return -ENODEV; + err = -ENODEV; + goto free_sound_chip; } } else if ((chip->tea575x_tuner & TUNER_TYPE_MASK) == 0) { unsigned int tuner_only = chip->tea575x_tuner & TUNER_ONLY; @@ -1306,6 +1303,10 @@ static int snd_fm801_create(struct snd_card *card,
*rchip = chip; return 0; + +free_sound_chip: + snd_fm801_free(chip); + return err; }
static int snd_card_fm801_probe(struct pci_dev *pci, @@ -1331,10 +1332,9 @@ static int snd_card_fm801_probe(struct pci_dev *pci,
err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + card->private_data = chip;
strcpy(card->driver, "FM801"); @@ -1347,45 +1347,42 @@ static int snd_card_fm801_probe(struct pci_dev *pci, goto __fm801_tuner_only;
err = snd_fm801_pcm(chip, 0); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + err = snd_fm801_mixer(chip); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, chip->port + FM801_MPU401_DATA, MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, -1, &chip->rmidi); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0, chip->port + FM801_OPL3_BANK1, OPL3_HW_OPL3_FM801, 1, &opl3); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card;
__fm801_tuner_only: 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_card_fm801_remove(struct pci_dev *pci)
From: Markus Elfring elfring@users.sourceforge.net Date: Wed, 15 Nov 2017 13:30:07 +0100
Adjust a jump label according to the Linux coding style convention.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/pci/fm801.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index e4c0fa8db5f6..0eaf3297400c 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -1344,7 +1344,7 @@ static int snd_card_fm801_probe(struct pci_dev *pci, card->shortname, chip->port, chip->irq);
if (chip->tea575x_tuner & TUNER_ONLY) - goto __fm801_tuner_only; + goto register_card;
err = snd_fm801_pcm(chip, 0); if (err < 0) @@ -1371,7 +1371,7 @@ static int snd_card_fm801_probe(struct pci_dev *pci, if (err < 0) goto free_card;
- __fm801_tuner_only: +register_card: err = snd_card_register(card); if (err < 0) goto free_card;
participants (1)
-
SF Markus Elfring