Skip to contentSkip to conversation

use stack instead of heap

PATCH In review Alexander Aring 2 participants 4 messages Feb 5, 2013 – Feb 6, 2013 1 message not in the archive

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

cover use stack instead of heap

In 6lowpan and mac802154 implemenation is a allocated temp heap buffer, which can also on the stack.

I hope 100 bytes in 6lowpan are fine.

Alexander Aring (2):
6lowpan: use stack buffer instead of heap
wpan: use stack buffer instead of heap

 net/ieee802154/6lowpan.c | 13 ++++---------
 net/mac802154/wpan.c     |  7 +------
 2 files changed, 5 insertions(+), 15 deletions(-)
Signature · 8 lines
1.8.1.2


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb

A message that is not in the archive (sent off-list or not yet received): 1360095824-12538-1-git-send-email-alex.aring-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/2 6lowpan: use stack buffer instead of heap

head buffer is only temporary available in lowpan_header_create. So it's not necessary to put it on the heap.

Also fixed a comment codestyle issue.

---
 net/ieee802154/6lowpan.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
net/ieee802154/6lowpan.c +4 -9
index f651da6..2bc5e8f 100644
@@ -377,17 +377,14 @@ static int lowpan_header_create(struct sk_buff *skb,
 	struct ipv6hdr *hdr;
 	const u8 *saddr = _saddr;
 	const u8 *daddr = _daddr;
-	u8 *head;
+	u8 head[100];
 	struct ieee802154_addr sa, da;
 
+	/* TODO:
+	 * if this package isn't ipv6 one, where should it be routed?
+	 */
 	if (type != ETH_P_IPV6)
 		return 0;
-		/* TODO:
-		 * if this package isn't ipv6 one, where should it be routed?
-		 */
-	head = kzalloc(100, GFP_KERNEL);
-	if (head == NULL)
-		return -ENOMEM;
 
 	hdr = ipv6_hdr(skb);
 	hc06_ptr = head + 2;
@@ -561,8 +558,6 @@ static int lowpan_header_create(struct sk_buff *skb,
 	skb_pull(skb, sizeof(struct ipv6hdr));
 	memcpy(skb_push(skb, hc06_ptr - head), head, hc06_ptr - head);
 
-	kfree(head);
-
 	lowpan_raw_dump_table(__func__, "raw skb data dump", skb->data,
 				skb->len);
 
Signature · 8 lines
1.8.1.2


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
#3 lore raw

PATCH 2/2 wpan: use stack buffer instead of heap

In reply to a message not in the archive

head buffer is only temporary available in mac802154_header_create. So it's not necessary to put it on the heap.

---
 net/mac802154/wpan.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
net/mac802154/wpan.c +1 -6
index 98c867b..d20c6d3 100644
@@ -137,16 +137,12 @@ static int mac802154_header_create(struct sk_buff *skb,
 	struct ieee802154_addr dev_addr;
 	struct mac802154_sub_if_data *priv = netdev_priv(dev);
 	int pos = 2;
-	u8 *head;
+	u8 head[MAC802154_FRAME_HARD_HEADER_LEN];
 	u16 fc;
 
 	if (!daddr)
 		return -EINVAL;
 
-	head = kzalloc(MAC802154_FRAME_HARD_HEADER_LEN, GFP_KERNEL);
-	if (head == NULL)
-		return -ENOMEM;
-
 	head[pos++] = mac_cb(skb)->seq; /* DSN/BSN */
 	fc = mac_cb_type(skb);
 
@@ -210,7 +206,6 @@ static int mac802154_header_create(struct sk_buff *skb,
 	head[1] = fc >> 8;
 
 	memcpy(skb_push(skb, pos), head, pos);
-	kfree(head);
 
 	return pos;
 }
Signature · 8 lines
1.8.1.2


------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
maintainer
#4 lore raw
In reply to Alexander Aring

From: Alexander Aring <[email protected]>
Date: Tue, 5 Feb 2013 21:23:42 +0100

Quoted 4 lines

In 6lowpan and mac802154 implemenation is a allocated temp heap buffer, which can also on the stack.

I hope 100 bytes in 6lowpan are fine.

Series applied to net-next, thanks.