tty/serial/max3100: Adjustments for max3100_probe()
Subsystems (2)
cover tty/serial/max3100: Adjustments for max3100_probe()
From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.15.1
PATCH 1/3 serial: max3100: Delete an error message for a failed memory allocation in max3100_probe()
From: Markus Elfring <[email protected]>
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.
--- drivers/tty/serial/max3100.c | 2 -- 1 file changed, 2 deletions(-)
drivers/tty/serial/max3100.c +0 -2
@@ -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 ; }
Signature · 1 line
2.15.1
PATCH 2/3 serial: max3100: Improve a size determination in max3100_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- drivers/tty/serial/max3100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/max3100.c +1 -1
@@ -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 ;
Signature · 1 line
2.15.1
PATCH 3/3 serial: max3100: Improve unlocking of a mutex in max3100_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
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.
--- drivers/tty/serial/max3100.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/tty/serial/max3100.c +9 -7
@@ -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)
Signature · 1 line
2.15.1