netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations
@ 2016-09-10  7:15 SF Markus Elfring
  2016-09-10  7:17 ` [PATCH 1/5] ATM-nicstar: Use kmalloc_array() in get_scq() SF Markus Elfring
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: SF Markus Elfring @ 2016-09-10  7:15 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] ATM-nicstar: Use kmalloc_array() in get_scq()
  2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
@ 2016-09-10  7:17 ` SF Markus Elfring
  2016-09-10  7:18 ` [PATCH 2/5] ATM-nicstar: Improve another size determination " SF Markus Elfring
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2016-09-10  7:17 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] ATM-nicstar: Improve another size determination in get_scq()
  2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
  2016-09-10  7:17 ` [PATCH 1/5] ATM-nicstar: Use kmalloc_array() in get_scq() SF Markus Elfring
@ 2016-09-10  7:18 ` SF Markus Elfring
  2016-09-10  7:19 ` [PATCH 3/5] ATM-nicstar: Improve another size determination in ns_init_card() SF Markus Elfring
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2016-09-10  7:18 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] ATM-nicstar: Improve another size determination in ns_init_card()
  2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
  2016-09-10  7:17 ` [PATCH 1/5] ATM-nicstar: Use kmalloc_array() in get_scq() SF Markus Elfring
  2016-09-10  7:18 ` [PATCH 2/5] ATM-nicstar: Improve another size determination " SF Markus Elfring
@ 2016-09-10  7:19 ` SF Markus Elfring
  2016-09-10  7:20 ` [PATCH 4/5] ATM-nicstar: Refactor a kmalloc() call " SF Markus Elfring
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2016-09-10  7:19 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] ATM-nicstar: Refactor a kmalloc() call in ns_init_card()
  2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2016-09-10  7:19 ` [PATCH 3/5] ATM-nicstar: Improve another size determination in ns_init_card() SF Markus Elfring
@ 2016-09-10  7:20 ` SF Markus Elfring
  2016-09-10  7:21 ` [PATCH 5/5] ATM-nicstar: Refactor a dev_alloc_skb() call in dequeue_rx() SF Markus Elfring
  2016-09-11  4:46 ` [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2016-09-10  7:20 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] ATM-nicstar: Refactor a dev_alloc_skb() call in dequeue_rx()
  2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
                   ` (3 preceding siblings ...)
  2016-09-10  7:20 ` [PATCH 4/5] ATM-nicstar: Refactor a kmalloc() call " SF Markus Elfring
@ 2016-09-10  7:21 ` SF Markus Elfring
  2016-09-11  4:46 ` [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2016-09-10  7:21 UTC (permalink / raw)
  To: linux-atm-general, netdev, Chas Williams
  Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations
  2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
                   ` (4 preceding siblings ...)
  2016-09-10  7:21 ` [PATCH 5/5] ATM-nicstar: Refactor a dev_alloc_skb() call in dequeue_rx() SF Markus Elfring
@ 2016-09-11  4:46 ` David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2016-09-11  4:46 UTC (permalink / raw)
  To: elfring
  Cc: linux-atm-general, netdev, 3chas3, linux-kernel, kernel-janitors,
	julia.lawall, pbonzini

From: SF Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 10 Sep 2016 09:15:37 +0200

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 10 Sep 2016 09:10:01 +0200
> 
> A few update suggestions were taken into account
> from static source code analysis.

Series applied.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-11  4:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-10  7:15 [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations SF Markus Elfring
2016-09-10  7:17 ` [PATCH 1/5] ATM-nicstar: Use kmalloc_array() in get_scq() SF Markus Elfring
2016-09-10  7:18 ` [PATCH 2/5] ATM-nicstar: Improve another size determination " SF Markus Elfring
2016-09-10  7:19 ` [PATCH 3/5] ATM-nicstar: Improve another size determination in ns_init_card() SF Markus Elfring
2016-09-10  7:20 ` [PATCH 4/5] ATM-nicstar: Refactor a kmalloc() call " SF Markus Elfring
2016-09-10  7:21 ` [PATCH 5/5] ATM-nicstar: Refactor a dev_alloc_skb() call in dequeue_rx() SF Markus Elfring
2016-09-11  4:46 ` [PATCH 0/5] ATM-nicstar: Fine-tuning for three function implementations David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).