[alsa-devel] [PATCH 0/2] ALSA: intel8x0: Fine-tuning for seven function implementations
From: Markus Elfring elfring@users.sourceforge.net Date: Wed, 15 Nov 2017 20:40:30 +0100
Two update suggestions were taken into account from static source code analysis.
Markus Elfring (2): Adjust 15 function calls together with a variable assignment Use common error handling code in two functions
sound/pci/intel8x0.c | 111 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 46 deletions(-)
From: Markus Elfring elfring@users.sourceforge.net Date: Wed, 15 Nov 2017 20:00: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/intel8x0.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-)
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index 4c24346340f4..2d7e0fb163f9 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c @@ -581,7 +581,8 @@ static unsigned short snd_intel8x0_codec_read(struct snd_ac97 *ac97, res = 0xffff; } else { res = iagetword(chip, reg + ac97->num * 0x80); - if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) { + tmp = igetdword(chip, ICHREG(GLOB_STA)); + if (tmp & ICH_RCS) { /* reset RCS and preserve other R/WC bits */ iputdword(chip, ICHREG(GLOB_STA), tmp & ~(chip->codec_ready_bits | ICH_GSCI)); @@ -602,7 +603,8 @@ static void snd_intel8x0_codec_read_test(struct intel8x0 *chip,
if (snd_intel8x0_codec_semaphore(chip, codec) >= 0) { iagetword(chip, codec * 0x80); - if ((tmp = igetdword(chip, ICHREG(GLOB_STA))) & ICH_RCS) { + tmp = igetdword(chip, ICHREG(GLOB_STA)); + if (tmp & ICH_RCS) { /* reset RCS and preserve other R/WC bits */ iputdword(chip, ICHREG(GLOB_STA), tmp & ~(chip->codec_ready_bits | ICH_GSCI)); @@ -1180,7 +1182,10 @@ static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ich runtime->hw.buffer_bytes_max = 64*1024; runtime->hw.period_bytes_max = 64*1024; } - 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; runtime->private_data = ichdev; return 0; @@ -2274,7 +2279,9 @@ static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock, udelay(1); } } - if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0) + + err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus); + if (err < 0) goto __err; pbus->private_free = snd_intel8x0_mixer_free_ac97_bus; if (ac97_clock >= 8000 && ac97_clock <= 48000) @@ -2290,7 +2297,8 @@ static int snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock, ac97.pci = chip->pci; for (i = 0; i < codecs; i++) { ac97.num = i; - if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) { + err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i]); + if (err < 0) { if (err != -EACCES) dev_err(chip->card->dev, "Unable to initialize codec #%d\n", i); @@ -2575,11 +2583,13 @@ static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing) int err; if (chip->device_type != DEVICE_ALI) { - if ((err = snd_intel8x0_ich_chip_init(chip, probing)) < 0) + err = snd_intel8x0_ich_chip_init(chip, probing); + if (err < 0) return err; iagetword(chip, 0); /* clear semaphore flag */ } else { - if ((err = snd_intel8x0_ali_chip_init(chip, probing)) < 0) + err = snd_intel8x0_ali_chip_init(chip, probing); + if (err < 0) return err; }
@@ -3035,7 +3045,8 @@ static int snd_intel8x0_create(struct snd_card *card,
*r_intel8x0 = NULL;
- if ((err = pci_enable_device(pci)) < 0) + err = pci_enable_device(pci); + if (err < 0) return err;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); @@ -3061,7 +3072,8 @@ static int snd_intel8x0_create(struct snd_card *card, pci->device == PCI_DEVICE_ID_INTEL_440MX) chip->fix_nocache = 1; /* enable workaround */
- if ((err = pci_request_regions(pci, card->shortname)) < 0) { + err = pci_request_regions(pci, card->shortname); + if (err < 0) { kfree(chip); pci_disable_device(pci); return err; @@ -3178,7 +3190,8 @@ static int snd_intel8x0_create(struct snd_card *card, for (i = 0; i < chip->max_codecs; i++) chip->codec_isr_bits |= chip->codec_bit[i];
- if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) { + err = snd_intel8x0_chip_init(chip, 1); + if (err < 0) { snd_intel8x0_free(chip); return err; } @@ -3192,7 +3205,8 @@ static int snd_intel8x0_create(struct snd_card *card, } chip->irq = pci->irq;
- 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_intel8x0_free(chip); return err; } @@ -3299,18 +3313,20 @@ static int snd_intel8x0_probe(struct pci_dev *pci, buggy_irq = 0; }
- if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, - &chip)) < 0) { + err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip); + if (err < 0) { snd_card_free(card); return err; } card->private_data = chip;
- if ((err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk)) < 0) { + err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk); + if (err < 0) { snd_card_free(card); return err; } - if ((err = snd_intel8x0_pcm(chip)) < 0) { + err = snd_intel8x0_pcm(chip); + if (err < 0) { snd_card_free(card); return err; } @@ -3330,7 +3346,8 @@ static int snd_intel8x0_probe(struct pci_dev *pci, } }
- 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 20:30:46 +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/intel8x0.c | 74 +++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 36 deletions(-)
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index 2d7e0fb163f9..7d31012cdf90 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c @@ -3051,8 +3051,8 @@ static int snd_intel8x0_create(struct snd_card *card,
chip = kzalloc(sizeof(*chip), GFP_KERNEL); if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; + err = -ENOMEM; + goto disable_device; } spin_lock_init(&chip->reg_lock); chip->device_type = device_type; @@ -3075,8 +3075,7 @@ static int snd_intel8x0_create(struct snd_card *card, err = pci_request_regions(pci, card->shortname); if (err < 0) { kfree(chip); - pci_disable_device(pci); - return err; + goto disable_device; }
if (device_type == DEVICE_ALI) { @@ -3091,8 +3090,7 @@ static int snd_intel8x0_create(struct snd_card *card, chip->addr = pci_iomap(pci, 0, 0); if (!chip->addr) { dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_intel8x0_free(chip); - return -EIO; + goto e_io; } if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ chip->bmaddr = pci_iomap(pci, 3, 0); @@ -3102,8 +3100,7 @@ static int snd_intel8x0_create(struct snd_card *card, port_inited: if (!chip->bmaddr) { dev_err(card->dev, "Controller space ioremap problem\n"); - snd_intel8x0_free(chip); - return -EIO; + goto e_io; } chip->bdbars_count = bdbars[device_type];
@@ -3143,9 +3140,9 @@ static int snd_intel8x0_create(struct snd_card *card, if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, &chip->bdbars) < 0) { - snd_intel8x0_free(chip); dev_err(card->dev, "cannot allocate buffer descriptors\n"); - return -ENOMEM; + err = -ENOMEM; + goto free_sound_chip; } /* tables must be aligned to 8 bytes here, but the kernel pages are much bigger, so we don't care (on i386) */ @@ -3191,28 +3188,34 @@ static int snd_intel8x0_create(struct snd_card *card, chip->codec_isr_bits |= chip->codec_bit[i];
err = snd_intel8x0_chip_init(chip, 1); - if (err < 0) { - snd_intel8x0_free(chip); - return err; - } + if (err < 0) + goto free_sound_chip;
/* request irq after initializaing int_sta_mask, etc */ if (request_irq(pci->irq, snd_intel8x0_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_intel8x0_free(chip); - return -EBUSY; + err = -EBUSY; + goto free_sound_chip; } chip->irq = pci->irq;
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_intel8x0_free(chip); - return err; - } + if (err < 0) + goto free_sound_chip;
*r_intel8x0 = chip; return 0; + +disable_device: + pci_disable_device(pci); + return err; + +e_io: + err = -EIO; +free_sound_chip: + snd_intel8x0_free(chip); + return err; }
static struct shortname_table { @@ -3314,22 +3317,18 @@ static int snd_intel8x0_probe(struct pci_dev *pci, }
err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + card->private_data = chip;
err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + err = snd_intel8x0_pcm(chip); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; snd_intel8x0_proc_init(chip);
@@ -3347,12 +3346,15 @@ static int snd_intel8x0_probe(struct pci_dev *pci, }
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); return 0; + +free_card: + snd_card_free(card); + return err; }
static void snd_intel8x0_remove(struct pci_dev *pci)
participants (1)
-
SF Markus Elfring