linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] net/sched/cls_fw: Fine-tuning for seven function implementations
@ 2017-11-08 18:40 SF Markus Elfring
  2017-11-08 18:41 ` [PATCH 1/3] net: sched: cls_fw: Use common error handling code in fw_change() SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-08 18:40 UTC (permalink / raw)
  To: netdev, Cong Wang, David S. Miller, Jamal Hadi Salim, Jiri Pirko
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 8 Nov 2017 19:36:54 +0100

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

Markus Elfring (3):
  Use common error handling code in fw_change()
  Improve two size determinations in fw_change()
  Adjust nine checks for null pointers

 net/sched/cls_fw.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

-- 
2.15.0

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

* [PATCH 1/3] net: sched: cls_fw: Use common error handling code in fw_change()
  2017-11-08 18:40 [PATCH 0/3] net/sched/cls_fw: Fine-tuning for seven function implementations SF Markus Elfring
@ 2017-11-08 18:41 ` SF Markus Elfring
  2017-11-08 18:42 ` [PATCH 2/3] net: sched: cls_fw: Improve two size determinations " SF Markus Elfring
  2017-11-08 18:43 ` [PATCH 3/3] net: sched: cls_fw: Adjust nine checks for null pointers SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-08 18:41 UTC (permalink / raw)
  To: netdev, Cong Wang, David S. Miller, Jamal Hadi Salim, Jiri Pirko
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 8 Nov 2017 19:15:08 +0100

Add a jump target so that a bit of exception handling can be better reused
in an if branch of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/sched/cls_fw.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 5908f56f76da..567db4d2349f 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -281,14 +281,13 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 		fnew->tp = f->tp;
 
 		err = tcf_exts_init(&fnew->exts, TCA_FW_ACT, TCA_FW_POLICE);
-		if (err < 0) {
-			kfree(fnew);
-			return err;
-		}
+		if (err < 0)
+			goto free_filter;
 
 		err = fw_set_parms(net, tp, fnew, tb, tca, base, ovr);
 		if (err < 0) {
 			tcf_exts_destroy(&fnew->exts);
+free_filter:
 			kfree(fnew);
 			return err;
 		}
-- 
2.15.0

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

* [PATCH 2/3] net: sched: cls_fw: Improve two size determinations in fw_change()
  2017-11-08 18:40 [PATCH 0/3] net/sched/cls_fw: Fine-tuning for seven function implementations SF Markus Elfring
  2017-11-08 18:41 ` [PATCH 1/3] net: sched: cls_fw: Use common error handling code in fw_change() SF Markus Elfring
@ 2017-11-08 18:42 ` SF Markus Elfring
  2017-11-08 18:43 ` [PATCH 3/3] net: sched: cls_fw: Adjust nine checks for null pointers SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-08 18:42 UTC (permalink / raw)
  To: netdev, Cong Wang, David S. Miller, Jamal Hadi Salim, Jiri Pirko
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 8 Nov 2017 19:19:10 +0100

Replace the specification of 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.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/sched/cls_fw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 567db4d2349f..53c1c8ae3e00 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -269,7 +269,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 		if (f->id != handle && handle)
 			return -EINVAL;
 
-		fnew = kzalloc(sizeof(struct fw_filter), GFP_KERNEL);
+		fnew = kzalloc(sizeof(*fnew), GFP_KERNEL);
 		if (!fnew)
 			return -ENOBUFS;
 
@@ -323,7 +323,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 		rcu_assign_pointer(tp->root, head);
 	}
 
-	f = kzalloc(sizeof(struct fw_filter), GFP_KERNEL);
+	f = kzalloc(sizeof(*f), GFP_KERNEL);
 	if (f == NULL)
 		return -ENOBUFS;
 
-- 
2.15.0

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

* [PATCH 3/3] net: sched: cls_fw: Adjust nine checks for null pointers
  2017-11-08 18:40 [PATCH 0/3] net/sched/cls_fw: Fine-tuning for seven function implementations SF Markus Elfring
  2017-11-08 18:41 ` [PATCH 1/3] net: sched: cls_fw: Use common error handling code in fw_change() SF Markus Elfring
  2017-11-08 18:42 ` [PATCH 2/3] net: sched: cls_fw: Improve two size determinations " SF Markus Elfring
@ 2017-11-08 18:43 ` SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-11-08 18:43 UTC (permalink / raw)
  To: netdev, Cong Wang, David S. Miller, Jamal Hadi Salim, Jiri Pirko
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 8 Nov 2017 19:26:29 +0100
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/sched/cls_fw.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index 53c1c8ae3e00..2af2627d6f45 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -68,7 +68,7 @@ static int fw_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 	int r;
 	u32 id = skb->mark;
 
-	if (head != NULL) {
+	if (head) {
 		id &= head->mask;
 
 		for (f = rcu_dereference_bh(head->ht[fw_hash(id)]); f;
@@ -106,7 +106,7 @@ static void *fw_get(struct tcf_proto *tp, u32 handle)
 	struct fw_head *head = rtnl_dereference(tp->root);
 	struct fw_filter *f;
 
-	if (head == NULL)
+	if (!head)
 		return NULL;
 
 	f = rtnl_dereference(head->ht[fw_hash(handle)]);
@@ -149,7 +149,7 @@ static void fw_destroy(struct tcf_proto *tp)
 	struct fw_filter *f;
 	int h;
 
-	if (head == NULL)
+	if (!head)
 		return;
 
 	for (h = 0; h < HTSIZE; h++) {
@@ -172,7 +172,7 @@ static int fw_delete(struct tcf_proto *tp, void *arg, bool *last)
 	int ret = -EINVAL;
 	int h;
 
-	if (head == NULL || f == NULL)
+	if (!head || !f)
 		goto out;
 
 	fp = &head->ht[fw_hash(f->id)];
@@ -324,7 +324,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 	}
 
 	f = kzalloc(sizeof(*f), GFP_KERNEL);
-	if (f == NULL)
+	if (!f)
 		return -ENOBUFS;
 
 	err = tcf_exts_init(&f->exts, TCA_FW_ACT, TCA_FW_POLICE);
@@ -354,7 +354,7 @@ static void fw_walk(struct tcf_proto *tp, struct tcf_walker *arg)
 	struct fw_head *head = rtnl_dereference(tp->root);
 	int h;
 
-	if (head == NULL)
+	if (!head)
 		arg->stop = 1;
 
 	if (arg->stop)
@@ -385,7 +385,7 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh,
 	struct fw_filter *f = fh;
 	struct nlattr *nest;
 
-	if (f == NULL)
+	if (!f)
 		return skb->len;
 
 	t->tcm_handle = f->id;
@@ -394,7 +394,7 @@ static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh,
 		return skb->len;
 
 	nest = nla_nest_start(skb, TCA_OPTIONS);
-	if (nest == NULL)
+	if (!nest)
 		goto nla_put_failure;
 
 	if (f->res.classid &&
-- 
2.15.0

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

end of thread, other threads:[~2017-11-08 18:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-08 18:40 [PATCH 0/3] net/sched/cls_fw: Fine-tuning for seven function implementations SF Markus Elfring
2017-11-08 18:41 ` [PATCH 1/3] net: sched: cls_fw: Use common error handling code in fw_change() SF Markus Elfring
2017-11-08 18:42 ` [PATCH 2/3] net: sched: cls_fw: Improve two size determinations " SF Markus Elfring
2017-11-08 18:43 ` [PATCH 3/3] net: sched: cls_fw: Adjust nine checks for null pointers SF Markus Elfring

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).