linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask
@ 2022-01-06  2:43 Jiasheng Jiang
  2022-02-14 11:43 ` Joerg Roedel
  0 siblings, 1 reply; 5+ messages in thread
From: Jiasheng Jiang @ 2022-01-06  2:43 UTC (permalink / raw)
  To: joro, will; +Cc: iommu, linux-kernel, Jiasheng Jiang

Because of the possible failure of the dma_supported(), the
dma_set_mask_and_coherent() may return error num.
Therefore, it should be better to check it and return the error if
fails.

Fixes: 1c894225bf5b ("iommu/ipmmu-vmsa: IPMMU device is 40-bit bus master")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/iommu/ipmmu-vmsa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
index aaa6a4d59057..7df5da44a004 100644
--- a/drivers/iommu/ipmmu-vmsa.c
+++ b/drivers/iommu/ipmmu-vmsa.c
@@ -1003,7 +1003,9 @@ static int ipmmu_probe(struct platform_device *pdev)
 	bitmap_zero(mmu->ctx, IPMMU_CTX_MAX);
 	mmu->features = of_device_get_match_data(&pdev->dev);
 	memset(mmu->utlb_ctx, IPMMU_CTX_INVALID, mmu->features->num_utlbs);
-	dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
+	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
+	if (ret)
+		return ret;
 
 	/* Map I/O memory and request IRQ. */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
2.25.1


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

* Re: [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask
  2022-01-06  2:43 [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask Jiasheng Jiang
@ 2022-02-14 11:43 ` Joerg Roedel
  2022-02-14 12:00   ` Nikita Yushchenko
  2022-02-14 12:32   ` Robin Murphy
  0 siblings, 2 replies; 5+ messages in thread
From: Joerg Roedel @ 2022-02-14 11:43 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: will, iommu, linux-kernel, Robin Murphy, Nikita Yushchenko,
	Laurent Pinchart

Adding more potential reviewers.

On Thu, Jan 06, 2022 at 10:43:02AM +0800, Jiasheng Jiang wrote:
> Because of the possible failure of the dma_supported(), the
> dma_set_mask_and_coherent() may return error num.
> Therefore, it should be better to check it and return the error if
> fails.
> 
> Fixes: 1c894225bf5b ("iommu/ipmmu-vmsa: IPMMU device is 40-bit bus master")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/iommu/ipmmu-vmsa.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
> index aaa6a4d59057..7df5da44a004 100644
> --- a/drivers/iommu/ipmmu-vmsa.c
> +++ b/drivers/iommu/ipmmu-vmsa.c
> @@ -1003,7 +1003,9 @@ static int ipmmu_probe(struct platform_device *pdev)
>  	bitmap_zero(mmu->ctx, IPMMU_CTX_MAX);
>  	mmu->features = of_device_get_match_data(&pdev->dev);
>  	memset(mmu->utlb_ctx, IPMMU_CTX_INVALID, mmu->features->num_utlbs);
> -	dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
> +	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
> +	if (ret)
> +		return ret;
>  
>  	/* Map I/O memory and request IRQ. */
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -- 
> 2.25.1

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

* Re: [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask
  2022-02-14 11:43 ` Joerg Roedel
@ 2022-02-14 12:00   ` Nikita Yushchenko
  2022-02-14 12:32   ` Robin Murphy
  1 sibling, 0 replies; 5+ messages in thread
From: Nikita Yushchenko @ 2022-02-14 12:00 UTC (permalink / raw)
  To: Joerg Roedel, Jiasheng Jiang
  Cc: will, iommu, linux-kernel, Robin Murphy, Laurent Pinchart

> Adding more potential reviewers.
> 
> On Thu, Jan 06, 2022 at 10:43:02AM +0800, Jiasheng Jiang wrote:
>> Because of the possible failure of the dma_supported(), the
>> dma_set_mask_and_coherent() may return error num.
>> Therefore, it should be better to check it and return the error if
>> fails.

Indeed, most uses of dma_set_mask_and_coherent() in the kernel do check return value.

Reviewed-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>

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

* Re: [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask
  2022-02-14 11:43 ` Joerg Roedel
  2022-02-14 12:00   ` Nikita Yushchenko
@ 2022-02-14 12:32   ` Robin Murphy
  2022-02-14 12:41     ` Joerg Roedel
  1 sibling, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2022-02-14 12:32 UTC (permalink / raw)
  To: Joerg Roedel, Jiasheng Jiang
  Cc: will, iommu, linux-kernel, Nikita Yushchenko, Laurent Pinchart

On 2022-02-14 11:43, Joerg Roedel wrote:
> Adding more potential reviewers.
> 
> On Thu, Jan 06, 2022 at 10:43:02AM +0800, Jiasheng Jiang wrote:
>> Because of the possible failure of the dma_supported(), the
>> dma_set_mask_and_coherent() may return error num.
>> Therefore, it should be better to check it and return the error if
>> fails.

In this particular case it cannot fail on any system the driver actually 
runs on - it's a platform device so the dma_mask pointer is always 
initialised, then dma_direct_supported() on arm64 will always return 
true for any mask wider than 32 bits, while arm_dma_supported() will 
also always pass since a 32-bit system cannot have memory above 40 bits 
either.

There's no great harm in adding the check for the sake of consistency, I 
guess, but it's purely cosmetic and not fixing anything.

Thanks,
Robin.

>> Fixes: 1c894225bf5b ("iommu/ipmmu-vmsa: IPMMU device is 40-bit bus master")
>> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>> ---
>>   drivers/iommu/ipmmu-vmsa.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c
>> index aaa6a4d59057..7df5da44a004 100644
>> --- a/drivers/iommu/ipmmu-vmsa.c
>> +++ b/drivers/iommu/ipmmu-vmsa.c
>> @@ -1003,7 +1003,9 @@ static int ipmmu_probe(struct platform_device *pdev)
>>   	bitmap_zero(mmu->ctx, IPMMU_CTX_MAX);
>>   	mmu->features = of_device_get_match_data(&pdev->dev);
>>   	memset(mmu->utlb_ctx, IPMMU_CTX_INVALID, mmu->features->num_utlbs);
>> -	dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
>> +	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40));
>> +	if (ret)
>> +		return ret;
>>   
>>   	/* Map I/O memory and request IRQ. */
>>   	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> -- 
>> 2.25.1

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

* Re: [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask
  2022-02-14 12:32   ` Robin Murphy
@ 2022-02-14 12:41     ` Joerg Roedel
  0 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2022-02-14 12:41 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Jiasheng Jiang, will, iommu, linux-kernel, Nikita Yushchenko,
	Laurent Pinchart

On Mon, Feb 14, 2022 at 12:32:21PM +0000, Robin Murphy wrote:
> In this particular case it cannot fail on any system the driver actually
> runs on - it's a platform device so the dma_mask pointer is always
> initialised, then dma_direct_supported() on arm64 will always return true
> for any mask wider than 32 bits, while arm_dma_supported() will also always
> pass since a 32-bit system cannot have memory above 40 bits either.
> 
> There's no great harm in adding the check for the sake of consistency, I
> guess, but it's purely cosmetic and not fixing anything.

Okay, thanks Robin and Nikita for looking to quickly into this. I will
apply it for 5.18 just to be on the safe side if the above assumptions
change.

Regards,

	Joerg

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

end of thread, other threads:[~2022-02-14 12:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06  2:43 [PATCH] iommu/ipmmu-vmsa: Check for error num after setting mask Jiasheng Jiang
2022-02-14 11:43 ` Joerg Roedel
2022-02-14 12:00   ` Nikita Yushchenko
2022-02-14 12:32   ` Robin Murphy
2022-02-14 12:41     ` Joerg Roedel

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).