ALSA: ml403-ac97cr: Fine-tuning for five function implementations
Subsystems (2)
cover ALSA: ml403-ac97cr: Fine-tuning for five function implementations
From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.15.0
PATCH 1/3 ALSA: ml403-ac97cr: Use common error handling code in two functions
From: Markus Elfring <[email protected]>
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.
--- sound/drivers/ml403-ac97cr.c | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
sound/drivers/ml403-ac97cr.c +26 -26
@@ -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)
Signature · 1 line
2.15.0
PATCH 2/3 ALSA: ml403-ac97cr: Delete an unnecessary return statement in snd_ml403_ac97cr_codec_write()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- sound/drivers/ml403-ac97cr.c | 1 - 1 file changed, 1 deletion(-)
sound/drivers/ml403-ac97cr.c +0 -1
@@ -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
Signature · 1 line
2.15.0
PATCH 3/3 ALSA: ml403-ac97cr: Adjust four checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- sound/drivers/ml403-ac97cr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
sound/drivers/ml403-ac97cr.c +4 -4
@@ -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);
Signature · 1 line
2.15.0