Skip to contentSkip to conversation

accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure

PATCH In review Lizhi Hou 3 participants 4 messages Mar 23

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure

From: Wendy Liang <[email protected]>

dma_alloc_noncoherent() returns NULL on failure, but callers of aie2_alloc_msg_buffer() check for IS_ERR(). Return ERR_PTR(-ENOMEM) instead of NULL to match the amdxdna_iommu_alloc() path and the caller's error checking convention.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
---
 drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_message.c +6 -1
index 7e219a5eda56..a1c546c3e81c 100644
@@ -56,6 +56,7 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size,
 			    dma_addr_t *dma_addr)
 {
 	struct amdxdna_dev *xdna = ndev->xdna;
+	void *vaddr;
 	int order;
 
 	*size = max(*size, SZ_8K);
@@ -67,8 +68,12 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size,
 	if (amdxdna_iova_on(xdna))
 		return amdxdna_iommu_alloc(xdna, *size, dma_addr);
 
-	return dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
+	vaddr = dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
 				      DMA_FROM_DEVICE, GFP_KERNEL);
+	if (!vaddr)
+		return ERR_PTR(-ENOMEM);
+
+	return vaddr;
 }
 
 void aie2_free_msg_buffer(struct amdxdna_dev_hdl *ndev, size_t size,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Lizhi Hou

From: Wendy Liang <[email protected]>

dma_alloc_noncoherent() returns NULL on failure, but callers of aie2_alloc_msg_buffer() check for IS_ERR(). Return ERR_PTR(-ENOMEM) instead of NULL to match the amdxdna_iommu_alloc() path and the caller's error checking convention.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
---
 drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_message.c +1 -0
index 7e219a5eda56..a1c546c3e81c 100644
@@ -56,6 +56,7 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size,
 			    dma_addr_t *dma_addr)
 {
 	struct amdxdna_dev *xdna = ndev->xdna;
+	void *vaddr;
 	int order;
 
 	*size = max(*size, SZ_8K);
@@ -67,8 +68,12 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size,
 	if (amdxdna_iova_on(xdna))
 		return amdxdna_iommu_alloc(xdna, *size, dma_addr);
 

drivers/accel/amdxdna/aie2_message.c void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size, · line 79

Quoted 10 lines
drivers/accel/amdxdna/aie2_message.c +5 -1
-	return dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
+	vaddr = dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
 				      DMA_FROM_DEVICE, GFP_KERNEL);
+	if (!vaddr)
+		return ERR_PTR(-ENOMEM);
+
+	return vaddr;
 }
 
 void aie2_free_msg_buffer(struct amdxdna_dev_hdl *ndev, size_t size,
#2 lore raw
In reply to Lizhi Hou
Quoted 30 lines · Lizhi Hou

From: Wendy Liang <[email protected]>

dma_alloc_noncoherent() returns NULL on failure, but callers of aie2_alloc_msg_buffer() check for IS_ERR(). Return ERR_PTR(-ENOMEM) instead of NULL to match the amdxdna_iommu_alloc() path and the caller's error checking convention.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
---
  drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_message.c +1 -0
index 7e219a5eda56..a1c546c3e81c 100644
@@ -56,6 +56,7 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size,
  			    dma_addr_t *dma_addr)
  {
  	struct amdxdna_dev *xdna = ndev->xdna;
+	void *vaddr;
  	int order;
 
  	*size = max(*size, SZ_8K);
@@ -67,8 +68,12 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size,
  	if (amdxdna_iova_on(xdna))
  		return amdxdna_iommu_alloc(xdna, *size, dma_addr);
 

drivers/accel/amdxdna/aie2_message.c void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl *ndev, u32 *size, · line 79

Quoted 10 lines
drivers/accel/amdxdna/aie2_message.c +5 -1
-	return dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
+	vaddr = dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
  				      DMA_FROM_DEVICE, GFP_KERNEL);
+	if (!vaddr)
+		return ERR_PTR(-ENOMEM);
+
+	return vaddr;
  }
 
  void aie2_free_msg_buffer(struct amdxdna_dev_hdl *ndev, size_t size,
author maintainer Applied
#3 lore raw

Applied to drm-misc-next

Quoted 43 lines · Mario Limonciello (AMD) (kernel.org)
Quoted 29 lines · Lizhi Hou

From: Wendy Liang <[email protected]>

dma_alloc_noncoherent() returns NULL on failure, but callers of aie2_alloc_msg_buffer() check for IS_ERR(). Return ERR_PTR(-ENOMEM) instead of NULL to match the amdxdna_iommu_alloc() path and the caller's error checking convention.

Fixes ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")

---
  drivers/accel/amdxdna/aie2_message.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/aie2_message.c +1 -0
index 7e219a5eda56..a1c546c3e81c 100644
@@ -56,6 +56,7 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl 
 *ndev, u32 *size,
                   dma_addr_t *dma_addr)
   {
       struct amdxdna_dev *xdna = ndev->xdna;
+    void *vaddr;
       int order;
         *size = max(*size, SZ_8K);
@@ -67,8 +68,12 @@ void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl 
 *ndev, u32 *size,
       if (amdxdna_iova_on(xdna))

drivers/accel/amdxdna/aie2_message.c void *aie2_alloc_msg_buffer(struct amdxdna_dev_hdl · line 79

Quoted 10 lines
drivers/accel/amdxdna/aie2_message.c +5 -0
           return amdxdna_iommu_alloc(xdna, *size, dma_addr);
   -    return dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
+    vaddr = dma_alloc_noncoherent(xdna->ddev.dev, *size, dma_addr,
                         DMA_FROM_DEVICE, GFP_KERNEL);
+    if (!vaddr)
+        return ERR_PTR(-ENOMEM);
+
+    return vaddr;
   }
     void aie2_free_msg_buffer(struct amdxdna_dev_hdl *ndev, size_t size,