Skip to contentSkip to conversation

tty/serial/ioc4: Adjustments for four function implementations

PATCH New SF Markus Elfring 1 participant 4 messages Dec 8, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover tty/serial/ioc4: Adjustments for four function implementations

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 22:47:43 +0100

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

Markus Elfring (3):
Delete error messages for a failed memory allocation in two functions Improve four size determinations
Adjust three function calls together with a variable assignment

 drivers/tty/serial/ioc4_serial.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/3 serial: ioc4: Delete error messages for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 22:15:53 +0100

Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

---
 drivers/tty/serial/ioc4_serial.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/tty/serial/ioc4_serial.c +2 -9
index db5b979e5a0c..9524a6d3e1d8 100644
@@ -1076,11 +1076,9 @@ static inline int ioc4_attach_local(struct ioc4_driver_data *idd)
 	for (port_number = 0; port_number < IOC4_NUM_SERIAL_PORTS;
 							port_number++) {
 		port = kzalloc(sizeof(struct ioc4_port), GFP_KERNEL);
-		if (!port) {
-			printk(KERN_WARNING
-				"IOC4 serial memory not available for port\n");
+		if (!port)
 			goto free;
-		}
+
 		spin_lock_init(&port->ip_lock);
 
 		/* we need to remember the previous ones, to point back to
@@ -2815,8 +2813,6 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
 	control = kzalloc(sizeof(struct ioc4_control), GFP_KERNEL);
 
 	if (!control) {
-		printk(KERN_WARNING "ioc4_attach_one"
-		       ": unable to get memory for the IOC4\n");
 		ret = -ENOMEM;
 		goto out2;
 	}
@@ -2825,9 +2821,6 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
 	/* Allocate the soft structure */
 	soft = kzalloc(sizeof(struct ioc4_soft), GFP_KERNEL);
 	if (!soft) {
-		printk(KERN_WARNING
-		       "ioc4 (%p): unable to get memory for the soft struct\n",
-		       (void *)idd->idd_pdev);
 		ret = -ENOMEM;
 		goto out3;
 	}
Signature · 1 line
2.15.1
#2 lore raw

PATCH 2/3 serial: ioc4: Improve four size determinations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 22:22:25 +0100

Replace the specification of data structures by pointer dereferences 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/ioc4_serial.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/tty/serial/ioc4_serial.c +4 -5
index 9524a6d3e1d8..6981ad2ca1b7 100644
@@ -1075,7 +1075,7 @@ static inline int ioc4_attach_local(struct ioc4_driver_data *idd)
 	/* Create port structures for each port */
 	for (port_number = 0; port_number < IOC4_NUM_SERIAL_PORTS;
 							port_number++) {
-		port = kzalloc(sizeof(struct ioc4_port), GFP_KERNEL);
+		port = kzalloc(sizeof(*port), GFP_KERNEL);
 		if (!port)
 			goto free;
 
@@ -2797,7 +2797,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
 		ret = -ENODEV;
 		goto out1;
 	}
-	serial = ioremap(tmp_addr1, sizeof(struct ioc4_serial));
+	serial = ioremap(tmp_addr1, sizeof(*serial));
 	if (!serial) {
 		printk(KERN_WARNING
 			 "ioc4 (%p) : unable to remap ioc4 serial register\n",
@@ -2810,8 +2810,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
 				(void *)serial));
 
 	/* Get memory for the new card */
-	control = kzalloc(sizeof(struct ioc4_control), GFP_KERNEL);
-
+	control = kzalloc(sizeof(*control), GFP_KERNEL);
 	if (!control) {
 		ret = -ENOMEM;
 		goto out2;
@@ -2819,7 +2818,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
 	idd->idd_serial_data = control;
 
 	/* Allocate the soft structure */
-	soft = kzalloc(sizeof(struct ioc4_soft), GFP_KERNEL);
+	soft = kzalloc(sizeof(*soft), GFP_KERNEL);
 	if (!soft) {
 		ret = -ENOMEM;
 		goto out3;
Signature · 1 line
2.15.1
#3 lore raw

PATCH 3/3 serial: ioc4: Adjust three function calls together with a variable assignment

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 22:40:31 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

---
 drivers/tty/serial/ioc4_serial.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/tty/serial/ioc4_serial.c +8 -5
index 6981ad2ca1b7..ba95a4cb8130 100644
@@ -1945,7 +1945,8 @@ static void handle_intr(void *arg, uint32_t sio_ir)
 			 * hasn't been delivered to the cpu yet anyway, even
 			 * though we see it as asserted when we read the sio_ir.
 			 */
-			if ((sio_ir = PENDING(port)) & hooks->intr_rx_high) {
+			sio_ir = PENDING(port);
+			if (sio_ir & hooks->intr_rx_high) {
 				if ((port->ip_flags & READ_ABORTED) = 0) {
 					port->ip_ienb &= ~hooks->intr_rx_high;
 					port->ip_flags |= INPUT_HIGH;
@@ -2902,16 +2903,18 @@ static struct ioc4_submodule ioc4_serial_submodule = {
  */
 static int __init ioc4_serial_init(void)
 {
-	int ret;
-
 	/* register with serial core */
-	if ((ret = uart_register_driver(&ioc4_uart_rs232)) < 0) {
+	int ret = uart_register_driver(&ioc4_uart_rs232);
+
+	if (ret < 0) {
 		printk(KERN_WARNING
 			"%s: Couldn't register rs232 IOC4 serial driver\n",
 			__func__);
 		goto out;
 	}
-	if ((ret = uart_register_driver(&ioc4_uart_rs422)) < 0) {
+
+	ret = uart_register_driver(&ioc4_uart_rs422);
+	if (ret < 0) {
 		printk(KERN_WARNING
 			"%s: Couldn't register rs422 IOC4 serial driver\n",
 			__func__);
Signature · 1 line
2.15.1