[PATCH v2 -next] 6LoWPAN: fix skb_copy call

Subsystems: ieee 802.15.4 subsystem, networking [general], the rest

DORMANTno replies

4 messages, 4 authors, 2011-09-01 · open the first message on its own page

[PATCH v2 -next] 6LoWPAN: fix skb_copy call

From: Alexander Smirnov <hidden>
Date: 2011-09-01 12:54:13

This patch fixes 2 issues in lowpan_skb_deliver function:
1. Check for return status of skb_copy call;
2. Use skb_copy with proper GFP flag depending on context.

Signed-off-by: Alexander Smirnov <redacted>
---
 net/ieee802154/6lowpan.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index cf304cc..16100be 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -477,9 +477,15 @@ static int lowpan_skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr)
 	struct sk_buff *new;
 	struct lowpan_dev_record *entry;
 	int stat = NET_RX_SUCCESS;
+	gfp_t mask;
 
-	new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
-								GFP_KERNEL);
+	if (in_interrupt())
+		mask = GFP_ATOMIC;
+	else
+		mask = GFP_KERNEL;
+
+	new = skb_copy_expand(skb, sizeof(struct ipv6hdr),
+					skb_tailroom(skb), mask);
 	kfree_skb(skb);
 
 	if (NULL == new)
@@ -495,7 +501,13 @@ static int lowpan_skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr)
 	rcu_read_lock();
 	list_for_each_entry_rcu(entry, &lowpan_devices, list)
 		if (lowpan_dev_info(entry->ldev)->real_dev == new->dev) {
-			skb = skb_copy(new, GFP_KERNEL);
+			skb = skb_copy(new, mask);
+
+			if (NULL == skb) {
+				stat = -ENOMEM;
+				break;
+			}
+
 			skb->dev = entry->ldev;
 
 			if (in_interrupt())
-- 
1.7.2.5


------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev

Re: [PATCH v2 -next] 6LoWPAN: fix skb_copy call

From: Eric Dumazet <hidden>
Date: 2011-09-01 12:00:44

Le jeudi 01 septembre 2011 à 16:54 +0400, Alexander Smirnov a écrit :
quoted hunk
This patch fixes 2 issues in lowpan_skb_deliver function:
1. Check for return status of skb_copy call;
2. Use skb_copy with proper GFP flag depending on context.

Signed-off-by: Alexander Smirnov <redacted>
---
 net/ieee802154/6lowpan.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index cf304cc..16100be 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -477,9 +477,15 @@ static int lowpan_skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr)
 	struct sk_buff *new;
 	struct lowpan_dev_record *entry;
 	int stat = NET_RX_SUCCESS;
+	gfp_t mask;
 
-	new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
-								GFP_KERNEL);
+	if (in_interrupt())
+		mask = GFP_ATOMIC;
+	else
+		mask = GFP_KERNEL;
I am not sure to understand if lowpan_skb_deliver() can be called in
pure process context. I feel we are in softirq handler or we have
disabled BH, so GFP_ATOMIC is the only choice.

If you are unsure, you could use following helper :

	mask = gfp_any();
quoted hunk
+
+	new = skb_copy_expand(skb, sizeof(struct ipv6hdr),
+					skb_tailroom(skb), mask);
 	kfree_skb(skb);
 

Re: [PATCH v2 -next] 6LoWPAN: fix skb_copy call

From: Daniel Baluta <hidden>
Date: 2011-09-01 12:10:09

quoted hunk
+                       if (NULL == skb) {
+                               stat = -ENOMEM;
+                               break;
+                       }
This can hurt our eyes :). I think the common convention
is to use: "if (skb == NULL) " or simply "if (!skb) "

thanks,
Daniel.

Re: [PATCH v2 -next] 6LoWPAN: fix skb_copy call

From: Alexander Smirnov <hidden>
Date: 2011-09-01 12:35:22

Hi Eric,

hmm, I think you are right.

First 6LoWPAN implementation was developed as a part of MAC layer and
code was based on this layer approach. But now 6lowpan is
MAC-independent, it's just a netif_rx hook and looks like I missed
this moment during migration.

sorry for confusion.

With best regards,
Alexander

2011/9/1 Eric Dumazet [off-list ref]:
Le jeudi 01 septembre 2011 à 16:54 +0400, Alexander Smirnov a écrit :
quoted
This patch fixes 2 issues in lowpan_skb_deliver function:
1. Check for return status of skb_copy call;
2. Use skb_copy with proper GFP flag depending on context.

Signed-off-by: Alexander Smirnov <redacted>
---
 net/ieee802154/6lowpan.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index cf304cc..16100be 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -477,9 +477,15 @@ static int lowpan_skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr)
      struct sk_buff *new;
      struct lowpan_dev_record *entry;
      int stat = NET_RX_SUCCESS;
+     gfp_t mask;

-     new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
-                                                             GFP_KERNEL);
+     if (in_interrupt())
+             mask = GFP_ATOMIC;
+     else
+             mask = GFP_KERNEL;
I am not sure to understand if lowpan_skb_deliver() can be called in
pure process context. I feel we are in softirq handler or we have
disabled BH, so GFP_ATOMIC is the only choice.

If you are unsure, you could use following helper :

       mask = gfp_any();
quoted
+
+     new = skb_copy_expand(skb, sizeof(struct ipv6hdr),
+                                     skb_tailroom(skb), mask);
      kfree_skb(skb);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help