[PATCH 3/3] serial: max3100: Improve unlocking of a mutex in max3100_probe()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux