Skip to content

Commit 5f0ca2f

Browse files
Jakub Kicinskidavem330
authored andcommitted
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: ecd63a0 ("nfp: add XDP support in the driver") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c3d64ad commit 5f0ca2f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/net/ethernet/netronome/nfp/nfp_net_common.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,10 +1180,14 @@ static void *nfp_net_rx_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr)
11801180
{
11811181
void *frag;
11821182

1183-
if (!dp->xdp_prog)
1183+
if (!dp->xdp_prog) {
11841184
frag = netdev_alloc_frag(dp->fl_bufsz);
1185-
else
1186-
frag = page_address(alloc_page(GFP_KERNEL | __GFP_COLD));
1185+
} else {
1186+
struct page *page;
1187+
1188+
page = alloc_page(GFP_KERNEL | __GFP_COLD);
1189+
frag = page ? page_address(page) : NULL;
1190+
}
11871191
if (!frag) {
11881192
nn_dp_warn(dp, "Failed to alloc receive page frag\n");
11891193
return NULL;
@@ -1203,10 +1207,14 @@ static void *nfp_net_napi_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr)
12031207
{
12041208
void *frag;
12051209

1206-
if (!dp->xdp_prog)
1210+
if (!dp->xdp_prog) {
12071211
frag = napi_alloc_frag(dp->fl_bufsz);
1208-
else
1209-
frag = page_address(alloc_page(GFP_ATOMIC | __GFP_COLD));
1212+
} else {
1213+
struct page *page;
1214+
1215+
page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1216+
frag = page ? page_address(page) : NULL;
1217+
}
12101218
if (!frag) {
12111219
nn_dp_warn(dp, "Failed to alloc receive page frag\n");
12121220
return NULL;

0 commit comments

Comments
 (0)