Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1710352 > unrolled thread

[PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-08-12 21:20 +0200
Last post2017-08-12 23:40 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/3] ALSA: mpu401: Adjustments for three function  implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-12 21:20 +0200
    [PATCH 2/3] ALSA: mpu401: Use common error handling code in  snd_mpu401_uart_new() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-12 21:20 +0200
      Re: [PATCH 2/3] ALSA: mpu401: Use common error handling code in  snd_mpu401_uart_new() Joe Perches <joe@perches.com> - 2017-08-13 03:10 +0200
    [PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers SF Markus Elfring <elfring@users.sourceforge.net> - 2017-08-12 21:20 +0200
    Re: [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations Takashi Iwai <tiwai@suse.de> - 2017-08-12 23:40 +0200

#1710352 — [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-08-12 21:20 +0200
Subject[PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations
Message-ID<udK6Z-4Y3-5@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1710353 — [PATCH 2/3] ALSA: mpu401: Use common error handling code in snd_mpu401_uart_new()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-08-12 21:20 +0200
Subject[PATCH 2/3] ALSA: mpu401: Use common error handling code in snd_mpu401_uart_new()
Message-ID<udK6Z-4Y3-7@gated-at.bofh.it>
In reply to#1710352
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

[toc] | [prev] | [next] | [standalone]


#1710408 — Re: [PATCH 2/3] ALSA: mpu401: Use common error handling code in snd_mpu401_uart_new()

FromJoe Perches <joe@perches.com>
Date2017-08-13 03:10 +0200
SubjectRe: [PATCH 2/3] ALSA: mpu401: Use common error handling code in snd_mpu401_uart_new()
Message-ID<udPzI-aT-9@gated-at.bofh.it>
In reply to#1710353
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.

[toc] | [prev] | [next] | [standalone]


#1710354 — [PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-08-12 21:20 +0200
Subject[PATCH 3/3] ALSA: mpu401: Adjust four checks for null pointers
Message-ID<udK70-4Y3-9@gated-at.bofh.it>
In reply to#1710352
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

[toc] | [prev] | [next] | [standalone]


#1710379 — Re: [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations

FromTakashi Iwai <tiwai@suse.de>
Date2017-08-12 23:40 +0200
SubjectRe: [PATCH 0/3] ALSA: mpu401: Adjustments for three function implementations
Message-ID<udMiv-6kh-31@gated-at.bofh.it>
In reply to#1710352
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web