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

[RFC PATCH net-next 1/8] skb: Add skb_put_uchar

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

skb_put currently returns an unsigned char *.

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

This would allow the skb_put 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      | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index acb83e2..894071e1 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1679,6 +1679,7 @@ static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
  */
 unsigned char *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);
 unsigned char *skb_put(struct sk_buff *skb, unsigned int len);
+void *skb_put_uchar(struct sk_buff *skb, unsigned char uc);
 static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
 {
 	unsigned char *tmp = skb_tail_pointer(skb);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 3cfff2a..73e20ad 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1410,6 +1410,32 @@ unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
 EXPORT_SYMBOL(skb_put);
 
 /**
+ *	skb_put_uchar - add an unsigned char to a buffer
+ *	@skb: buffer to use
+ *	@uc: unsigned char to add
+ *
+ *	This function extends the used data area of the buffer. If this would
+ *	exceed the total buffer size the kernel will panic. A pointer to the
+ *	first byte of the extra data is returned.
+ */
+void *skb_put_uchar(struct sk_buff *skb, unsigned char uc)
+{
+	unsigned char *tmp = skb_tail_pointer(skb);
+
+	SKB_LINEAR_ASSERT(skb);
+
+	skb->tail++;
+	skb->len++;
+	if (unlikely(skb->tail > skb->end))
+		skb_over_panic(skb, 1, __builtin_return_address(0));
+
+	*tmp = uc;
+
+	return tmp;
+}
+EXPORT_SYMBOL(skb_put_uchar);
+
+/**
  *	skb_push - add data to the start of a buffer
  *	@skb: buffer to use
  *	@len: amount of data to add
-- 
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