Skip to content

Commit

Permalink
net-tun: Add type safety to tun_xdp_to_ptr() and tun_ptr_to_xdp()
Browse files Browse the repository at this point in the history
This reduces likelihood of incorrect use.

Test: builds

Signed-off-by: Maciej Żenczykowski <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
zenczykowski authored and Alexei Starovoitov committed Aug 19, 2020
1 parent 3708115 commit b558b6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ bool tun_is_xdp_frame(void *ptr)
}
EXPORT_SYMBOL(tun_is_xdp_frame);

void *tun_xdp_to_ptr(void *ptr)
void *tun_xdp_to_ptr(struct xdp_frame *xdp)
{
return (void *)((unsigned long)ptr | TUN_XDP_FLAG);
return (void *)((unsigned long)xdp | TUN_XDP_FLAG);
}
EXPORT_SYMBOL(tun_xdp_to_ptr);

void *tun_ptr_to_xdp(void *ptr)
struct xdp_frame *tun_ptr_to_xdp(void *ptr)
{
return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
}
Expand Down
8 changes: 4 additions & 4 deletions include/linux/if_tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct tun_xdp_hdr {
struct socket *tun_get_socket(struct file *);
struct ptr_ring *tun_get_tx_ring(struct file *file);
bool tun_is_xdp_frame(void *ptr);
void *tun_xdp_to_ptr(void *ptr);
void *tun_ptr_to_xdp(void *ptr);
void *tun_xdp_to_ptr(struct xdp_frame *xdp);
struct xdp_frame *tun_ptr_to_xdp(void *ptr);
void tun_ptr_free(void *ptr);
#else
#include <linux/err.h>
Expand All @@ -48,11 +48,11 @@ static inline bool tun_is_xdp_frame(void *ptr)
{
return false;
}
static inline void *tun_xdp_to_ptr(void *ptr)
static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
{
return NULL;
}
static inline void *tun_ptr_to_xdp(void *ptr)
static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
{
return NULL;
}
Expand Down

0 comments on commit b558b6c

Please sign in to comment.