Skip to contentSkip to conversation

net-pktgen: Adjustments for some function implementations

PATCH New SF Markus Elfring 1 participant 4 messages May 22, 2017

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

cover net-pktgen: Adjustments for some function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 11:01:23 +0200

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

Markus Elfring (3):
Improve four size determinations
Delete an error message for a failed memory allocation in pktgen_create_thread() Adjust five checks for null pointers

 net/core/pktgen.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
Signature · 1 line
2.13.0
#1 lore raw

PATCH 1/3 net: pktgen: Improve four size determinations

From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 10:34:11 +0200

Replace the specification of four data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 net/core/pktgen.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
net/core/pktgen.c +4 -5
index 96947f5d41e4..c89f4ad21187 100644
@@ -2995,10 +2995,10 @@ static struct sk_buff *fill_packet_ipv6(struct net_device *odev,
 
 	skb_reset_mac_header(skb);
 	skb_set_network_header(skb, skb->len);
-	iph = (struct ipv6hdr *) skb_put(skb, sizeof(struct ipv6hdr));
+	iph = (struct ipv6hdr *)skb_put(skb, sizeof(*iph));
 
 	skb_set_transport_header(skb, skb->len);
-	udph = (struct udphdr *) skb_put(skb, sizeof(struct udphdr));
+	udph = (struct udphdr *)skb_put(skb, sizeof(*udph));
 	skb_set_queue_mapping(skb, queue_map);
 	skb->priority = pkt_dev->skb_priority;
 
@@ -3678,5 +3678,5 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 		return -EBUSY;
 	}
 
-	pkt_dev = kzalloc_node(sizeof(struct pktgen_dev), GFP_KERNEL, node);
+	pkt_dev = kzalloc_node(sizeof(*pkt_dev), GFP_KERNEL, node);
 	if (!pkt_dev)
@@ -3756,6 +3756,5 @@ static int __net_init pktgen_create_thread(int cpu, struct pktgen_net *pn)
 	struct proc_dir_entry *pe;
 	struct task_struct *p;
 
-	t = kzalloc_node(sizeof(struct pktgen_thread), GFP_KERNEL,
-			 cpu_to_node(cpu));
+	t = kzalloc_node(sizeof(*t), GFP_KERNEL, cpu_to_node(cpu));
 	if (!t) {
Signature · 1 line
2.13.0
#2 lore raw

PATCH 2/3 net: pktgen: Delete an error message for a failed memory allocation in pktgen_create_thread()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 10:38:46 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 net/core/pktgen.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/pktgen.c +1 -3
index c89f4ad21187..51008ddc7af6 100644
@@ -3760,7 +3760,5 @@ static int __net_init pktgen_create_thread(int cpu, struct pktgen_net *pn)
-	if (!t) {
-		pr_err("ERROR: out of memory, can't create new thread\n");
+	if (!t)
 		return -ENOMEM;
-	}
 
 	mutex_init(&t->if_lock);
 	t->cpu = cpu;
Signature · 1 line
2.13.0
#3 lore raw

PATCH 3/3 net: pktgen: Adjust five checks for null pointers

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 22 May 2017 10:44:16 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

---
 net/core/pktgen.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/core/pktgen.c +5 -5
index 51008ddc7af6..a28350c9ac67 100644
@@ -1986,7 +1986,7 @@ static void pktgen_mark_device(const struct pktgen_net *pn, const char *ifname)
 	while (1) {
 
 		pkt_dev = __pktgen_NN_threads(pn, ifname, REMOVE);
-		if (pkt_dev = NULL)
+		if (!pkt_dev)
 			break;	/* success */
 
 		mutex_unlock(&pktgen_thread_lock);
@@ -3274,7 +3274,7 @@ static struct pktgen_dev *next_to_run(struct pktgen_thread *t)
 	list_for_each_entry_rcu(pkt_dev, &t->if_list, list) {
 		if (!pkt_dev->running)
 			continue;
-		if (best = NULL)
+		if (!best)
 			best = pkt_dev;
 		else if (ktime_compare(pkt_dev->next_tx, best->next_tx) < 0)
 			best = pkt_dev;
@@ -3402,7 +3402,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
 		kfree_skb(pkt_dev->skb);
 
 		pkt_dev->skb = fill_packet(odev, pkt_dev);
-		if (pkt_dev->skb = NULL) {
+		if (!pkt_dev->skb) {
 			pr_err("ERROR: couldn't allocate skb in fill_packet\n");
 			schedule();
 			pkt_dev->clone_count--;	/* back out increment, OOM */
@@ -3685,7 +3685,7 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
 	strcpy(pkt_dev->odevname, ifname);
 	pkt_dev->flows = vzalloc_node(MAX_CFLOWS * sizeof(struct flow_state),
 				      node);
-	if (pkt_dev->flows = NULL) {
+	if (!pkt_dev->flows) {
 		kfree(pkt_dev);
 		return -ENOMEM;
 	}
@@ -3868,7 +3868,7 @@ static int __net_init pg_net_init(struct net *net)
 		return -ENODEV;
 	}
 	pe = proc_create(PGCTRL, 0600, pn->proc_dir, &pktgen_fops);
-	if (pe = NULL) {
+	if (!pe) {
 		pr_err("cannot create %s procfs entry\n", PGCTRL);
 		ret = -EINVAL;
 		goto remove;
Signature · 1 line
2.13.0