Skip to contentSkip to conversation

ATM-ZeitNet: Fine-tuning for three function implementations

PATCH In review SF Markus Elfring 2 participants 6 messages Sep 10, 2016 – Sep 11, 2016

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

cover ATM-ZeitNet: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 10:54:04 +0200

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

Markus Elfring (4):
Use kmalloc_array() in start_tx()
Improve a size determination in zatm_open() Replace one kzalloc() call by kcalloc()
Fix indentation for one DPRINTK() call in start_rx()

 drivers/atm/zatm.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
Signature · 1 line
2.10.0
#1 lore raw

PATCH 1/4 ATM-ZeitNet: Use kmalloc_array() in start_tx()

From: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 09:55:53 +0200

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

This issue was detected by using the Coccinelle software.

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

---
 drivers/atm/zatm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/atm/zatm.c +3 -2
index cecfb94..d378ff2 100644
@@ -998,8 +998,9 @@ static int start_tx(struct atm_dev *dev)
 
 	DPRINTK("start_tx\n");
 	zatm_dev = ZATM_DEV(dev);
-	zatm_dev->tx_map = kmalloc(sizeof(struct atm_vcc *)*
-	    zatm_dev->chans,GFP_KERNEL);
+	zatm_dev->tx_map = kmalloc_array(zatm_dev->chans,
+					 sizeof(*zatm_dev->tx_map),
+					 GFP_KERNEL);
 	if (!zatm_dev->tx_map) return -ENOMEM;
 	zatm_dev->tx_bw = ATM_OC3_PCR;
 	zatm_dev->free_shapers = (1 << NR_SHAPERS)-1;
Signature · 1 line
2.10.0
#2 lore raw

PATCH 2/4 ATM-ZeitNet: Improve a size determination in zatm_open()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 10:07:38 +0200

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.

---
 drivers/atm/zatm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/zatm.c +1 -1
index d378ff2..218c6af 100644
@@ -1399,7 +1399,7 @@ static int zatm_open(struct atm_vcc *vcc)
 	DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n",vcc->dev->number,vcc->vpi,
 	    vcc->vci);
 	if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) {
-		zatm_vcc = kmalloc(sizeof(struct zatm_vcc),GFP_KERNEL);
+		zatm_vcc = kmalloc(sizeof(*zatm_vcc), GFP_KERNEL);
 		if (!zatm_vcc) {
 			clear_bit(ATM_VF_ADDR,&vcc->flags);
 			return -ENOMEM;
Signature · 1 line
2.10.0
#3 lore raw

PATCH 3/4 ATM-ZeitNet: Replace one kzalloc() call by kcalloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 10:21:15 +0200

* The script "checkpatch.pl" can point information out like the following.

WARNING: Prefer kcalloc over kzalloc with multiply

Thus fix the affected source code place.

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

* Delete the local variable "size" which became unnecessary with this refactoring.

---
 drivers/atm/zatm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/atm/zatm.c +4 -3
index 218c6af..2cc9e2a 100644
@@ -598,12 +598,13 @@ static void close_rx(struct atm_vcc *vcc)
 static int start_rx(struct atm_dev *dev)
 {
 	struct zatm_dev *zatm_dev;
-	int size,i;
+	int i;
 
 DPRINTK("start_rx\n");
 	zatm_dev = ZATM_DEV(dev);
-	size = sizeof(struct atm_vcc *)*zatm_dev->chans;
-	zatm_dev->rx_map =  kzalloc(size,GFP_KERNEL);
+	zatm_dev->rx_map = kcalloc(zatm_dev->chans,
+				   sizeof(*zatm_dev->rx_map),
+				   GFP_KERNEL);
 	if (!zatm_dev->rx_map) return -ENOMEM;
 	/* set VPI/VCI split (use all VCIs and give what's left to VPIs) */
 	zpokel(zatm_dev,(1 << dev->ci_range.vci_bits)-1,uPD98401_VRR);
Signature · 1 line
2.10.0
#4 lore raw

PATCH 4/4 ATM-ZeitNet: Fix indentation for one DPRINTK() call in start_rx()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 10:38:04 +0200

Adjust the indentation for a call of the macro "DPRINTK" in this function.

---
 drivers/atm/zatm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/zatm.c +1 -1
index 2cc9e2a..d3dc954 100644
@@ -600,7 +600,7 @@ static int start_rx(struct atm_dev *dev)
 	struct zatm_dev *zatm_dev;
 	int i;
 
-DPRINTK("start_rx\n");
+	DPRINTK("start_rx\n");
 	zatm_dev = ZATM_DEV(dev);
 	zatm_dev->rx_map = kcalloc(zatm_dev->chans,
 				   sizeof(*zatm_dev->rx_map),
Signature · 1 line
2.10.0