[PATCH 0/4] ATM-ZeitNet: Fine-tuning for three function implementations

STALE3685d

6 messages, 2 authors, 2016-09-11 · open the first message on its own page

[PATCH 0/4] ATM-ZeitNet: Fine-tuning for three function implementations

From: SF Markus Elfring <hidden>
Date: 2016-09-10 08:58:04

From: Markus Elfring <redacted>
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(-)

-- 
2.10.0

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

From: SF Markus Elfring <hidden>
Date: 2016-09-10 09:00:44

From: Markus Elfring <redacted>
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.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/atm/zatm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index cecfb94..d378ff2 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -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;
-- 
2.10.0

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

From: SF Markus Elfring <hidden>
Date: 2016-09-10 09:01:48

From: Markus Elfring <redacted>
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.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/atm/zatm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index d378ff2..218c6af 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -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;
-- 
2.10.0

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

From: SF Markus Elfring <hidden>
Date: 2016-09-10 09:03:09

From: Markus Elfring <redacted>
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.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/atm/zatm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index 218c6af..2cc9e2a 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -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);
-- 
2.10.0

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

From: SF Markus Elfring <hidden>
Date: 2016-09-10 09:04:24

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 10:38:04 +0200

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

Signed-off-by: Markus Elfring <redacted>
---
 drivers/atm/zatm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index 2cc9e2a..d3dc954 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -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),
-- 
2.10.0

Re: [PATCH 0/4] ATM-ZeitNet: Fine-tuning for three function implementations

From: David Miller <davem@davemloft.net>
Date: 2016-09-11 04:46:51

From: SF Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 10:57:37 +0200
A few update suggestions were taken into account
from static source code analysis.
Series applied.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help