[alsa-devel] [PATCH 0/3] ALSA: ml403-ac97cr: Fine-tuning for five function implementations
From: Markus Elfring elfring@users.sourceforge.net Date: Sat, 11 Nov 2017 14:13:12 +0100
Three update suggestions were taken into account from static source code analysis.
Markus Elfring (3): Use common error handling code in two functions Delete an unnecessary return statement in snd_ml403_ac97cr_codec_write() Adjust four checks for null pointers
sound/drivers/ml403-ac97cr.c | 61 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 31 deletions(-)
From: Markus Elfring elfring@users.sourceforge.net Date: Sat, 11 Nov 2017 13:50:24 +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/drivers/ml403-ac97cr.c | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c index 18fd12996cf7..12a54bfde1a5 100644 --- a/sound/drivers/ml403-ac97cr.c +++ b/sound/drivers/ml403-ac97cr.c @@ -1144,8 +1144,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev, snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " "unable to remap memory region (%pR)\n", resource); - snd_ml403_ac97cr_free(ml403_ac97cr); - return -EBUSY; + goto e_busy; } snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": " "remap controller memory region to " @@ -1157,8 +1156,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev, snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " "unable to grab IRQ %d\n", irq); - snd_ml403_ac97cr_free(ml403_ac97cr); - return -EBUSY; + goto e_busy; } ml403_ac97cr->irq = irq; snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": " @@ -1170,8 +1168,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev, snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " "unable to grab IRQ %d\n", irq); - snd_ml403_ac97cr_free(ml403_ac97cr); - return -EBUSY; + goto e_busy; } ml403_ac97cr->capture_irq = irq; snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": " @@ -1179,20 +1176,23 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev, ml403_ac97cr->capture_irq);
err = snd_ml403_ac97cr_chip_init(ml403_ac97cr); - if (err < 0) { - snd_ml403_ac97cr_free(ml403_ac97cr); - return err; - } + if (err < 0) + goto free_data;
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ml403_ac97cr, &ops); if (err < 0) { PDEBUG(INIT_FAILURE, "probe(): snd_device_new() failed!\n"); - snd_ml403_ac97cr_free(ml403_ac97cr); - return err; + goto free_data; }
*rml403_ac97cr = ml403_ac97cr; return 0; + +e_busy: + err = -EBUSY; +free_data: + snd_ml403_ac97cr_free(ml403_ac97cr); + return err; }
static void snd_ml403_ac97cr_mixer_free(struct snd_ac97 *ac97) @@ -1281,22 +1281,19 @@ static int snd_ml403_ac97cr_probe(struct platform_device *pfdev) err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr); if (err < 0) { PDEBUG(INIT_FAILURE, "probe(): create failed!\n"); - snd_card_free(card); - return err; + goto free_card; } PDEBUG(INIT_INFO, "probe(): create done\n"); card->private_data = ml403_ac97cr; err = snd_ml403_ac97cr_mixer(ml403_ac97cr); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + PDEBUG(INIT_INFO, "probe(): mixer done\n"); err = snd_ml403_ac97cr_pcm(ml403_ac97cr, 0); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + PDEBUG(INIT_INFO, "probe(): PCM done\n"); strcpy(card->driver, SND_ML403_AC97CR_DRIVER); strcpy(card->shortname, "ML403 AC97 Controller Reference"); @@ -1306,13 +1303,16 @@ static int snd_ml403_ac97cr_probe(struct platform_device *pfdev) ml403_ac97cr->capture_irq, dev + 1);
err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); - return err; - } + if (err < 0) + goto free_card; + platform_set_drvdata(pfdev, card); PDEBUG(INIT_INFO, "probe(): (done)\n"); return 0; + +free_card: + snd_card_free(card); + return err; }
static int snd_ml403_ac97cr_remove(struct platform_device *pfdev)
From: Markus Elfring elfring@users.sourceforge.net Date: Sat, 11 Nov 2017 13:57:14 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: void function return statements are not generally useful
Thus remove such a statement in the affected function.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/drivers/ml403-ac97cr.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c index 12a54bfde1a5..4cf964ea2802 100644 --- a/sound/drivers/ml403-ac97cr.c +++ b/sound/drivers/ml403-ac97cr.c @@ -1060,7 +1060,6 @@ snd_ml403_ac97cr_codec_write(struct snd_ac97 *ac97, unsigned short reg, reg, val, val); #endif mutex_unlock(&ml403_ac97cr->cdc_mutex); - return; }
static int
From: Markus Elfring elfring@users.sourceforge.net Date: Sat, 11 Nov 2017 14:04:04 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/drivers/ml403-ac97cr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c index 4cf964ea2802..d897175a63b2 100644 --- a/sound/drivers/ml403-ac97cr.c +++ b/sound/drivers/ml403-ac97cr.c @@ -533,7 +533,7 @@ snd_ml403_ac97cr_pcm_pointer(struct snd_pcm_substream *substream) if (substream == ml403_ac97cr->capture_substream) ind2_rec = &ml403_ac97cr->capture_ind2_rec;
- if (ind2_rec != NULL) + if (ind2_rec) return snd_pcm_indirect2_pointer(substream, ind2_rec); return (snd_pcm_uframes_t) 0; } @@ -788,7 +788,7 @@ static irqreturn_t snd_ml403_ac97cr_irq(int irq, void *dev_id) int cmp_irq;
ml403_ac97cr = (struct snd_ml403_ac97cr *)dev_id; - if (ml403_ac97cr == NULL) + if (!ml403_ac97cr) return IRQ_NONE;
pfdev = ml403_ac97cr->pfdev; @@ -1120,7 +1120,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
*rml403_ac97cr = NULL; ml403_ac97cr = kzalloc(sizeof(*ml403_ac97cr), GFP_KERNEL); - if (ml403_ac97cr == NULL) + if (!ml403_ac97cr) return -ENOMEM; spin_lock_init(&ml403_ac97cr->reg_lock); mutex_init(&ml403_ac97cr->cdc_mutex); @@ -1139,7 +1139,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev, ml403_ac97cr->port = ioremap_nocache(resource->start, (resource->end) - (resource->start) + 1); - if (ml403_ac97cr->port == NULL) { + if (!ml403_ac97cr->port) { snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " "unable to remap memory region (%pR)\n", resource);
participants (1)
-
SF Markus Elfring