Skip to content

Commit dcfea72

Browse files
zx2c4davem330
authored andcommitted
net: introduce skb_list_walk_safe for skb segment walking
As part of the continual effort to remove direct usage of skb->next and skb->prev, this patch adds a helper for iterating through the singly-linked variant of skb lists, which are used for lists of GSO packet. The name "skb_list_..." has been chosen to match the existing function, "kfree_skb_list, which also operates on these singly-linked lists, and the "..._walk_safe" part is the same idiom as elsewhere in the kernel. This patch removes the helper from wireguard and puts it into linux/skbuff.h, while making it a bit more robust for general usage. In particular, parenthesis are added around the macro argument usage, and it now accounts for trying to iterate through an already-null skb pointer, which will simply run the iteration zero times. This latter enhancement means it can be used to replace both do { ... } while and while (...) open-coded idioms. This should take care of these three possible usages, which match all current methods of iterations. skb_list_walk_safe(segs, skb, next) { ... } skb_list_walk_safe(skb, skb, next) { ... } skb_list_walk_safe(segs, skb, segs) { ... } Gcc appears to generate efficient code for each of these. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 542d306 commit dcfea72

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

‎drivers/net/wireguard/device.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,4 @@ struct wg_device {
6262
int wg_device_init(void);
6363
void wg_device_uninit(void);
6464

65-
/* Later after the dust settles, this can be moved into include/linux/skbuff.h,
66-
* where virtually all code that deals with GSO segs can benefit, around ~30
67-
* drivers as of writing.
68-
*/
69-
#define skb_list_walk_safe(first, skb, next) \
70-
for (skb = first, next = skb->next; skb; \
71-
skb = next, next = skb ? skb->next : NULL)
72-
7365
#endif /* _WG_DEVICE_H */

‎include/linux/skbuff.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,11 @@ static inline void skb_mark_not_on_list(struct sk_buff *skb)
14781478
skb->next = NULL;
14791479
}
14801480

1481+
/* Iterate through singly-linked GSO fragments of an skb. */
1482+
#define skb_list_walk_safe(first, skb, next) \
1483+
for ((skb) = (first), (next) = (skb) ? (skb)->next : NULL; (skb); \
1484+
(skb) = (next), (next) = (skb) ? (skb)->next : NULL)
1485+
14811486
static inline void skb_list_del_init(struct sk_buff *skb)
14821487
{
14831488
__list_del_entry(&skb->list);

0 commit comments

Comments
 (0)