Skip to contentSkip to conversation

ALSA: korg1212: Fine-tuning for three function implementations

PATCH Applied SF Markus Elfring 2 participants 5 messages Nov 16, 2017 – Nov 28, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ALSA: korg1212: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Thu, 16 Nov 2017 12:42:42 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Adjust eight function calls together with a variable assignment Delete a duplicate function call "release_firmware" in snd_korg1212_create() Use common error handling code in two functions

 sound/pci/korg1212/korg1212.c | 85 ++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 38 deletions(-)
Signature · 1 line
2.15.0
#1 lore raw

PATCH 1/3 ALSA: korg1212: Adjust eight function calls together with a variable assignment

From: Markus Elfring <[email protected]>
Date: Thu, 16 Nov 2017 09:42:45 +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/korg1212/korg1212.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
sound/pci/korg1212/korg1212.c +18 -10
index c7b007164c99..6dde8c215b48 100644
@@ -1542,7 +1542,8 @@ static int snd_korg1212_hw_params(struct snd_pcm_substream *substream,
 	        return 0;
 	}
 
-        if ((err = snd_korg1212_SetRate(korg1212, params_rate(params))) < 0) {
+	err = snd_korg1212_SetRate(korg1212, params_rate(params));
+	if (err < 0) {
                 spin_unlock_irqrestore(&korg1212->lock, flags);
                 return err;
         }
@@ -2174,8 +2175,9 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
         };
 
         * rchip = NULL;
-        if ((err = pci_enable_device(pci)) < 0)
-                return err;
+	err = pci_enable_device(pci);
+	if (err < 0)
+		return err;
 
         korg1212 = kzalloc(sizeof(*korg1212), GFP_KERNEL);
         if (korg1212 = NULL) {
@@ -2211,7 +2213,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
         for (i=0; i<kAudioChannels; i++)
                 korg1212->volumePhase[i] = 0;
 
-	if ((err = pci_request_regions(pci, "korg1212")) < 0) {
+	err = pci_request_regions(pci, "korg1212");
+	if (err < 0) {
 		kfree(korg1212);
 		pci_disable_device(pci);
 		return err;
@@ -2235,7 +2238,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 		   korg1212->iomem2, iomem2_size,
 		   stateName[korg1212->cardState]);
 
-        if ((korg1212->iobase = ioremap(korg1212->iomem, iomem_size)) = NULL) {
+	korg1212->iobase = ioremap(korg1212->iomem, iomem_size);
+	if (!korg1212->iobase) {
 		snd_printk(KERN_ERR "korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212->iomem,
                            korg1212->iomem + iomem_size - 1);
                 snd_korg1212_free(korg1212);
@@ -2375,7 +2379,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	if (rc)
 		K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);
 
-        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops)) < 0) {
+	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops);
+	if (err < 0) {
                 snd_korg1212_free(korg1212);
                 return err;
         }
@@ -2400,8 +2405,9 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
                korg1212->RoutingTablePhy, LowerWordSwap(korg1212->RoutingTablePhy),
                korg1212->AdatTimeCodePhy, LowerWordSwap(korg1212->AdatTimeCodePhy));
 
-        if ((err = snd_pcm_new(korg1212->card, "korg1212", 0, 1, 1, &korg1212->pcm)) < 0)
-                return err;
+	err = snd_pcm_new(korg1212->card, "korg1212", 0, 1, 1, &korg1212->pcm);
+	if (err < 0)
+		return err;
 
 	korg1212->pcm->private_data = korg1212;
         korg1212->pcm->private_free = snd_korg1212_free_pcm;
@@ -2451,7 +2457,8 @@ snd_korg1212_probe(struct pci_dev *pci,
 	if (err < 0)
 		return err;
 
-        if ((err = snd_korg1212_create(card, pci, &korg1212)) < 0) {
+	err = snd_korg1212_create(card, pci, &korg1212);
+	if (err < 0) {
 		snd_card_free(card);
 		return err;
 	}
@@ -2463,7 +2470,8 @@ snd_korg1212_probe(struct pci_dev *pci,
 
         K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card->longname);
 
-	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
#2 lore raw

PATCH 2/3 ALSA: korg1212: Delete a duplicate function call "release_firmware" in snd_korg1212_create()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 16 Nov 2017 11:22:26 +0100

The function "release_firmware" is called in the current implementation of the function "_request_firmware" after a failure was detected.

Such a call should therefore not be repeated directly after the corresponding error information was received in the local variable "err" of the function "snd_korg1212_create".
Thus remove a misplaced function call.

---
 sound/pci/korg1212/korg1212.c | 1 -
 1 file changed, 1 deletion(-)
sound/pci/korg1212/korg1212.c +0 -1
index 6dde8c215b48..dc701519d219 100644
@@ -2352,7 +2352,6 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 
 	err = request_firmware(&dsp_code, "korg/k1212.dsp", &pci->dev);
 	if (err < 0) {
-		release_firmware(dsp_code);
 		snd_printk(KERN_ERR "firmware not available\n");
 		snd_korg1212_free(korg1212);
 		return err;
Signature · 1 line
2.15.0
#4 lore raw

PATCH 3/3 ALSA: korg1212: Use common error handling code in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 16 Nov 2017 11:55:58 +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/korg1212/korg1212.c | 62 ++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 30 deletions(-)
sound/pci/korg1212/korg1212.c +32 -30
index dc701519d219..b908c7c986ab 100644
@@ -2181,8 +2181,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 
         korg1212 = kzalloc(sizeof(*korg1212), GFP_KERNEL);
         if (korg1212 = NULL) {
-		pci_disable_device(pci);
-                return -ENOMEM;
+		err = -ENOMEM;
+		goto disable_device;
 	}
 
 	korg1212->card = card;
@@ -2216,8 +2216,7 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	err = pci_request_regions(pci, "korg1212");
 	if (err < 0) {
 		kfree(korg1212);
-		pci_disable_device(pci);
-		return err;
+		goto disable_device;
 	}
 
         korg1212->iomem = pci_resource_start(korg1212->pci, 0);
@@ -2242,8 +2241,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	if (!korg1212->iobase) {
 		snd_printk(KERN_ERR "korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212->iomem,
                            korg1212->iomem + iomem_size - 1);
-                snd_korg1212_free(korg1212);
-                return -EBUSY;
+		err = -EBUSY;
+		goto free_sound_chip;
         }
 
         err = request_irq(pci->irq, snd_korg1212_interrupt,
@@ -2252,8 +2251,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 
         if (err) {
 		snd_printk(KERN_ERR "korg1212: unable to grab IRQ %d\n", pci->irq);
-                snd_korg1212_free(korg1212);
-                return -EBUSY;
+		err = -EBUSY;
+		goto free_sound_chip;
         }
 
         korg1212->irq = pci->irq;
@@ -2298,8 +2297,7 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
 				sizeof(struct KorgSharedBuffer), &korg1212->dma_shared) < 0) {
 		snd_printk(KERN_ERR "korg1212: can not allocate shared buffer memory (%zd bytes)\n", sizeof(struct KorgSharedBuffer));
-                snd_korg1212_free(korg1212);
-                return -ENOMEM;
+		goto e_nomem;
         }
         korg1212->sharedBufferPtr = (struct KorgSharedBuffer *)korg1212->dma_shared.area;
         korg1212->sharedBufferPhy = korg1212->dma_shared.addr;
@@ -2313,8 +2311,7 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
 				korg1212->DataBufsSize, &korg1212->dma_play) < 0) {
 		snd_printk(KERN_ERR "korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
-                snd_korg1212_free(korg1212);
-                return -ENOMEM;
+		goto e_nomem;
         }
 	korg1212->playDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_play.area;
 	korg1212->PlayDataPhy = korg1212->dma_play.addr;
@@ -2325,8 +2322,7 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
 				korg1212->DataBufsSize, &korg1212->dma_rec) < 0) {
 		snd_printk(KERN_ERR "korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize);
-                snd_korg1212_free(korg1212);
-                return -ENOMEM;
+		goto e_nomem;
         }
         korg1212->recordDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_rec.area;
         korg1212->RecDataPhy = korg1212->dma_rec.addr;
@@ -2353,16 +2349,14 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 	err = request_firmware(&dsp_code, "korg/k1212.dsp", &pci->dev);
 	if (err < 0) {
 		snd_printk(KERN_ERR "firmware not available\n");
-		snd_korg1212_free(korg1212);
-		return err;
+		goto free_sound_chip;
 	}
 
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
 				dsp_code->size, &korg1212->dma_dsp) < 0) {
 		snd_printk(KERN_ERR "korg1212: cannot allocate dsp code memory (%zd bytes)\n", dsp_code->size);
-                snd_korg1212_free(korg1212);
 		release_firmware(dsp_code);
-                return -ENOMEM;
+		goto e_nomem;
         }
 
         K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n",
@@ -2379,10 +2373,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
 		K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]);
 
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops);
-	if (err < 0) {
-                snd_korg1212_free(korg1212);
-                return err;
-        }
+	if (err < 0)
+		goto free_sound_chip;
         
 	snd_korg1212_EnableCardInterrupts(korg1212);
 
@@ -2429,6 +2421,15 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
         * rchip = korg1212;
 	return 0;
 
+disable_device:
+	pci_disable_device(pci);
+	return err;
+
+e_nomem:
+	err = -ENOMEM;
+free_sound_chip:
+	snd_korg1212_free(korg1212);
+	return err;
 }
 
 /*
@@ -2457,10 +2458,8 @@ snd_korg1212_probe(struct pci_dev *pci,
 		return err;
 
 	err = snd_korg1212_create(card, pci, &korg1212);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	strcpy(card->driver, "korg1212");
 	strcpy(card->shortname, "korg1212");
@@ -2470,13 +2469,16 @@ snd_korg1212_probe(struct pci_dev *pci,
         K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card->longname);
 
 	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_korg1212_remove(struct pci_dev *pci)
Signature · 1 line
2.15.0
Applied
#3 lore raw

Re: [PATCH 2/3] ALSA: korg1212: Delete a duplicate function call "release_firmware" in snd_korg1212_create()

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 16 Nov 2017 11:22:26 +0100

The function "release_firmware" is called in the current implementation of the function "_request_firmware" after a failure was detected.

Quoted 8 lines

Such a call should therefore not be repeated directly after the corresponding error information was received in the local variable "err" of the function "snd_korg1212_create".
Thus remove a misplaced function call.

Applied, thanks.

Takashi