Skip to content

Commit

Permalink
tuntap: simplify error handling in tun_build_skb()
Browse files Browse the repository at this point in the history
There's no need to duplicate page get logic in each action. So this
patch tries to get page and calculate the offset before processing XDP
actions (except for XDP_DROP), and undo them when meet errors (we
don't care the performance on errors). This will be used for factoring
out XDP logic.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jason Wang authored and David S. Miller committed Sep 13, 2018
1 parent 291aeb2 commit f7053b6
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1701,17 +1701,13 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
xdp_do_flush_map();
if (err)
goto err_redirect;
rcu_read_unlock();
local_bh_enable();
return NULL;
goto out;
case XDP_TX:
get_page(alloc_frag->page);
alloc_frag->offset += buflen;
if (tun_xdp_tx(tun->dev, &xdp) < 0)
goto err_redirect;
rcu_read_unlock();
local_bh_enable();
return NULL;
goto out;
case XDP_PASS:
delta = orig_data - xdp.data;
len = xdp.data_end - xdp.data;
Expand Down Expand Up @@ -1742,7 +1738,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,

err_redirect:
put_page(alloc_frag->page);
err_xdp:
out:
rcu_read_unlock();
local_bh_enable();
this_cpu_inc(tun->pcpu_stats->rx_dropped);
Expand Down

0 comments on commit f7053b6

Please sign in to comment.