[PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations

STALE3688d

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

[PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations

From: SF Markus Elfring <hidden>
Date: 2016-09-10 07:16:12

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 09:10:01 +0200

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

Markus Elfring (5):
  Use kmalloc_array() in get_scq()
  Improve another size determination in get_scq()
  Improve another size determination in ns_init_card()
  Refactor a kmalloc() call in ns_init_card()
  Refactor a dev_alloc_skb() call in dequeue_rx()

 drivers/atm/nicstar.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

-- 
2.10.0

[PATCH 1/5] ATM-nicstar: Use kmalloc_array() in get_scq()

From: SF Markus Elfring <hidden>
Date: 2016-09-10 07:18:23

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 08:02:06 +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/nicstar.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 700ed15..50dec13 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -871,8 +871,9 @@ static scq_info *get_scq(ns_dev *card, int size, u32 scd)
 		kfree(scq);
 		return NULL;
 	}
-	scq->skb = kmalloc(sizeof(struct sk_buff *) *
-			   (size / NS_SCQE_SIZE), GFP_KERNEL);
+	scq->skb = kmalloc_array(size / NS_SCQE_SIZE,
+				 sizeof(*scq->skb),
+				 GFP_KERNEL);
 	if (!scq->skb) {
 		dma_free_coherent(&card->pcidev->dev,
 				  2 * size, scq->org, scq->dma);
-- 
2.10.0

[PATCH 2/5] ATM-nicstar: Improve another size determination in get_scq()

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

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 08:18:10 +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/nicstar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 50dec13..96062e1 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -862,7 +862,7 @@ static scq_info *get_scq(ns_dev *card, int size, u32 scd)
 	if (size != VBR_SCQSIZE && size != CBR_SCQSIZE)
 		return NULL;
 
-	scq = kmalloc(sizeof(scq_info), GFP_KERNEL);
+	scq = kmalloc(sizeof(*scq), GFP_KERNEL);
 	if (!scq)
 		return NULL;
         scq->org = dma_alloc_coherent(&card->pcidev->dev,
-- 
2.10.0

[PATCH 3/5] ATM-nicstar: Improve another size determination in ns_init_card()

From: SF Markus Elfring <hidden>
Date: 2016-09-10 07:19:59

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 08:30:09 +0200

Replace the specification of a data structure by a reference for a field
in a local variable 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/nicstar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 96062e1..ef977bf 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -611,7 +611,7 @@ static int ns_init_card(int i, struct pci_dev *pcidev)
 	for (j = 0; j < card->rct_size; j++)
 		ns_write_sram(card, j * 4, u32d, 4);
 
-	memset(card->vcmap, 0, NS_MAX_RCTSIZE * sizeof(vc_map));
+	memset(card->vcmap, 0, sizeof(card->vcmap));
 
 	for (j = 0; j < NS_FRSCD_NUM; j++)
 		card->scd2vc[j] = NULL;
-- 
2.10.0

[PATCH 4/5] ATM-nicstar: Refactor a kmalloc() call in ns_init_card()

From: SF Markus Elfring <hidden>
Date: 2016-09-10 07:20:40

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 08:48:17 +0200

* The script "checkpatch.pl" can point out that assignments should usually
  not be performed within condition checks.
  Thus move an assignment for a local variable to a separate statement
  in this function.

* 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/nicstar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index ef977bf..04f5781 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -370,7 +370,8 @@ static int ns_init_card(int i, struct pci_dev *pcidev)
 		return error;
         }
 
-	if ((card = kmalloc(sizeof(ns_dev), GFP_KERNEL)) == NULL) {
+	card = kmalloc(sizeof(*card), GFP_KERNEL);
+	if (!card) {
 		printk
 		    ("nicstar%d: can't allocate memory for device structure.\n",
 		     i);
-- 
2.10.0

[PATCH 5/5] ATM-nicstar: Refactor a dev_alloc_skb() call in dequeue_rx()

From: SF Markus Elfring <hidden>
Date: 2016-09-10 07:21:52

From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 08:56:03 +0200

The script "checkpatch.pl" can point out that assignments should usually
not be performed within condition checks.
Thus move an assignment for a local variable to a separate statement
in this function.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/atm/nicstar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 04f5781..c7296b5 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -2023,7 +2023,8 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
 
 		cell = skb->data;
 		for (i = ns_rsqe_cellcount(rsqe); i; i--) {
-			if ((sb = dev_alloc_skb(NS_SMSKBSIZE)) == NULL) {
+			sb = dev_alloc_skb(NS_SMSKBSIZE);
+			if (!sb) {
 				printk
 				    ("nicstar%d: Can't allocate buffers for aal0.\n",
 				     card->index);
-- 
2.10.0

Re: [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations

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

From: SF Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 09:15:37 +0200
From: Markus Elfring <redacted>
Date: Sat, 10 Sep 2016 09:10:01 +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