netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] nui: Fix dma_mapping_error() check
@ 2025-06-27 14:48 Thomas Fourier
  2025-06-27 20:16 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Fourier @ 2025-06-27 14:48 UTC (permalink / raw)
  Cc: Thomas Fourier, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Thomas Gleixner, Ingo Molnar,
	Jonathan Currier, Matthew Wilcox (Oracle), Uwe Kleine-König,
	Shuah Khan, netdev, linux-kernel

dma_map_XXX() functions return as error values DMA_MAPPING_ERROR which
is often ~0. The error value should be tested with dma_mapping_error().

Fixes: ec2deec1f352 ("niu: Fix to check for dma mapping errors.")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 drivers/net/ethernet/sun/niu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
index ddca8fc7883e..11ff08373de4 100644
--- a/drivers/net/ethernet/sun/niu.c
+++ b/drivers/net/ethernet/sun/niu.c
@@ -3336,7 +3336,7 @@ static int niu_rbr_add_page(struct niu *np, struct rx_ring_info *rp,
 
 	addr = np->ops->map_page(np->device, page, 0,
 				 PAGE_SIZE, DMA_FROM_DEVICE);
-	if (!addr) {
+	if (dma_mapping_error(np->device, addr)) {
 		__free_page(page);
 		return -ENOMEM;
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] nui: Fix dma_mapping_error() check
  2025-06-27 14:48 [PATCH net] nui: Fix dma_mapping_error() check Thomas Fourier
@ 2025-06-27 20:16 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2025-06-27 20:16 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Thomas Gleixner, Ingo Molnar, Jonathan Currier,
	Matthew Wilcox (Oracle), Uwe Kleine-König, Shuah Khan,
	netdev, linux-kernel

On Fri, Jun 27, 2025 at 04:48:19PM +0200, Thomas Fourier wrote:
> dma_map_XXX() functions return as error values DMA_MAPPING_ERROR which
> is often ~0. The error value should be tested with dma_mapping_error().
> 
> Fixes: ec2deec1f352 ("niu: Fix to check for dma mapping errors.")
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> ---
>  drivers/net/ethernet/sun/niu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
> index ddca8fc7883e..11ff08373de4 100644
> --- a/drivers/net/ethernet/sun/niu.c
> +++ b/drivers/net/ethernet/sun/niu.c
> @@ -3336,7 +3336,7 @@ static int niu_rbr_add_page(struct niu *np, struct rx_ring_info *rp,
>  
>  	addr = np->ops->map_page(np->device, page, 0,
>  				 PAGE_SIZE, DMA_FROM_DEVICE);
> -	if (!addr) {
> +	if (dma_mapping_error(np->device, addr)) {
>  		__free_page(page);
>  		return -ENOMEM;
>  	}

Hi Thomas,

Looking over niu.c I see two implementations of the .map_page callback.

1. niu_pci_map_page is a trivial wrapper around dma_map_page.
   And in that case your change looks good.

2. niu_phys_map_page, which looks like this:

static u64 niu_phys_map_page(struct device *dev, struct page *page,
                             unsigned long offset, size_t size,
                             enum dma_data_direction direction)
{
        return page_to_phys(page) + offset;
}

In this case dma_mapping_error may well correctly detect (no) errors.
But it will call debug_dma_mapping_error(), which doesn't seem ideal.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-27 20:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 14:48 [PATCH net] nui: Fix dma_mapping_error() check Thomas Fourier
2025-06-27 20:16 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).