linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] tty/serial/max3100: Adjustments for max3100_probe()
@ 2017-12-08 20:10 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
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-12-08 20:10 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 8 Dec 2017 21:05:43 +0100

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

Markus Elfring (3):
  Delete an error message for a failed memory allocation
  Improve a size determination
  Improve unlocking of a mutex

 drivers/tty/serial/max3100.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

-- 
2.15.1

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

* [PATCH 1/3] serial: max3100: Delete an error message for a failed memory allocation in max3100_probe()
  2017-12-08 20:10 [PATCH 0/3] tty/serial/max3100: Adjustments for max3100_probe() SF Markus Elfring
@ 2017-12-08 20:11 ` 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 ` [PATCH 3/3] serial: max3100: Improve unlocking of a mutex " SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-12-08 20:11 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby; +Cc: LKML, kernel-janitors

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

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>
---
 drivers/tty/serial/max3100.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 27d6049eb6a9..b7b7e6582f3f 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -763,8 +763,6 @@ static int max3100_probe(struct spi_device *spi)
 
 	max3100s[i] = kzalloc(sizeof(struct max3100_port), GFP_KERNEL);
 	if (!max3100s[i]) {
-		dev_warn(&spi->dev,
-			 "kmalloc for max3100 structure %d failed!\n", i);
 		mutex_unlock(&max3100s_lock);
 		return -ENOMEM;
 	}
-- 
2.15.1

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

* [PATCH 2/3] serial: max3100: Improve a size determination in max3100_probe()
  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 ` SF Markus Elfring
  2017-12-08 20:13 ` [PATCH 3/3] serial: max3100: Improve unlocking of a mutex " SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-12-08 20:12 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 8 Dec 2017 20:32:09 +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>
---
 drivers/tty/serial/max3100.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index b7b7e6582f3f..00c0e650537d 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -761,7 +761,7 @@ static int max3100_probe(struct spi_device *spi)
 		return -ENOMEM;
 	}
 
-	max3100s[i] = kzalloc(sizeof(struct max3100_port), GFP_KERNEL);
+	max3100s[i] = kzalloc(sizeof(*max3100s[i]), GFP_KERNEL);
 	if (!max3100s[i]) {
 		mutex_unlock(&max3100s_lock);
 		return -ENOMEM;
-- 
2.15.1


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

* [PATCH 3/3] serial: max3100: Improve unlocking of a mutex in max3100_probe()
  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
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-12-08 20:13 UTC (permalink / raw)
  To: linux-serial, Greg Kroah-Hartman, Jiri Slaby; +Cc: LKML, kernel-janitors

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

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/3] serial: max3100: Improve unlocking of a mutex " 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).