git: de40bc6f3d6b - stable/13 - LinuxKPI: skbuff.h: fix -Warray-bounds warnings

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 26 Jun 2023 12:08:32 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=de40bc6f3d6bf8ab1a4b546630cc847a3b8c5113

commit de40bc6f3d6bf8ab1a4b546630cc847a3b8c5113
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-04-19 21:37:01 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-06-26 09:09:49 +0000

    LinuxKPI: skbuff.h: fix -Warray-bounds warnings
    
    Harmonize sk_buff_head and sk_buff further and fix -Warray-bounds
    warnings reports by gcc.  At the same time simplify some code by
    re-using other functions or factoring some code out.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit b2dcb848688e1e8346762531208dd7d468ff3854)
---
 sys/compat/linuxkpi/common/include/linux/skbuff.h | 61 +++++++++++++----------
 1 file changed, 34 insertions(+), 27 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/skbuff.h b/sys/compat/linuxkpi/common/include/linux/skbuff.h
index 12a6be42e743..fca161537837 100644
--- a/sys/compat/linuxkpi/common/include/linux/skbuff.h
+++ b/sys/compat/linuxkpi/common/include/linux/skbuff.h
@@ -89,8 +89,16 @@ enum sk_buff_pkt_type {
 
 struct sk_buff_head {
 		/* XXX TODO */
-	struct sk_buff		*next;
-	struct sk_buff		*prev;
+	union {
+		struct {
+			struct sk_buff		*next;
+			struct sk_buff		*prev;
+		};
+		struct sk_buff_head_l {
+			struct sk_buff		*next;
+			struct sk_buff		*prev;
+		} list;
+	};
 	size_t			qlen;
 	spinlock_t		lock;
 };
@@ -527,8 +535,8 @@ __skb_insert(struct sk_buff *new, struct sk_buff *prev, struct sk_buff *next,
 	SKB_TRACE_FMT(new, "prev %p next %p q %p", prev, next, q);
 	new->prev = prev;
 	new->next = next;
-	next->prev = new;
-	prev->next = new;
+	((struct sk_buff_head_l *)next)->prev = new;
+	((struct sk_buff_head_l *)prev)->next = new;
 	q->qlen++;
 }
 
@@ -538,7 +546,7 @@ __skb_queue_after(struct sk_buff_head *q, struct sk_buff *skb,
 {
 
 	SKB_TRACE_FMT(q, "skb %p new %p", skb, new);
-	__skb_insert(new, skb, skb->next, q);
+	__skb_insert(new, skb, ((struct sk_buff_head_l *)skb)->next, q);
 }
 
 static inline void
@@ -551,24 +559,18 @@ __skb_queue_before(struct sk_buff_head *q, struct sk_buff *skb,
 }
 
 static inline void
-__skb_queue_tail(struct sk_buff_head *q, struct sk_buff *skb)
+__skb_queue_tail(struct sk_buff_head *q, struct sk_buff *new)
 {
-	struct sk_buff *s;
 
-	SKB_TRACE2(q, skb);
-	q->qlen++;
-	s = (struct sk_buff *)q;
-	s->prev->next = skb;
-	skb->prev = s->prev;
-	skb->next = s;
-	s->prev = skb;
+	SKB_TRACE2(q, new);
+	__skb_queue_after(q, (struct sk_buff *)q, new);
 }
 
 static inline void
-skb_queue_tail(struct sk_buff_head *q, struct sk_buff *skb)
+skb_queue_tail(struct sk_buff_head *q, struct sk_buff *new)
 {
 	SKB_TRACE2(q, skb);
-	return (__skb_queue_tail(q, skb));
+	return (__skb_queue_tail(q, new));
 }
 
 static inline struct sk_buff *
@@ -817,26 +819,31 @@ skb_mark_not_on_list(struct sk_buff *skb)
 	SKB_TODO();
 }
 
+static inline void
+___skb_queue_splice_init(const struct sk_buff_head *from,
+    struct sk_buff *p, struct sk_buff *n)
+{
+	struct sk_buff *b, *e;
+
+	b = from->next;
+	e = from->prev;
+
+	b->prev = p;
+	((struct sk_buff_head_l *)p)->next = b;
+	e->next = n;
+	((struct sk_buff_head_l *)n)->prev = e;
+}
+
 static inline void
 skb_queue_splice_init(struct sk_buff_head *from, struct sk_buff_head *to)
 {
-	struct sk_buff *b, *e, *n;
 
 	SKB_TRACE2(from, to);
 
 	if (skb_queue_empty(from))
 		return;
 
-	/* XXX do we need a barrier around this? */
-	b = from->next;
-	e = from->prev;
-	n = to->next;
-
-	b->prev = (struct sk_buff *)to;
-	to->next = b;
-	e->next = n;
-	n->prev = e;
-
+	___skb_queue_splice_init(from, (struct sk_buff *)to, to->next);
 	to->qlen += from->qlen;
 	__skb_queue_head_init(from);
 }