* Re: [net-next,v20,3/7] net: mtip: Add buffers management functions to the L2 switch driver [not found] <20260126103400.1683125-4-lukasz.majewski@mailbox.org> @ 2026-01-28 2:25 ` Jakub Kicinski 2026-01-28 21:48 ` Łukasz Majewski 0 siblings, 1 reply; 2+ messages in thread From: Jakub Kicinski @ 2026-01-28 2:25 UTC (permalink / raw) To: lukasz.majewski Cc: Jakub Kicinski, festevam, linux-arm-kernel, s.hauer, kernel, horms, shawnguo, imx, linux-kernel, conor+dt, devicetree, wahrenst, pabeni, davem, netdev, richardcochran, edumazet, andrew+netdev, robh, krzk+dt, andrew This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html --- net: mtip: Add buffers management functions to the L2 switch driver This patch adds buffer management functions for the MTIP L2 switch driver, implementing mtip_free_buffers(), mtip_create_page_pool(), and mtip_alloc_buffers() for RX page pool and TX bounce buffer handling. > diff --git a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c > index 03c5163d6508..9c21a3d29c1c 100644 > --- a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c > +++ b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c > @@ -888,11 +888,96 @@ static void mtip_get_drvinfo(struct net_device *dev, > > static void mtip_free_buffers(struct net_device *dev) > { > + struct mtip_ndev_priv *priv = netdev_priv(dev); > + struct switch_enet_private *fep = priv->fep; > + int i; > + > + for (i = 0; i < RX_RING_SIZE; i++) { > + page_pool_put_full_page(fep->page_pool, > + fep->page[i], false); Can fep->page[i] be NULL here? When mtip_alloc_buffers() fails partway through the RX allocation loop, it calls mtip_free_buffers() via the error path. At that point, only some fep->page[] entries have been allocated - the rest remain NULL from the kzalloc initialization. The call chain page_pool_put_full_page()->page_pool_put_netmem()-> page_pool_unref_and_test()->page_pool_unref_netmem()-> netmem_get_pp_ref_count_ref() will attempt to access &NULL->pp_ref_count when passed a NULL page, causing a NULL pointer dereference. Should there be a NULL check before calling page_pool_put_full_page()? > + fep->page[i] = NULL; > + } > + > + page_pool_destroy(fep->page_pool); > + fep->page_pool = NULL; > + > + for (i = 0; i < TX_RING_SIZE; i++) > + kfree(fep->tx_bounce[i]); > } [ ... ] > +static int mtip_alloc_buffers(struct net_device *dev) > +{ > + struct mtip_ndev_priv *priv = netdev_priv(dev); > + struct switch_enet_private *fep = priv->fep; > + struct cbd_t *bdp; > + struct page *page; > + int i, ret; > + > + ret = mtip_create_page_pool(fep, RX_RING_SIZE); > + if (ret < 0) { > + dev_err(&fep->pdev->dev, "Failed to create page pool\n"); > + return ret; > + } > + > + bdp = fep->rx_bd_base; > + for (i = 0; i < RX_RING_SIZE; i++) { > + page = page_pool_dev_alloc_pages(fep->page_pool); > + if (!page) { > + dev_err(&fep->pdev->dev, > + "Failed to allocate page for rx buffer\n"); > + goto err; > + } [ ... ] > + err: > + mtip_free_buffers(dev); When this error path is taken, fep->page[] may contain NULL entries for pages that were never allocated. > + return -ENOMEM; > } ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [net-next,v20,3/7] net: mtip: Add buffers management functions to the L2 switch driver 2026-01-28 2:25 ` [net-next,v20,3/7] net: mtip: Add buffers management functions to the L2 switch driver Jakub Kicinski @ 2026-01-28 21:48 ` Łukasz Majewski 0 siblings, 0 replies; 2+ messages in thread From: Łukasz Majewski @ 2026-01-28 21:48 UTC (permalink / raw) To: Jakub Kicinski Cc: festevam, linux-arm-kernel, s.hauer, kernel, horms, shawnguo, imx, linux-kernel, conor+dt, devicetree, wahrenst, pabeni, davem, netdev, richardcochran, edumazet, andrew+netdev, robh, krzk+dt, andrew Hi Jakub, > This is an AI-generated review of your patch. The human sending this > email has considered the AI review valid, or at least plausible. > > For local reproduction steps see > https://netdev-ai.bots.linux.dev/ai-local.html --- > net: mtip: Add buffers management functions to the L2 switch driver > > This patch adds buffer management functions for the MTIP L2 switch > driver, implementing mtip_free_buffers(), mtip_create_page_pool(), and > mtip_alloc_buffers() for RX page pool and TX bounce buffer handling. > > > diff --git a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c > > b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c index > > 03c5163d6508..9c21a3d29c1c 100644 --- > > a/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c +++ > > b/drivers/net/ethernet/freescale/mtipsw/mtipl2sw.c @@ -888,11 > > +888,96 @@ static void mtip_get_drvinfo(struct net_device *dev, > > > > static void mtip_free_buffers(struct net_device *dev) > > { > > + struct mtip_ndev_priv *priv = netdev_priv(dev); > > + struct switch_enet_private *fep = priv->fep; > > + int i; > > + > > + for (i = 0; i < RX_RING_SIZE; i++) { > > + page_pool_put_full_page(fep->page_pool, > > + fep->page[i], false); > > Can fep->page[i] be NULL here? When mtip_alloc_buffers() fails > partway through the RX allocation loop, it calls mtip_free_buffers() > via the error path. At that point, only some fep->page[] entries > have been allocated - the rest remain NULL from the kzalloc > initialization. > > The call chain page_pool_put_full_page()->page_pool_put_netmem()-> > page_pool_unref_and_test()->page_pool_unref_netmem()-> > netmem_get_pp_ref_count_ref() will attempt to access > &NULL->pp_ref_count when passed a NULL page, causing a NULL pointer > dereference. > > Should there be a NULL check before calling page_pool_put_full_page()? > Yes, such check shall be added. > > + fep->page[i] = NULL; > > + } > > + > > + page_pool_destroy(fep->page_pool); > > + fep->page_pool = NULL; > > + > > + for (i = 0; i < TX_RING_SIZE; i++) > > + kfree(fep->tx_bounce[i]); > > } > > [ ... ] > > > +static int mtip_alloc_buffers(struct net_device *dev) > > +{ > > + struct mtip_ndev_priv *priv = netdev_priv(dev); > > + struct switch_enet_private *fep = priv->fep; > > + struct cbd_t *bdp; > > + struct page *page; > > + int i, ret; > > + > > + ret = mtip_create_page_pool(fep, RX_RING_SIZE); > > + if (ret < 0) { > > + dev_err(&fep->pdev->dev, "Failed to create page > > pool\n"); > > + return ret; > > + } > > + > > + bdp = fep->rx_bd_base; > > + for (i = 0; i < RX_RING_SIZE; i++) { > > + page = page_pool_dev_alloc_pages(fep->page_pool); > > + if (!page) { > > + dev_err(&fep->pdev->dev, > > + "Failed to allocate page for rx > > buffer\n"); > > + goto err; > > + } > > [ ... ] > > > + err: > > + mtip_free_buffers(dev); > > When this error path is taken, fep->page[] may contain NULL entries > for pages that were never allocated. > > > + return -ENOMEM; > > } I will add proper fix for v21. -- Best regards, Łukasz Majewski ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-28 21:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260126103400.1683125-4-lukasz.majewski@mailbox.org>
2026-01-28 2:25 ` [net-next,v20,3/7] net: mtip: Add buffers management functions to the L2 switch driver Jakub Kicinski
2026-01-28 21:48 ` Łukasz Majewski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox