Thread (14 messages) flat view 14 messages, 3 authors, 2015-05-06
STALE4113d

[RFC PATCH net-next 3/8] skb: Add skb_push_uchar

From: Joe Perches <joe@perches.com>
Date: 2015-05-04 20:06:10
Subsystem: networking [general], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

skb_push currently returns an unsigned char *.

There are uses like "*skb_push(skb, 1) = <char>" that might be
better represented by a new skb_push_uchar(<char>) function.

This would allow the skb_push function to be converted to
return void and eliminate many casts of the unsigned char *
return to some other type.

Signed-off-by: Joe Perches <joe@perches.com>
---
 include/linux/skbuff.h |  1 +
 net/core/skbuff.c      | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 894071e1..30cd234 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1690,6 +1690,7 @@ static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
 }
 
 unsigned char *skb_push(struct sk_buff *skb, unsigned int len);
+void *skb_push_uchar(struct sk_buff *skb, unsigned char uc);
 static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
 {
 	skb->data -= len;
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 73e20ad..b092d2b 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1455,6 +1455,28 @@ unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
 EXPORT_SYMBOL(skb_push);
 
 /**
+ *	skb_push_uchar - add an unsigned char to the start of a buffer
+ *	@skb: buffer to use
+ *	@uc: unsigned char to add
+ *
+ *	This function extends the used data area of the buffer at the buffer
+ *	start. If this would exceed the total buffer headroom the kernel will
+ *	panic. A pointer to the first byte of the extra data is returned.
+ */
+void *skb_push_uchar(struct sk_buff *skb, unsigned char uc)
+{
+	skb->data--;
+	skb->len++;
+	if (unlikely(skb->data<skb->head))
+		skb_under_panic(skb, 1, __builtin_return_address(0));
+
+	*skb->data = uc;
+
+	return skb->data;
+}
+EXPORT_SYMBOL(skb_push_uchar);
+
+/**
  *	skb_pull - remove data from the start of a buffer
  *	@skb: buffer to use
  *	@len: amount of data to remove
-- 
2.1.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help