linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] ALSA: sgio2audio: Fine-tuning for two function implementations
@ 2017-11-11 19:20 SF Markus Elfring
  2017-11-11 19:21 ` [PATCH 1/3] ALSA: sgio2audio: Use common error handling code in two functions SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-11-11 19:20 UTC (permalink / raw)
  To: alsa-devel, Arvind Yadav, Bhumika Goyal, Jaroslav Kysela,
	Mark Brown, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 20:16:32 +0100

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

Markus Elfring (3):
  Use common error handling code in two functions
  Improve a size determination in snd_sgio2audio_create()
  Adjust two null pointer checks in snd_sgio2audio_create()

 sound/mips/sgio2audio.c | 53 ++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

-- 
2.15.0

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

* [PATCH 1/3] ALSA: sgio2audio: Use common error handling code in two functions
  2017-11-11 19:20 [PATCH 0/3] ALSA: sgio2audio: Fine-tuning for two function implementations SF Markus Elfring
@ 2017-11-11 19:21 ` SF Markus Elfring
  2017-11-11 19:22 ` [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create() SF Markus Elfring
  2017-11-11 19:23 ` [PATCH 3/3] ALSA: sgio2audio: Adjust two null pointer checks " SF Markus Elfring
  2 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-11-11 19:21 UTC (permalink / raw)
  To: alsa-devel, Arvind Yadav, Bhumika Goyal, Jaroslav Kysela,
	Mark Brown, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 19:56:07 +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/mips/sgio2audio.c | 47 +++++++++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index 71c942162c25..62715a01f507 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -893,18 +893,19 @@ static int snd_sgio2audio_create(struct snd_card *card,
 
 	/* initialize the AD1843 codec */
 	err = ad1843_init(&chip->ad1843);
-	if (err < 0) {
-		snd_sgio2audio_free(chip);
-		return err;
-	}
+	if (err < 0)
+		goto free_chip;
 
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
-	if (err < 0) {
-		snd_sgio2audio_free(chip);
-		return err;
-	}
+	if (err < 0)
+		goto free_chip;
+
 	*rchip = chip;
 	return 0;
+
+free_chip:
+	snd_sgio2audio_free(chip);
+	return err;
 }
 
 static int snd_sgio2audio_probe(struct platform_device *pdev)
@@ -918,21 +919,16 @@ static int snd_sgio2audio_probe(struct platform_device *pdev)
 		return err;
 
 	err = snd_sgio2audio_create(card, &chip);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	err = snd_sgio2audio_new_pcm(chip);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	err = snd_sgio2audio_new_mixer(chip);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
 
 	strcpy(card->driver, "SGI O2 Audio");
 	strcpy(card->shortname, "SGI O2 Audio");
@@ -942,12 +938,15 @@ static int snd_sgio2audio_probe(struct platform_device *pdev)
 		MACEISA_AUDIO3_MERR_IRQ);
 
 	err = snd_card_register(card);
-	if (err < 0) {
-		snd_card_free(card);
-		return err;
-	}
+	if (err < 0)
+		goto free_card;
+
 	platform_set_drvdata(pdev, card);
 	return 0;
+
+free_card:
+	snd_card_free(card);
+	return err;
 }
 
 static int snd_sgio2audio_remove(struct platform_device *pdev)
-- 
2.15.0

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

* [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create()
  2017-11-11 19:20 [PATCH 0/3] ALSA: sgio2audio: Fine-tuning for two function implementations SF Markus Elfring
  2017-11-11 19:21 ` [PATCH 1/3] ALSA: sgio2audio: Use common error handling code in two functions SF Markus Elfring
@ 2017-11-11 19:22 ` SF Markus Elfring
  2017-11-28  6:50   ` Takashi Iwai
  2017-11-11 19:23 ` [PATCH 3/3] ALSA: sgio2audio: Adjust two null pointer checks " SF Markus Elfring
  2 siblings, 1 reply; 5+ messages in thread
From: SF Markus Elfring @ 2017-11-11 19:22 UTC (permalink / raw)
  To: alsa-devel, Arvind Yadav, Bhumika Goyal, Jaroslav Kysela,
	Mark Brown, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 20:02:07 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/mips/sgio2audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index 62715a01f507..9e175a184b66 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -840,7 +840,7 @@ static int snd_sgio2audio_create(struct snd_card *card,
 	if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
 		return -ENOENT;
 
-	chip = kzalloc(sizeof(struct snd_sgio2audio), GFP_KERNEL);
+	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
 	if (chip == NULL)
 		return -ENOMEM;
 
-- 
2.15.0

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

* [PATCH 3/3] ALSA: sgio2audio: Adjust two null pointer checks in snd_sgio2audio_create()
  2017-11-11 19:20 [PATCH 0/3] ALSA: sgio2audio: Fine-tuning for two function implementations SF Markus Elfring
  2017-11-11 19:21 ` [PATCH 1/3] ALSA: sgio2audio: Use common error handling code in two functions SF Markus Elfring
  2017-11-11 19:22 ` [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create() SF Markus Elfring
@ 2017-11-11 19:23 ` SF Markus Elfring
  2 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-11-11 19:23 UTC (permalink / raw)
  To: alsa-devel, Arvind Yadav, Bhumika Goyal, Jaroslav Kysela,
	Mark Brown, Takashi Iwai
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 20:10:22 +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/mips/sgio2audio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index 9e175a184b66..4027f0fc8db6 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -841,14 +841,14 @@ static int snd_sgio2audio_create(struct snd_card *card,
 		return -ENOENT;
 
 	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
-	if (chip == NULL)
+	if (!chip)
 		return -ENOMEM;
 
 	chip->card = card;
 
 	chip->ring_base = dma_alloc_coherent(NULL, MACEISA_RINGBUFFERS_SIZE,
 					     &chip->ring_base_dma, GFP_USER);
-	if (chip->ring_base == NULL) {
+	if (!chip->ring_base) {
 		printk(KERN_ERR
 		       "sgio2audio: could not allocate ring buffers\n");
 		kfree(chip);
-- 
2.15.0

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

* Re: [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create()
  2017-11-11 19:22 ` [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create() SF Markus Elfring
@ 2017-11-28  6:50   ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2017-11-28  6:50 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: alsa-devel, Arvind Yadav, Bhumika Goyal, Mark Brown,
	Jaroslav Kysela, kernel-janitors, LKML

On Sat, 11 Nov 2017 20:22:36 +0100,
SF Markus Elfring wrote:
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 11 Nov 2017 20:02:07 +0100
> 
> Replace the specification of a data structure by a pointer dereference
> as the parameter for the operator "sizeof" to make the corresponding size
> determination a bit safer according to the Linux coding style convention.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Applied, thanks.


Takashi

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

end of thread, other threads:[~2017-11-28  6:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-11 19:20 [PATCH 0/3] ALSA: sgio2audio: Fine-tuning for two function implementations SF Markus Elfring
2017-11-11 19:21 ` [PATCH 1/3] ALSA: sgio2audio: Use common error handling code in two functions SF Markus Elfring
2017-11-11 19:22 ` [PATCH 2/3] ALSA: sgio2audio: Improve a size determination in snd_sgio2audio_create() SF Markus Elfring
2017-11-28  6:50   ` Takashi Iwai
2017-11-11 19:23 ` [PATCH 3/3] ALSA: sgio2audio: Adjust two null pointer checks " 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).