Skip to contentSkip to conversation

tty/serial/pch_uart: Adjustments for four function implementations

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

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

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

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 19:03:45 +0100

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

Markus Elfring (4):
Delete an error message for a failed memory allocation in dma_handle_tx() Use kcalloc() in dma_handle_tx()
Delete an unnecessary return statement in two functions Improve a size determination in pch_uart_init_port()

 drivers/tty/serial/pch_uart.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/4 serial: pch_uart: Delete an error message for a failed memory allocation in dma_handle_tx()

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 18:28:20 +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/pch_uart.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tty/serial/pch_uart.c +1 -3
index 760d5dd0aada..0fc72c491c9b 100644
@@ -992,10 +992,8 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv)
 	priv->tx_dma_use = 1;
 
 	priv->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
-	if (!priv->sg_tx_p) {
-		dev_err(priv->port.dev, "%s:kzalloc Failed\n", __func__);
+	if (!priv->sg_tx_p)
 		return 0;
-	}
 
 	sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
 	sg = priv->sg_tx_p;
Signature · 1 line
2.15.1
#2 lore raw

PATCH 2/4 serial: pch_uart: Use kcalloc() in dma_handle_tx()

In reply to SF Markus Elfring

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

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/tty/serial/pch_uart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/pch_uart.c +1 -1
index 0fc72c491c9b..53cdf23b83c6 100644
@@ -991,7 +991,7 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv)
 
 	priv->tx_dma_use = 1;
 
-	priv->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
+	priv->sg_tx_p = kcalloc(num, sizeof(*priv->sg_tx_p), GFP_ATOMIC);
 	if (!priv->sg_tx_p)
 		return 0;
 
Signature · 1 line
2.15.1
#3 lore raw

PATCH 3/4 serial: pch_uart: Delete an unnecessary return statement in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 18:48:10 +0100

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

WARNING: void function return statements are not generally useful

Thus remove such a statement in the affected functions.

---
 drivers/tty/serial/pch_uart.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tty/serial/pch_uart.c +1 -3
index 53cdf23b83c6..790a7aae331f 100644
@@ -693,8 +693,6 @@ static void pch_free_dma(struct uart_port *port)
 		priv->rx_buf_virt = NULL;
 		priv->rx_buf_dma = 0;
 	}
-
-	return;
 }
 
 static bool filter(struct dma_chan *chan, void *slave)
@@ -1861,8 +1859,8 @@ static void pch_uart_pci_remove(struct pci_dev *pdev)
 	pch_uart_exit_port(priv);
 	pci_disable_device(pdev);
 	kfree(priv);
-	return;
 }
+
 #ifdef CONFIG_PM
 static int pch_uart_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
Signature · 1 line
2.15.1
#4 lore raw

PATCH 4/4 serial: pch_uart: Improve a size determination in pch_uart_init_port()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 8 Dec 2017 18:53:21 +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/pch_uart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/pch_uart.c +1 -1
index 790a7aae331f..1c30309ef02c 100644
@@ -1747,7 +1747,7 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
 	board = &drv_dat[id->driver_data];
 	port_type = board->port_type;
 
-	priv = kzalloc(sizeof(struct eg20t_port), GFP_KERNEL);
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (priv = NULL)
 		goto init_port_alloc_err;
 
Signature · 1 line
2.15.1