[PATCH V1] accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure

Lizhi Hou posted 1 patch 1 week, 5 days ago
drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH V1] accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure
Posted by Lizhi Hou 1 week, 5 days ago
From: Wendy Liang <wendy.liang@amd.com>

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")
Signed-off-by: Wendy Liang <wendy.liang@amd.com>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/amdxdna/aie2_message.c b/drivers/accel/amdxdna/aie2_message.c
index 7e219a5eda56..a1c546c3e81c 100644
--- a/drivers/accel/amdxdna/aie2_message.c
+++ b/drivers/accel/amdxdna/aie2_message.c
@@ -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,
-- 
2.34.1
Re: [PATCH V1] accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure
Posted by Karol Wachowski 1 week, 5 days ago
On 3/23/2026 6:37 PM, Lizhi Hou wrote:
> From: Wendy Liang <wendy.liang@amd.com>
> 
> 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")
> Signed-off-by: Wendy Liang <wendy.liang@amd.com>
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> ---
>  drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/accel/amdxdna/aie2_message.c b/drivers/accel/amdxdna/aie2_message.c
> index 7e219a5eda56..a1c546c3e81c 100644
> --- a/drivers/accel/amdxdna/aie2_message.c
> +++ b/drivers/accel/amdxdna/aie2_message.c
> @@ -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,

Reviewed-by: Karol Wachowski <karol.wachowski@linux.intel.com>
Re: [PATCH V1] accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure
Posted by Mario Limonciello (AMD) (kernel.org) 1 week, 5 days ago

On 3/23/2026 12:37 PM, Lizhi Hou wrote:
> From: Wendy Liang <wendy.liang@amd.com>
> 
> 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")
> Signed-off-by: Wendy Liang <wendy.liang@amd.com>
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> ---
>   drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/accel/amdxdna/aie2_message.c b/drivers/accel/amdxdna/aie2_message.c
> index 7e219a5eda56..a1c546c3e81c 100644
> --- a/drivers/accel/amdxdna/aie2_message.c
> +++ b/drivers/accel/amdxdna/aie2_message.c
> @@ -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,
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Re: [PATCH V1] accel/amdxdna: Return ERR_PTR on dma_alloc_noncoherent failure
Posted by Lizhi Hou 1 week, 5 days ago
Applied to drm-misc-next

On 3/23/26 10:56, Mario Limonciello (AMD) (kernel.org) wrote:
>
>
> On 3/23/2026 12:37 PM, Lizhi Hou wrote:
>> From: Wendy Liang <wendy.liang@amd.com>
>>
>> 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")
>> Signed-off-by: Wendy Liang <wendy.liang@amd.com>
>> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
>> ---
>>   drivers/accel/amdxdna/aie2_message.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/accel/amdxdna/aie2_message.c 
>> b/drivers/accel/amdxdna/aie2_message.c
>> index 7e219a5eda56..a1c546c3e81c 100644
>> --- a/drivers/accel/amdxdna/aie2_message.c
>> +++ b/drivers/accel/amdxdna/aie2_message.c
>> @@ -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,
> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>