* [PATCH 0/3] ALSA: es1938: Fine-tuning for seven function implementations
@ 2017-11-14 20:34 SF Markus Elfring
2017-11-14 20:36 ` [PATCH 1/3] ALSA: es1938: Adjust 14 function calls together with a variable assignment SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-14 20:34 UTC (permalink / raw)
To: alsa-devel, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai,
Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 14 Nov 2017 21:30:12 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Adjust 14 function calls together with a variable assignment
Use common error handling code in snd_es1938_probe()
Use common error handling code in snd_es1938_create()
sound/pci/es1938.c | 117 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 67 insertions(+), 50 deletions(-)
--
2.15.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] ALSA: es1938: Adjust 14 function calls together with a variable assignment
2017-11-14 20:34 [PATCH 0/3] ALSA: es1938: Fine-tuning for seven function implementations SF Markus Elfring
@ 2017-11-14 20:36 ` SF Markus Elfring
2017-11-14 20:37 ` [PATCH 2/3] ALSA: es1938: Use common error handling code in snd_es1938_probe() SF Markus Elfring
2017-11-14 20:38 ` [PATCH 3/3] ALSA: es1938: Use common error handling code in snd_es1938_create() SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-14 20:36 UTC (permalink / raw)
To: alsa-devel, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai,
Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 14 Nov 2017 21:00:32 +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/es1938.c | 54 +++++++++++++++++++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 19 deletions(-)
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 9d248eb2e26c..83d652bdef51 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -312,7 +312,8 @@ static void snd_es1938_write_cmd(struct es1938 *chip, unsigned char cmd)
int i;
unsigned char v;
for (i = 0; i < WRITE_LOOP_TIMEOUT; i++) {
- if (!(v = inb(SLSB_REG(chip, READSTATUS)) & 0x80)) {
+ v = inb(SLSB_REG(chip, READSTATUS));
+ if (!(v & 0x80)) {
outb(cmd, SLSB_REG(chip, WRITEDATA));
return;
}
@@ -328,9 +329,13 @@ static int snd_es1938_get_byte(struct es1938 *chip)
{
int i;
unsigned char v;
- for (i = GET_LOOP_TIMEOUT; i; i--)
- if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80)
+
+ for (i = GET_LOOP_TIMEOUT; i; i--) {
+ v = inb(SLSB_REG(chip, STATUS));
+ if (v & 0x80)
return inb(SLSB_REG(chip, READDATA));
+ }
+
dev_err(chip->card->dev, "get_byte timeout: status 0x02%x\n", v);
return -ENODEV;
}
@@ -885,11 +890,10 @@ static int snd_es1938_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params)
{
- int err;
+ int err = snd_pcm_lib_malloc_pages(substream,
+ params_buffer_bytes(hw_params));
- if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
- return err;
- return 0;
+ return (err < 0) ? err : 0;
}
static int snd_es1938_pcm_hw_free(struct snd_pcm_substream *substream)
@@ -1035,9 +1039,9 @@ static const struct snd_pcm_ops snd_es1938_capture_ops = {
static int snd_es1938_new_pcm(struct es1938 *chip, int device)
{
struct snd_pcm *pcm;
- int err;
+ int err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm);
- if ((err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm)) < 0)
+ if (err < 0)
return err;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1938_playback_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1938_capture_ops);
@@ -1594,7 +1598,8 @@ static int snd_es1938_create(struct snd_card *card,
*rchip = NULL;
/* enable PCI device */
- if ((err = pci_enable_device(pci)) < 0)
+ err = pci_enable_device(pci);
+ if (err < 0)
return err;
/* check, if we can restrict PCI DMA transfers to 24 bits */
if (dma_set_mask(&pci->dev, DMA_BIT_MASK(24)) < 0 ||
@@ -1615,7 +1620,8 @@ static int snd_es1938_create(struct snd_card *card,
chip->card = card;
chip->pci = pci;
chip->irq = -1;
- if ((err = pci_request_regions(pci, "ESS Solo-1")) < 0) {
+ err = pci_request_regions(pci, "ESS Solo-1");
+ if (err < 0) {
kfree(chip);
pci_disable_device(pci);
return err;
@@ -1640,7 +1646,8 @@ static int snd_es1938_create(struct snd_card *card,
snd_es1938_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_es1938_free(chip);
return err;
}
@@ -1771,7 +1778,9 @@ static int snd_es1938_mixer(struct es1938 *chip)
kctl->private_free = snd_es1938_hwv_free;
break;
}
- if ((err = snd_ctl_add(card, kctl)) < 0)
+
+ err = snd_ctl_add(card, kctl);
+ if (err < 0)
return err;
}
return 0;
@@ -1805,7 +1814,9 @@ static int snd_es1938_probe(struct pci_dev *pci,
return -ENODEV;
}
}
- if ((err = snd_es1938_create(card, pci, &chip)) < 0) {
+
+ err = snd_es1938_create(card, pci, &chip);
+ if (err < 0) {
snd_card_free(card);
return err;
}
@@ -1818,11 +1829,13 @@ static int snd_es1938_probe(struct pci_dev *pci,
chip->revision,
chip->irq);
- if ((err = snd_es1938_new_pcm(chip, 0)) < 0) {
+ err = snd_es1938_new_pcm(chip, 0);
+ if (err < 0) {
snd_card_free(card);
return err;
}
- if ((err = snd_es1938_mixer(chip)) < 0) {
+ err = snd_es1938_mixer(chip);
+ if (err < 0) {
snd_card_free(card);
return err;
}
@@ -1833,11 +1846,13 @@ static int snd_es1938_probe(struct pci_dev *pci,
dev_err(card->dev, "OPL3 not detected at 0x%lx\n",
SLSB_REG(chip, FMLOWADDR));
} else {
- if ((err = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
+ err = snd_opl3_timer_new(opl3, 0, 1);
+ 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;
}
@@ -1855,7 +1870,8 @@ static int snd_es1938_probe(struct pci_dev *pci,
snd_es1938_create_gameport(chip);
- if ((err = snd_card_register(card)) < 0) {
+ err = snd_card_register(card);
+ if (err < 0) {
snd_card_free(card);
return err;
}
--
2.15.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] ALSA: es1938: Use common error handling code in snd_es1938_probe()
2017-11-14 20:34 [PATCH 0/3] ALSA: es1938: Fine-tuning for seven function implementations SF Markus Elfring
2017-11-14 20:36 ` [PATCH 1/3] ALSA: es1938: Adjust 14 function calls together with a variable assignment SF Markus Elfring
@ 2017-11-14 20:37 ` SF Markus Elfring
2017-11-14 20:38 ` [PATCH 3/3] ALSA: es1938: Use common error handling code in snd_es1938_create() SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-14 20:37 UTC (permalink / raw)
To: alsa-devel, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai,
Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 14 Nov 2017 21:06:05 +0100
Add a jump target 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/es1938.c | 48 ++++++++++++++++++++++--------------------------
1 file changed, 22 insertions(+), 26 deletions(-)
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 83d652bdef51..b19e611345d1 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1810,16 +1810,15 @@ static int snd_es1938_probe(struct pci_dev *pci,
for (idx = 0; idx < 5; idx++) {
if (pci_resource_start(pci, idx) == 0 ||
!(pci_resource_flags(pci, idx) & IORESOURCE_IO)) {
- snd_card_free(card);
- return -ENODEV;
+ err = -ENODEV;
+ goto free_card;
}
}
err = snd_es1938_create(card, pci, &chip);
- if (err < 0) {
- snd_card_free(card);
- return err;
- }
+ if (err < 0)
+ goto free_card;
+
card->private_data = chip;
strcpy(card->driver, "ES1938");
@@ -1830,15 +1829,13 @@ static int snd_es1938_probe(struct pci_dev *pci,
chip->irq);
err = snd_es1938_new_pcm(chip, 0);
- if (err < 0) {
- snd_card_free(card);
- return err;
- }
+ if (err < 0)
+ goto free_card;
+
err = snd_es1938_mixer(chip);
- if (err < 0) {
- snd_card_free(card);
- return err;
- }
+ if (err < 0)
+ goto free_card;
+
if (snd_opl3_create(card,
SLSB_REG(chip, FMLOWADDR),
SLSB_REG(chip, FMHIGHADDR),
@@ -1847,15 +1844,12 @@ static int snd_es1938_probe(struct pci_dev *pci,
SLSB_REG(chip, FMLOWADDR));
} else {
err = snd_opl3_timer_new(opl3, 0, 1);
- 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;
}
if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
chip->mpu_port,
@@ -1871,14 +1865,16 @@ static int snd_es1938_probe(struct pci_dev *pci,
snd_es1938_create_gameport(chip);
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_es1938_remove(struct pci_dev *pci)
--
2.15.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] ALSA: es1938: Use common error handling code in snd_es1938_create()
2017-11-14 20:34 [PATCH 0/3] ALSA: es1938: Fine-tuning for seven function implementations SF Markus Elfring
2017-11-14 20:36 ` [PATCH 1/3] ALSA: es1938: Adjust 14 function calls together with a variable assignment SF Markus Elfring
2017-11-14 20:37 ` [PATCH 2/3] ALSA: es1938: Use common error handling code in snd_es1938_probe() SF Markus Elfring
@ 2017-11-14 20:38 ` SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-14 20:38 UTC (permalink / raw)
To: alsa-devel, Bhumika Goyal, Jaroslav Kysela, Takashi Iwai,
Takashi Sakamoto
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 14 Nov 2017 21:25:55 +0100
Add jump targets so that a bit of exception handling can be better reused
at the end of this function.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/es1938.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index b19e611345d1..2b4dd1297bbc 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1606,14 +1606,14 @@ static int snd_es1938_create(struct snd_card *card,
dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) {
dev_err(card->dev,
"architecture does not support 24bit PCI busmaster DMA\n");
- pci_disable_device(pci);
- return -ENXIO;
+ err = -ENXIO;
+ goto disable_device;
}
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);
spin_lock_init(&chip->mixer_lock);
@@ -1623,8 +1623,7 @@ static int snd_es1938_create(struct snd_card *card,
err = pci_request_regions(pci, "ESS Solo-1");
if (err < 0) {
kfree(chip);
- pci_disable_device(pci);
- return err;
+ goto disable_device;
}
chip->io_port = pci_resource_start(pci, 0);
chip->sb_port = pci_resource_start(pci, 1);
@@ -1634,8 +1633,8 @@ static int snd_es1938_create(struct snd_card *card,
if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED,
KBUILD_MODNAME, chip)) {
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
- snd_es1938_free(chip);
- return -EBUSY;
+ err = -EBUSY;
+ goto free_sound_chip;
}
chip->irq = pci->irq;
dev_dbg(card->dev,
@@ -1647,13 +1646,19 @@ static int snd_es1938_create(struct snd_card *card,
snd_es1938_chip_init(chip);
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
- if (err < 0) {
- snd_es1938_free(chip);
- return err;
- }
+ if (err < 0)
+ goto free_sound_chip;
*rchip = chip;
return 0;
+
+disable_device:
+ pci_disable_device(pci);
+ return err;
+
+free_sound_chip:
+ snd_es1938_free(chip);
+ return err;
}
/* --------------------------------------------------------------------
--
2.15.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-14 20:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-14 20:34 [PATCH 0/3] ALSA: es1938: Fine-tuning for seven function implementations SF Markus Elfring
2017-11-14 20:36 ` [PATCH 1/3] ALSA: es1938: Adjust 14 function calls together with a variable assignment SF Markus Elfring
2017-11-14 20:37 ` [PATCH 2/3] ALSA: es1938: Use common error handling code in snd_es1938_probe() SF Markus Elfring
2017-11-14 20:38 ` [PATCH 3/3] ALSA: es1938: Use common error handling code in snd_es1938_create() 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;
as well as URLs for NNTP newsgroup(s).