提交 fd784d12 编写于 作者: M Magnus Karlsson 提交者: Yang Yingliang

xsk: Use struct_size() helper

mainline inclusion
from mainline-v5.6-rc1
commit 1d9cb1f3
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I4SGA9?from=project-issue
CVE: NA

--------------------------------

Improve readability and maintainability by using the struct_size()
helper when allocating the AF_XDP rings.
Signed-off-by: NMagnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/1576759171-28550-13-git-send-email-magnus.karlsson@intel.comSigned-off-by: NHuang Guobin <huangguobin4@huawei.com>
Reviewed-by: NYue Haibing <yuehaibing@huawei.com>
Reviewed-by: NWei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 3c002599
...@@ -15,14 +15,14 @@ void xskq_set_umem(struct xsk_queue *q, struct xdp_umem_props *umem_props) ...@@ -15,14 +15,14 @@ void xskq_set_umem(struct xsk_queue *q, struct xdp_umem_props *umem_props)
q->umem_props = *umem_props; q->umem_props = *umem_props;
} }
static u32 xskq_umem_get_ring_size(struct xsk_queue *q) static size_t xskq_get_ring_size(struct xsk_queue *q, bool umem_queue)
{ {
return sizeof(struct xdp_umem_ring) + q->nentries * sizeof(u64); struct xdp_umem_ring *umem_ring;
} struct xdp_rxtx_ring *rxtx_ring;
static u32 xskq_rxtx_get_ring_size(struct xsk_queue *q) if (umem_queue)
{ return struct_size(umem_ring, desc, q->nentries);
return sizeof(struct xdp_ring) + q->nentries * sizeof(struct xdp_desc); return struct_size(rxtx_ring, desc, q->nentries);
} }
struct xsk_queue *xskq_create(u32 nentries, bool umem_queue) struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
...@@ -40,8 +40,7 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue) ...@@ -40,8 +40,7 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue)
gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN |
__GFP_COMP | __GFP_NORETRY; __GFP_COMP | __GFP_NORETRY;
size = umem_queue ? xskq_umem_get_ring_size(q) : size = xskq_get_ring_size(q, umem_queue);
xskq_rxtx_get_ring_size(q);
q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags, q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags,
get_order(size)); get_order(size));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册