Skip to contentSkip to conversation

ATM-nicstar: Fine-tuning for three function implementations

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

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

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

From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.10.0
#1 lore raw

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

From: Markus Elfring <[email protected]>
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.

---
 drivers/atm/nicstar.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/atm/nicstar.c +3 -2
index 700ed15..50dec13 100644
@@ -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);
Signature · 1 line
2.10.0
#2 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/atm/nicstar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/nicstar.c +1 -1
index 50dec13..96062e1 100644
@@ -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,
Signature · 1 line
2.10.0
#3 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/atm/nicstar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/nicstar.c +1 -1
index 96062e1..ef977bf 100644
@@ -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;
Signature · 1 line
2.10.0
#4 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/atm/nicstar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/atm/nicstar.c +2 -1
index ef977bf..04f5781 100644
@@ -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);
Signature · 1 line
2.10.0
#5 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 drivers/atm/nicstar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/atm/nicstar.c +2 -1
index 04f5781..c7296b5 100644
@@ -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);
Signature · 1 line
2.10.0