linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-serial@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 3/3] serial: max3100: Improve unlocking of a mutex in max3100_probe()
Date: Fri, 8 Dec 2017 21:13:43 +0100	[thread overview]
Message-ID: <c8e2234e-5b34-79bf-cb71-f9821ea0eefe@users.sourceforge.net> (raw)
In-Reply-To: <82c37f92-b4ee-8bea-bd10-de3b6691151d@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 8 Dec 2017 20:52:37 +0100

* Add a jump target so that a call of the function "mutex_unlock" is stored
  only once in this function implementation.

* Replace three calls by goto statements.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/tty/serial/max3100.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 00c0e650537d..e4908410565c 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -747,8 +747,7 @@ static int max3100_probe(struct spi_device *spi)
 		retval = uart_register_driver(&max3100_uart_driver);
 		if (retval) {
 			printk(KERN_ERR "Couldn't register max3100 uart driver\n");
-			mutex_unlock(&max3100s_lock);
-			return retval;
+			goto unlock;
 		}
 	}
 
@@ -757,14 +756,14 @@ static int max3100_probe(struct spi_device *spi)
 			break;
 	if (i == MAX_MAX3100) {
 		dev_warn(&spi->dev, "too many MAX3100 chips\n");
-		mutex_unlock(&max3100s_lock);
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto unlock;
 	}
 
 	max3100s[i] = kzalloc(sizeof(*max3100s[i]), GFP_KERNEL);
 	if (!max3100s[i]) {
-		mutex_unlock(&max3100s_lock);
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto unlock;
 	}
 	max3100s[i]->spi = spi;
 	max3100s[i]->irq = spi->irq;
@@ -803,8 +802,11 @@ static int max3100_probe(struct spi_device *spi)
 		tx = MAX3100_WC | MAX3100_SHDN;
 		max3100_sr(max3100s[i], tx, &rx);
 	}
+
+	retval = 0;
+unlock:
 	mutex_unlock(&max3100s_lock);
-	return 0;
+	return retval;
 }
 
 static int max3100_remove(struct spi_device *spi)
-- 
2.15.1

      parent reply	other threads:[~2017-12-08 20:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 20:10 [PATCH 0/3] tty/serial/max3100: Adjustments for max3100_probe() SF Markus Elfring
2017-12-08 20:11 ` [PATCH 1/3] serial: max3100: Delete an error message for a failed memory allocation in max3100_probe() SF Markus Elfring
2017-12-08 20:12 ` [PATCH 2/3] serial: max3100: Improve a size determination " SF Markus Elfring
2017-12-08 20:13 ` SF Markus Elfring [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c8e2234e-5b34-79bf-cb71-f9821ea0eefe@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).