mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] ALSA: pcxhr: Fine-tuning for three function implementations
@ 2017-11-16 21:24 SF Markus Elfring
  2017-11-16 21:26 ` [PATCH 1/2] ALSA: pcxhr: Adjust six function calls together with a variable assignment SF Markus Elfring
  2017-11-16 21:28 ` [PATCH 2/2] ALSA: pcxhr: Use common error handling code in pcxhr_probe() SF Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-16 21:24 UTC (permalink / raw)
  To: alsa-devel, Arnd Bergmann, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Nov 2017 22:20:02 +0100

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

Markus Elfring (2):
  Adjust six function calls together with a variable assignment
  Use common error handling code in pcxhr_probe()

 sound/pci/pcxhr/pcxhr.c | 82 ++++++++++++++++++++++++++-----------------------
 1 file changed, 44 insertions(+), 38 deletions(-)

-- 
2.15.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] ALSA: pcxhr: Adjust six function calls together with a variable assignment
  2017-11-16 21:24 [PATCH 0/2] ALSA: pcxhr: Fine-tuning for three function implementations SF Markus Elfring
@ 2017-11-16 21:26 ` SF Markus Elfring
  2017-11-16 21:28 ` [PATCH 2/2] ALSA: pcxhr: Use common error handling code in pcxhr_probe() SF Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-16 21:26 UTC (permalink / raw)
  To: alsa-devel, Arnd Bergmann, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Nov 2017 21:50:21 +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/pcxhr/pcxhr.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index f9ae72f28ddc..c490d7e57ff7 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -1166,9 +1166,10 @@ int pcxhr_create_pcm(struct snd_pcxhr *chip)
 	char name[32];
 
 	snprintf(name, sizeof(name), "pcxhr %d", chip->chip_idx);
-	if ((err = snd_pcm_new(chip->card, name, 0,
-			       chip->nb_streams_play,
-			       chip->nb_streams_capt, &pcm)) < 0) {
+	err = snd_pcm_new(chip->card, name, 0,
+			  chip->nb_streams_play,
+			  chip->nb_streams_capt, &pcm);
+	if (err < 0) {
 		dev_err(chip->card->dev, "cannot create pcm %s\n", name);
 		return err;
 	}
@@ -1233,7 +1234,8 @@ static int pcxhr_create(struct pcxhr_mgr *mgr,
 			chip->nb_streams_capt = 1;	/* or 1 stereo stream */
 	}
 
-	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) {
 		pcxhr_chip_free(chip);
 		return err;
 	}
@@ -1530,7 +1532,8 @@ static int pcxhr_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);
 
@@ -1575,7 +1578,8 @@ static int pcxhr_probe(struct pci_dev *pci,
 		mgr->granularity = PCXHR_GRANULARITY;
 
 	/* 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;
@@ -1646,7 +1650,8 @@ static int pcxhr_probe(struct pci_dev *pci,
 		snprintf(card->longname, sizeof(card->longname),
 			 "%s [PCM #%d]", mgr->name, i);
 
-		if ((err = pcxhr_create(mgr, card, i)) < 0) {
+		err = pcxhr_create(mgr, card, i);
+		if (err < 0) {
 			snd_card_free(card);
 			pcxhr_free(mgr);
 			return err;
@@ -1656,7 +1661,8 @@ static int pcxhr_probe(struct pci_dev *pci,
 			/* init proc interface only for chip0 */
 			pcxhr_proc_init(mgr->chip[i]);
 
-		if ((err = snd_card_register(card)) < 0) {
+		err = snd_card_register(card);
+		if (err < 0) {
 			pcxhr_free(mgr);
 			return err;
 		}
-- 
2.15.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ALSA: pcxhr: Use common error handling code in pcxhr_probe()
  2017-11-16 21:24 [PATCH 0/2] ALSA: pcxhr: Fine-tuning for three function implementations SF Markus Elfring
  2017-11-16 21:26 ` [PATCH 1/2] ALSA: pcxhr: Adjust six function calls together with a variable assignment SF Markus Elfring
@ 2017-11-16 21:28 ` SF Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-11-16 21:28 UTC (permalink / raw)
  To: alsa-devel, Arnd Bergmann, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Nov 2017 22:11:52 +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/pcxhr/pcxhr.c | 62 ++++++++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index c490d7e57ff7..f05c6a042890 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -1541,21 +1541,21 @@ static int pcxhr_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;
 	}
 
 	/* alloc card manager */
 	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-	if (! mgr) {
-		pci_disable_device(pci);
-		return -ENOMEM;
+	if (!mgr) {
+		err = -ENOMEM;
+		goto disable_device;
 	}
 
 	if (snd_BUG_ON(pci_id->driver_data >= PCI_ID_LAST)) {
 		kfree(mgr);
-		pci_disable_device(pci);
-		return -ENODEV;
+		err = -ENODEV;
+		goto disable_device;
 	}
 	card_name =
 		pcxhr_board_params[pci_id->driver_data].board_name;
@@ -1581,8 +1581,7 @@ static int pcxhr_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 < 3; i++)
 		mgr->port[i] = pci_resource_start(pci, i);
@@ -1594,8 +1593,8 @@ static int pcxhr_probe(struct pci_dev *pci,
 				 pcxhr_threaded_irq, IRQF_SHARED,
 				 KBUILD_MODNAME, mgr)) {
 		dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq);
-		pcxhr_free(mgr);
-		return -EBUSY;
+		err = -EBUSY;
+		goto free_manager;
 	}
 	mgr->irq = pci->irq;
 
@@ -1614,10 +1613,8 @@ static int pcxhr_probe(struct pci_dev *pci,
 			    sizeof(u32) * (PCXHR_SIZE_MAX_LONG_STATUS -
 					   PCXHR_SIZE_MAX_STATUS),
 			    GFP_KERNEL);
-	if (! mgr->prmh) {
-		pcxhr_free(mgr);
-		return -ENOMEM;
-	}
+	if (!mgr->prmh)
+		goto e_nomem;
 
 	for (i=0; i < PCXHR_MAX_CARDS; i++) {
 		struct snd_card *card;
@@ -1640,8 +1637,7 @@ static int pcxhr_probe(struct pci_dev *pci,
 
 		if (err < 0) {
 			dev_err(&pci->dev, "cannot allocate the card %d\n", i);
-			pcxhr_free(mgr);
-			return err;
+			goto free_manager;
 		}
 
 		strcpy(card->driver, DRIVER_NAME);
@@ -1653,8 +1649,7 @@ static int pcxhr_probe(struct pci_dev *pci,
 		err = pcxhr_create(mgr, card, i);
 		if (err < 0) {
 			snd_card_free(card);
-			pcxhr_free(mgr);
-			return err;
+			goto free_manager;
 		}
 
 		if (i == 0)
@@ -1662,32 +1657,37 @@ static int pcxhr_probe(struct pci_dev *pci,
 			pcxhr_proc_init(mgr->chip[i]);
 
 		err = snd_card_register(card);
-		if (err < 0) {
-			pcxhr_free(mgr);
-			return err;
-		}
+		if (err < 0)
+			goto free_manager;
 	}
 
 	/* create hostport purgebuffer */
 	size = PAGE_ALIGN(sizeof(struct pcxhr_hostport));
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
-				size, &mgr->hostport) < 0) {
-		pcxhr_free(mgr);
-		return -ENOMEM;
-	}
+				size, &mgr->hostport) < 0)
+		goto e_nomem;
+
 	/* init purgebuffer */
 	memset(mgr->hostport.area, 0, size);
 
 	/* create a DSP loader */
 	err = pcxhr_setup_firmware(mgr);
-	if (err < 0) {
-		pcxhr_free(mgr);
-		return err;
-	}
+	if (err < 0)
+		goto free_manager;
 
 	pci_set_drvdata(pci, mgr);
 	dev++;
 	return 0;
+
+disable_device:
+	pci_disable_device(pci);
+	return err;
+
+e_nomem:
+	err = -ENOMEM;
+free_manager:
+	pcxhr_free(mgr);
+	return err;
 }
 
 static void pcxhr_remove(struct pci_dev *pci)
-- 
2.15.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-16 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-16 21:24 [PATCH 0/2] ALSA: pcxhr: Fine-tuning for three function implementations SF Markus Elfring
2017-11-16 21:26 ` [PATCH 1/2] ALSA: pcxhr: Adjust six function calls together with a variable assignment SF Markus Elfring
2017-11-16 21:28 ` [PATCH 2/2] ALSA: pcxhr: Use common error handling code in pcxhr_probe() SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®