Skip to contentSkip to conversation

xdp: compact the function xsk_map_inc

PATCH Superseded Zhu Yanjun 2 participants 2 messages Nov 22, 2020 – Nov 23, 2020

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zhu Yanjun

author
#0 lore raw

PATCH 1/1 xdp: compact the function xsk_map_inc

From: Zhu Yanjun <[email protected]>

The function xsk_map_inc always returns zero. As such, changing the return type to void and removing the test code.

---
 net/xdp/xsk.c    |    1 -
 net/xdp/xsk.h    |    2 +-
 net/xdp/xskmap.c |   10 ++--------
 3 files changed, 3 insertions(+), 10 deletions(-)
net/xdp/xsk.c +0 -1
index cfbec39..c1b8a88 100644
@@ -548,7 +548,6 @@ static void xsk_unbind_dev(struct xdp_sock *xs)
 	node = list_first_entry_or_null(&xs->map_list, struct xsk_map_node,
 					node);
 	if (node) {
-		WARN_ON(xsk_map_inc(node->map));
 		map = node->map;
 		*map_entry = node->map_entry;
 	}
net/xdp/xsk.h +1 -1
index b9e896c..766b9e2 100644
@@ -41,7 +41,7 @@ struct xsk_map_node {
 
 void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
 			     struct xdp_sock **map_entry);
-int xsk_map_inc(struct xsk_map *map);
+void xsk_map_inc(struct xsk_map *map);
 void xsk_map_put(struct xsk_map *map);
 void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id);
 int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,
net/xdp/xskmap.c +2 -8
index 49da2b8..c7dd94a 100644
@@ -11,10 +11,9 @@
 
 #include "xsk.h"
 
-int xsk_map_inc(struct xsk_map *map)
+void xsk_map_inc(struct xsk_map *map)
 {
 	bpf_map_inc(&map->map);
-	return 0;
 }
 
 void xsk_map_put(struct xsk_map *map)
@@ -26,17 +25,12 @@ void xsk_map_put(struct xsk_map *map)
 					       struct xdp_sock **map_entry)
 {
 	struct xsk_map_node *node;
-	int err;
 
 	node = kzalloc(sizeof(*node), GFP_ATOMIC | __GFP_NOWARN);
 	if (!node)
 		return ERR_PTR(-ENOMEM);
 
-	err = xsk_map_inc(map);
-	if (err) {
-		kfree(node);
-		return ERR_PTR(err);
-	}
+	xsk_map_inc(map);
 
 	node->map = map;
 	node->map_entry = map_entry;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 44 lines · Zhu Yanjun

From: Zhu Yanjun <[email protected]>

The function xsk_map_inc always returns zero. As such, changing the return type to void and removing the test code.

---
 net/xdp/xsk.c    |    1 -
 net/xdp/xsk.h    |    2 +-
 net/xdp/xskmap.c |   10 ++--------
 3 files changed, 3 insertions(+), 10 deletions(-)
net/xdp/xsk.c +0 -1
index cfbec39..c1b8a88 100644
@@ -548,7 +548,6 @@ static void xsk_unbind_dev(struct xdp_sock *xs)
        node = list_first_entry_or_null(&xs->map_list, struct xsk_map_node,
                                        node);
        if (node) {
-               WARN_ON(xsk_map_inc(node->map));
                map = node->map;
                *map_entry = node->map_entry;
        }
net/xdp/xsk.h +1 -1
index b9e896c..766b9e2 100644
@@ -41,7 +41,7 @@ struct xsk_map_node {
 
 void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
                             struct xdp_sock **map_entry);
-int xsk_map_inc(struct xsk_map *map);
+void xsk_map_inc(struct xsk_map *map);
 void xsk_map_put(struct xsk_map *map);
 void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id);
 int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool,
net/xdp/xskmap.c +0 -0
index 49da2b8..c7dd94a 100644

net/xdp/xskmap.c line 17

Quoted 9 lines
net/xdp/xskmap.c +1 -2
@@ -11,10 +11,9 @@
 
 #include "xsk.h"
 
-int xsk_map_inc(struct xsk_map *map)
+void xsk_map_inc(struct xsk_map *map)
 {
        bpf_map_inc(&map->map);
-       return 0;
 }

Thank you Yanjun for your cleanup. I think we can take this one step further and remove the function xsk_map_inc completely and use bpf_map_inc directly in the code. Could you please do this and submit a v2?

Quoted 23 lines
net/xdp/xskmap.c +1 -7
 void xsk_map_put(struct xsk_map *map)
@@ -26,17 +25,12 @@ void xsk_map_put(struct xsk_map *map)
                                               struct xdp_sock **map_entry)
 {
        struct xsk_map_node *node;
-       int err;
 
        node = kzalloc(sizeof(*node), GFP_ATOMIC | __GFP_NOWARN);
        if (!node)
                return ERR_PTR(-ENOMEM);
 
-       err = xsk_map_inc(map);
-       if (err) {
-               kfree(node);
-               return ERR_PTR(err);
-       }
+       xsk_map_inc(map);
 
        node->map = map;
        node->map_entry = map_entry;
--

1.7.1