Commit 5f0ca2fb authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: handle page allocation failures

page_address() does not handle NULL argument gracefully,
make sure we NULL-check the page pointer before passing it
to page_address().

Fixes: ecd63a02 ("nfp: add XDP support in the driver")
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarSimon Horman <simon.horman@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c3d64ad4
...@@ -1180,10 +1180,14 @@ static void *nfp_net_rx_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr) ...@@ -1180,10 +1180,14 @@ static void *nfp_net_rx_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr)
{ {
void *frag; void *frag;
if (!dp->xdp_prog) if (!dp->xdp_prog) {
frag = netdev_alloc_frag(dp->fl_bufsz); frag = netdev_alloc_frag(dp->fl_bufsz);
else } else {
frag = page_address(alloc_page(GFP_KERNEL | __GFP_COLD)); struct page *page;
page = alloc_page(GFP_KERNEL | __GFP_COLD);
frag = page ? page_address(page) : NULL;
}
if (!frag) { if (!frag) {
nn_dp_warn(dp, "Failed to alloc receive page frag\n"); nn_dp_warn(dp, "Failed to alloc receive page frag\n");
return NULL; return NULL;
...@@ -1203,10 +1207,14 @@ static void *nfp_net_napi_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr) ...@@ -1203,10 +1207,14 @@ static void *nfp_net_napi_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr)
{ {
void *frag; void *frag;
if (!dp->xdp_prog) if (!dp->xdp_prog) {
frag = napi_alloc_frag(dp->fl_bufsz); frag = napi_alloc_frag(dp->fl_bufsz);
else } else {
frag = page_address(alloc_page(GFP_ATOMIC | __GFP_COLD)); struct page *page;
page = alloc_page(GFP_ATOMIC | __GFP_COLD);
frag = page ? page_address(page) : NULL;
}
if (!frag) { if (!frag) {
nn_dp_warn(dp, "Failed to alloc receive page frag\n"); nn_dp_warn(dp, "Failed to alloc receive page frag\n");
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment