public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations
@ 2017-08-12 19:10 SF Markus Elfring
  2017-08-12 19:11 ` [PATCH 1/3] ALSA: mpu401: Delete an error message for a failed memory allocation in snd_mpu401_uart_new() SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-12 19:10 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Takashi Iwai, Takashi Sakamoto
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 12 Aug 2017 21:05:21 +0200

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

Markus Elfring (3):
  Delete an error message for a failed memory allocation in snd_mpu401_uart_new()
  Use common error handling code in snd_mpu401_uart_new()
  Adjust four checks for null pointers

 sound/drivers/mpu401/mpu401_uart.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

-- 
2.14.0

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

* [PATCH 1/3] ALSA: mpu401: Delete an error message for a failed memory allocation in snd_mpu401_uart_new()
  2017-08-12 19:10 [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations SF Markus Elfring
@ 2017-08-12 19:11 ` SF Markus Elfring
  2017-08-12 19:12 ` [PATCH 2/3] ALSA: mpu401: Use common error handling code " SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-12 19:11 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Takashi Iwai, Takashi Sakamoto
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 12 Aug 2017 20:20:11 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/drivers/mpu401/mpu401_uart.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index 3a7c317ae012..cc347386fc2b 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -545,7 +545,6 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 		return err;
 	mpu = kzalloc(sizeof(*mpu), GFP_KERNEL);
 	if (mpu == NULL) {
-		snd_printk(KERN_ERR "mpu401_uart: cannot allocate\n");
 		snd_device_free(card, rmidi);
 		return -ENOMEM;
 	}
-- 
2.14.0

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

* [PATCH 2/3] ALSA: mpu401: Use common error handling code in snd_mpu401_uart_new()
  2017-08-12 19:10 [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations SF Markus Elfring
  2017-08-12 19:11 ` [PATCH 1/3] ALSA: mpu401: Delete an error message for a failed memory allocation in snd_mpu401_uart_new() SF Markus Elfring
@ 2017-08-12 19:12 ` SF Markus Elfring
  2017-08-13  1:08   ` Joe Perches
  2017-08-12 19:13 ` [PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers SF Markus Elfring
  2017-08-12 21:36 ` [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations Takashi Iwai
  3 siblings, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-12 19:12 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Takashi Iwai, Takashi Sakamoto
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 12 Aug 2017 20:40:17 +0200

Add a jump target 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/drivers/mpu401/mpu401_uart.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index cc347386fc2b..e8bdea193eab 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -545,8 +545,8 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 		return err;
 	mpu = kzalloc(sizeof(*mpu), GFP_KERNEL);
 	if (mpu == NULL) {
-		snd_device_free(card, rmidi);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto free_device;
 	}
 	rmidi->private_data = mpu;
 	rmidi->private_free = snd_mpu401_uart_free;
@@ -562,8 +562,8 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 			snd_printk(KERN_ERR "mpu401_uart: "
 				   "unable to grab port 0x%lx size %d\n",
 				   port, res_size);
-			snd_device_free(card, rmidi);
-			return -EBUSY;
+			err = -EBUSY;
+			goto free_device;
 		}
 	}
 	if (info_flags & MPU401_INFO_MMIO) {
@@ -583,8 +583,8 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 				"MPU401 UART", (void *) mpu)) {
 			snd_printk(KERN_ERR "mpu401_uart: "
 				   "unable to grab IRQ %d\n", irq);
-			snd_device_free(card, rmidi);
-			return -EBUSY;
+			err = -EBUSY;
+			goto free_device;
 		}
 	}
 	if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK))
@@ -612,6 +612,9 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 	if (rrawmidi)
 		*rrawmidi = rmidi;
 	return 0;
+free_device:
+	snd_device_free(card, rmidi);
+	return err;
 }
 
 EXPORT_SYMBOL(snd_mpu401_uart_new);
-- 
2.14.0

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

* [PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers
  2017-08-12 19:10 [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations SF Markus Elfring
  2017-08-12 19:11 ` [PATCH 1/3] ALSA: mpu401: Delete an error message for a failed memory allocation in snd_mpu401_uart_new() SF Markus Elfring
  2017-08-12 19:12 ` [PATCH 2/3] ALSA: mpu401: Use common error handling code " SF Markus Elfring
@ 2017-08-12 19:13 ` SF Markus Elfring
  2017-08-12 21:36 ` [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations Takashi Iwai
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-08-12 19:13 UTC (permalink / raw)
  To: alsa-devel, Jaroslav Kysela, Takashi Iwai, Takashi Sakamoto
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 12 Aug 2017 20:50:16 +0200
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/mpu401/mpu401_uart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index e8bdea193eab..b997222274bd 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -136,7 +136,7 @@ irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id)
 {
 	struct snd_mpu401 *mpu = dev_id;
 	
-	if (mpu == NULL)
+	if (!mpu)
 		return IRQ_NONE;
 	_snd_mpu401_uart_interrupt(mpu);
 	return IRQ_HANDLED;
@@ -157,7 +157,7 @@ irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id)
 {
 	struct snd_mpu401 *mpu = dev_id;
 	
-	if (mpu == NULL)
+	if (!mpu)
 		return IRQ_NONE;
 	uart_interrupt_tx(mpu);
 	return IRQ_HANDLED;
@@ -544,7 +544,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 				   out_enable, in_enable, &rmidi)) < 0)
 		return err;
 	mpu = kzalloc(sizeof(*mpu), GFP_KERNEL);
-	if (mpu == NULL) {
+	if (!mpu) {
 		err = -ENOMEM;
 		goto free_device;
 	}
@@ -558,7 +558,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
 	if (! (info_flags & MPU401_INFO_INTEGRATED)) {
 		int res_size = hardware == MPU401_HW_PC98II ? 4 : 2;
 		mpu->res = request_region(port, res_size, "MPU401 UART");
-		if (mpu->res == NULL) {
+		if (!mpu->res) {
 			snd_printk(KERN_ERR "mpu401_uart: "
 				   "unable to grab port 0x%lx size %d\n",
 				   port, res_size);
-- 
2.14.0

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

* Re: [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations
  2017-08-12 19:10 [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-08-12 19:13 ` [PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers SF Markus Elfring
@ 2017-08-12 21:36 ` Takashi Iwai
  3 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2017-08-12 21:36 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: alsa-devel, Jaroslav Kysela, Takashi Sakamoto, kernel-janitors,
	LKML

On Sat, 12 Aug 2017 21:10:12 +0200,
SF Markus Elfring wrote:
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 12 Aug 2017 21:05:21 +0200
> 
> A few update suggestions were taken into account
> from static source code analysis.
> 
> Markus Elfring (3):
>   Delete an error message for a failed memory allocation in snd_mpu401_uart_new()
>   Use common error handling code in snd_mpu401_uart_new()
>   Adjust four checks for null pointers

Applied all three patches, thanks.


Takashi

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

* Re: [PATCH 2/3] ALSA: mpu401: Use common error handling code in snd_mpu401_uart_new()
  2017-08-12 19:12 ` [PATCH 2/3] ALSA: mpu401: Use common error handling code " SF Markus Elfring
@ 2017-08-13  1:08   ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2017-08-13  1:08 UTC (permalink / raw)
  To: SF Markus Elfring, alsa-devel, Jaroslav Kysela, Takashi Iwai,
	Takashi Sakamoto
  Cc: LKML, kernel-janitors

On Sat, 2017-08-12 at 21:12 +0200, SF Markus Elfring wrote:
> Add a jump target so that a bit of exception handling can be better
> reused at the end of this function.
[]
> diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
[]
> @@ -612,6 +612,9 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
>  	if (rrawmidi)
>  		*rrawmidi = rmidi;
>  	return 0;
> +free_device:
> +	snd_device_free(card, rmidi);
> +	return err;
>  }
>  
>  EXPORT_SYMBOL(snd_mpu401_uart_new);

It may be more common and better to leave a blank line
between a single line return and a label.

It separates logical points in the function a bit more.

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

end of thread, other threads:[~2017-08-13  1:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-12 19:10 [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations SF Markus Elfring
2017-08-12 19:11 ` [PATCH 1/3] ALSA: mpu401: Delete an error message for a failed memory allocation in snd_mpu401_uart_new() SF Markus Elfring
2017-08-12 19:12 ` [PATCH 2/3] ALSA: mpu401: Use common error handling code " SF Markus Elfring
2017-08-13  1:08   ` Joe Perches
2017-08-12 19:13 ` [PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers SF Markus Elfring
2017-08-12 21:36 ` [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations Takashi Iwai

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