Skip to contentSkip to conversation

Simplify lowpan receive path so skb is freed in, lowpan_rcv when dropped.

PATCH In review Martin Townsend 3 participants 10 messages Aug 4, 2014

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

PATCH v3 1/1 Simplify lowpan receive path so skb is freed in, lowpan_rcv when dropped.

---
 include/net/6lowpan.h         |  2 +-
 net/6lowpan/iphc.c            | 29 ++++++++++++++++-------------
 net/bluetooth/6lowpan.c       | 12 ++++++++----
 net/ieee802154/6lowpan_rtnl.c | 12 ++++++------
 4 files changed, 31 insertions(+), 24 deletions(-)
include/net/6lowpan.h +1 -1
index d7e9169..aa0381e 100644
@@ -374,7 +374,7 @@ lowpan_uncompress_size(const struct sk_buff *skb, u16 *dgram_offset)
 
 typedef int (*skb_delivery_cb)(struct sk_buff *skb);
 
-int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
+int lowpan_process_data(struct sk_buff **skb_inout, struct net_device *dev,
 		const u8 *saddr, const u8 saddr_type, const u8 saddr_len,
 		const u8 *daddr, const u8 daddr_type, const u8 daddr_len,
 		u8 iphc0, u8 iphc1, skb_delivery_cb skb_deliver);
net/6lowpan/iphc.c +16 -13
index 92eed6d..18dac0a 100644
@@ -179,11 +179,11 @@ static int skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr,
 
 	new = skb_copy_expand(skb, sizeof(struct ipv6hdr), skb_tailroom(skb),
 			      GFP_ATOMIC);
-	kfree_skb(skb);
-
 	if (!new)
 		return -ENOMEM;
 
+	kfree_skb(skb);
+
 	skb_push(new, sizeof(struct ipv6hdr));
 	skb_reset_network_header(new);
 	skb_copy_to_linear_data(new, hdr, sizeof(struct ipv6hdr));
@@ -196,6 +196,8 @@ static int skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr,
 		       new->data, new->len);
 
 	stat = deliver_skb(new);
+	if (stat < 0)
+		stat = NET_RX_DROP;
 
 	kfree_skb(new);
 
@@ -333,7 +335,7 @@ err:
 /* TTL uncompression values */
 static const u8 lowpan_ttl_values[] = { 0, 1, 64, 255 };
 
-int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
+int lowpan_process_data(struct sk_buff **skb_inout, struct net_device *dev,
 			const u8 *saddr, const u8 saddr_type, const u8 saddr_len,
 			const u8 *daddr, const u8 daddr_type, const u8 daddr_len,
 			u8 iphc0, u8 iphc1, skb_delivery_cb deliver_skb)
@@ -341,6 +343,8 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
 	struct ipv6hdr hdr = {};
 	u8 tmp, num_context = 0;
 	int err;
+	int err_ret = -EINVAL;
+	struct sk_buff *skb = *skb_inout;
 
 	raw_dump_table(__func__, "raw skb data dump uncompressed",
 		       skb->data, skb->len);
@@ -461,7 +465,6 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
 	/* UDP data uncompression */
 	if (iphc0 & LOWPAN_IPHC_NH_C) {
 		struct udphdr uh;
-		struct sk_buff *new;
 
 		if (uncompress_udp_header(skb, &uh))
 			goto drop;
@@ -469,14 +472,15 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
 		/* replace the compressed UDP head by the uncompressed UDP
 		 * header
 		 */
-		new = skb_copy_expand(skb, sizeof(struct udphdr),
+		skb = skb_copy_expand(skb, sizeof(struct udphdr),
 				      skb_tailroom(skb), GFP_ATOMIC);
-		kfree_skb(skb);
-
-		if (!new)
-			return -ENOMEM;
-
-		skb = new;
+		if (!skb) {
+			err_ret = -ENOMEM;
+			goto drop;
+		}
+		
+		kfree_skb(*skb_inout);
+		*skb_inout = skb;
 
 		skb_push(skb, sizeof(struct udphdr));
 		skb_reset_transport_header(skb);
@@ -503,8 +507,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
 	return skb_deliver(skb, &hdr, dev, deliver_skb);
 
 drop:
-	kfree_skb(skb);
-	return -EINVAL;
+	return err_ret;
 }
 EXPORT_SYMBOL_GPL(lowpan_process_data);
 
net/bluetooth/6lowpan.c +8 -4
index f5df93f..38a2987 100644
@@ -215,7 +215,7 @@ static int give_skb_to_upper(struct sk_buff *skb)
 	return ret;
 }
 
-static int process_data(struct sk_buff *skb, struct net_device *netdev,
+static int process_data(struct sk_buff **skb_inout, struct net_device *netdev,
 			struct l2cap_chan *chan)
 {
 	const u8 *saddr, *daddr;
@@ -223,6 +223,7 @@ static int process_data(struct sk_buff *skb, struct net_device *netdev,
 	struct lowpan_dev *dev;
 	struct lowpan_peer *peer;
 	unsigned long flags;
+	struct sk_buff *skb = *skb_inout;
 
 	dev = lowpan_dev(netdev);
 
@@ -245,13 +246,12 @@ static int process_data(struct sk_buff *skb, struct net_device *netdev,
 	if (lowpan_fetch_skb_u8(skb, &iphc1))
 		goto drop;
 
-	return lowpan_process_data(skb, netdev,
+	return lowpan_process_data(skb_inout, netdev,
 				   saddr, IEEE802154_ADDR_LONG, EUI64_ADDR_LEN,
 				   daddr, IEEE802154_ADDR_LONG, EUI64_ADDR_LEN,
 				   iphc0, iphc1, give_skb_to_upper);
 
 drop:
-	kfree_skb(skb);
 	return -EINVAL;
 }
 
@@ -300,7 +300,11 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
 			if (!local_skb)
 				goto drop;
 
-			ret = process_data(local_skb, dev, chan);
+			ret = process_data(&local_skb, dev, chan);
+			if (ret < 0) {
+				kfree_skb(local_skb);
+				goto drop;
+			}
 			if (ret != NET_RX_SUCCESS)
 				goto drop;
 
net/ieee802154/6lowpan_rtnl.c +6 -6
index 3154775..3ae7646 100644
@@ -166,11 +166,12 @@ static int lowpan_give_skb_to_devices(struct sk_buff *skb)
 	return stat;
 }
 
-static int process_data(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
+static int process_data(struct sk_buff **skb_inout, const struct ieee802154_hdr *hdr)
 {
 	u8 iphc0, iphc1;
 	struct ieee802154_addr_sa sa, da;
 	void *sap, *dap;
+	struct sk_buff *skb = *skb_inout;
 
 	raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
 	/* at least two bytes will be used for the encoding */
@@ -196,13 +197,12 @@ static int process_data(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 	else
 		dap = &da.hwaddr;
 
-	return lowpan_process_data(skb, skb->dev, sap, sa.addr_type,
+	return lowpan_process_data(skb_inout, skb->dev, sap, sa.addr_type,
 				   IEEE802154_ADDR_LEN, dap, da.addr_type,
 				   IEEE802154_ADDR_LEN, iphc0, iphc1,
 				   lowpan_give_skb_to_devices);
 
 drop:
-	kfree_skb(skb);
 	return -EINVAL;
 }
 
@@ -485,14 +485,14 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 	} else {
 		switch (skb->data[0] & 0xe0) {
 		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
-			ret = process_data(skb, &hdr);
+			ret = process_data(&skb, &hdr);
 			if (ret == NET_RX_DROP)
 				goto drop;
 			break;
 		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
 			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
 			if (ret == 1) {
-				ret = process_data(skb, &hdr);
+				ret = process_data(&skb, &hdr);
 				if (ret == NET_RX_DROP)
 					goto drop;
 			}
@@ -500,7 +500,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
 			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
 			if (ret == 1) {
-				ret = process_data(skb, &hdr);
+				ret = process_data(&skb, &hdr);
 				if (ret == NET_RX_DROP)
 					goto drop;
 			}
Signature · 1 line
1.9.1
maintainer
#1 lore raw

Hi Martin,

still conflicts here:

M include/net/6lowpan.h
M net/6lowpan/iphc.c
M net/bluetooth/6lowpan.c
M net/ieee802154/6lowpan_rtnl.c
<stdin>:91: trailing whitespace.

warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging net/ieee802154/6lowpan_rtnl.c
Auto-merging net/bluetooth/6lowpan.c
Auto-merging net/6lowpan/iphc.c
CONFLICT (content): Merge conflict in net/6lowpan/iphc.c
Auto-merging include/net/6lowpan.h
Failed to merge in the changes.
Patch failed at 0001 Simplify lowpan receive path so skb is freed in, lowpan_rcv when dropped.

Save your work in a branch.

Do you have bluetooth-next in your remotes? Then run "git remote update $REMOTE_NAME" and checkout $REMOTE_NAME/master, then use git cherry-pick to add patches from the branch.

- Alex

#2 lore raw

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
Quoted 1 line

From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

- Martin.

Quoted 32 lines · Alexander Aring

Hi Martin,

still conflicts here:

M include/net/6lowpan.h
M net/6lowpan/iphc.c
M net/bluetooth/6lowpan.c
M net/ieee802154/6lowpan_rtnl.c
<stdin>:91: trailing whitespace.

warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging net/ieee802154/6lowpan_rtnl.c
Auto-merging net/bluetooth/6lowpan.c
Auto-merging net/6lowpan/iphc.c
CONFLICT (content): Merge conflict in net/6lowpan/iphc.c
Auto-merging include/net/6lowpan.h
Failed to merge in the changes.
Patch failed at 0001 Simplify lowpan receive path so skb is freed in, lowpan_rcv when dropped.

Save your work in a branch.

Do you have bluetooth-next in your remotes? Then run "git remote update $REMOTE_NAME" and checkout $REMOTE_NAME/master, then use git cherry-pick to add patches from the branch.

- Alex
--
To unsubscribe from this list: send the line "unsubscribe linux-wpan" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#3 lore raw
Quoted 5 lines · Martin Townsend

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

- Alex

#4 lore raw

I did a pull first and after the merge my patch is still at the top of the log.

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git pull
Already up-to-date.
martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git log
commit e3964f42db0e58e0ad289b89af0235af0db1f141
Author: Martin Townsend <[email protected]>
Date:   Fri Aug 1 15:59:57 2014 +0100

Simplify lowpan receive path so skb is freed in lowpan_rcv when dropped.

commit 751c8445fff787ad1fdb2a9285e8cf8ef865446d
Merge: 2ab17e7 dc6be9f
Author: Martin Townsend <[email protected]>
Date: Fri Aug 1 15:15:06 2014 +0100

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next

commit 2ab17e768aa38426ec39a66a411b4f533dafa8c1

Author: Martin Townsend <[email protected]>
Date:   Fri Aug 1 10:08:05 2014 +0100

Remove dev parameter from skb_delivery_cb in 6lowpan.

This parameter is never used by any function implementing this callback.

...

I'll check the patch hasn't been mangled by my email client somehow.

- Martin

Quoted 12 lines · Alexander Aring
Quoted 5 lines · Martin Townsend

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

- Alex

maintainer
#5 lore raw
In reply to Alexander Aring

Martin,

Quoted 11 lines · Alexander Aring
Quoted 5 lines · Martin Townsend

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

I think I know now why it fails. This patch depends on your previous patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback."), otherwise I get merge conflicts.

Normally you need to send this in a series of patches to avoid something like this. Now you need to wait until your patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback.") go into the bluetooth-next tree.

Next time, if you have a bunch of patches which depends on each other then send patch series. Sorry.

- Alex

#6 lore raw

Oops, sorry about that.

- Martin

Quoted 32 lines · Alexander Aring

Martin,

Quoted 11 lines · Alexander Aring
Quoted 5 lines · Martin Townsend

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

I think I know now why it fails. This patch depends on your previous patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback."), otherwise I get merge conflicts.

Normally you need to send this in a series of patches to avoid something like this. Now you need to wait until your patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback.") go into the bluetooth-next tree.

Next time, if you have a bunch of patches which depends on each other then send patch series. Sorry.

- Alex
--
To unsubscribe from this list: send the line "unsubscribe linux-wpan" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#7 lore raw
In reply to Alexander Aring
Quoted 15 lines · Alexander Aring

Martin,

Quoted 11 lines · Alexander Aring
Quoted 5 lines · Martin Townsend

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

Quoted 9 lines

I think I know now why it fails. This patch depends on your previous patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback."), otherwise I get merge conflicts.

Normally you need to send this in a series of patches to avoid something like this. Now you need to wait until your patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback.") go into the bluetooth-next tree.

Or write in the patch file under the "---" lines:

"This patch depends on..." if Marcel can deal with this kind of dependency notification.

Otherwise nobody knows what's going on now and want to apply it on bluetooth-next, like me...

btw. lines after "---" will be ignored by appling.

- Alex

maintainer
#8 lore raw

Hi Alex,

Quoted 23 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

Quoted 9 lines

I think I know now why it fails. This patch depends on your previous patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback."), otherwise I get merge conflicts.

Normally you need to send this in a series of patches to avoid something like this. Now you need to wait until your patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback.") go into the bluetooth-next tree.

Or write in the patch file under the "---" lines:

Quoted 8 lines

"This patch depends on..." if Marcel can deal with this kind of dependency notification.

Otherwise nobody knows what's going on now and want to apply it on bluetooth-next, like me...

btw. lines after "---" will be ignored by applying.

so I am fine either way. You can mention this in the section after --- or you just send a patch set that is versioned [PATCH x/y].

Just right now I am delaying applying net/6lowpan/ patches until John, Dave and I have resolved the merge conflicts for getting the current patches into net-next. After that I will start actively applying these patches.

Regards

Marcel

maintainer
#9 lore raw

Hi Marcel,

Quoted 32 lines · Marcel Holtmann

Hi Alex,

Quoted 30 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

The changes were made to a clone of bluetooth-next, do I have the right repository?

martin@martin-HP-ProDesk-490-G1-MT:~/workspace/bluetooth-next$ git ls-remote
From git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git

yes, but maybe it's a little bit outdated. Try to update it, on top of git log should be the patches:

http://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git/log/

Quoted 9 lines

I think I know now why it fails. This patch depends on your previous patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback."), otherwise I get merge conflicts.

Normally you need to send this in a series of patches to avoid something like this. Now you need to wait until your patch ("6lowpan: Remove ununsed dev parameter from skb_delivery_cb callback.") go into the bluetooth-next tree.

Or write in the patch file under the "---" lines:

"This patch depends on..." if Marcel can deal with this kind of dependency notification.

Otherwise nobody knows what's going on now and want to apply it on bluetooth-next, like me...

Quoted 6 lines
Quoted 1 line

btw. lines after "---" will be ignored by applying.

so I am fine either way. You can mention this in the section after --- or you just send a patch set that is versioned [PATCH x/y].

Just right now I am delaying applying net/6lowpan/ patches until John, Dave and I have resolved the merge conflicts for getting the current patches into net-next. After that I will start actively applying these patches.

Thanks for explanation and carry about the merge conflicts. Sorry about that there exists now a huge merge conflicts, but this should never happen if all 802.15.4/6lowpan stuff goes into bluetooth.

- Alex