linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers:vfio: make the logic cleaner with braket
@ 2022-03-08  9:49 jianchunfu
  2022-03-08 20:59 ` Alex Williamson
  0 siblings, 1 reply; 2+ messages in thread
From: jianchunfu @ 2022-03-08  9:49 UTC (permalink / raw)
  To: alex.williamson; +Cc: cohuck, kvm, linux-kernel, jianchunfu

Use braket to avoid identifying operators in function
vfio_iova_dirty_bitmap() and vfio_dma_do_unmap()
when there are too many field values.

Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
---
 drivers/vfio/vfio_iommu_type1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 9394aa944..199547012 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -1251,7 +1251,7 @@ static int vfio_iova_dirty_bitmap(u64 __user *bitmap, struct vfio_iommu *iommu,
 		return -EINVAL;
 
 	dma = vfio_find_dma(iommu, iova + size - 1, 0);
-	if (dma && dma->iova + dma->size != iova + size)
+	if (dma && (dma->iova + dma->size) != (iova + size))
 		return -EINVAL;
 
 	for (n = rb_first(&iommu->dma_list); n; n = rb_next(n)) {
@@ -1363,7 +1363,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
 			goto unlock;
 
 		dma = vfio_find_dma(iommu, iova + size - 1, 0);
-		if (dma && dma->iova + dma->size != iova + size)
+		if (dma && (dma->iova + dma->size) != (iova + size))
 			goto unlock;
 	}
 
@@ -2958,7 +2958,7 @@ static int vfio_iommu_type1_dirty_pages(struct vfio_iommu *iommu,
 			ret = -EINVAL;
 			goto out_unlock;
 		}
-		if (!range.size || range.size & (iommu_pgsize - 1)) {
+		if (!range.size || (range.size & (iommu_pgsize - 1))) {
 			ret = -EINVAL;
 			goto out_unlock;
 		}
-- 
2.18.4




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

* Re: [PATCH] drivers:vfio: make the logic cleaner with braket
  2022-03-08  9:49 [PATCH] drivers:vfio: make the logic cleaner with braket jianchunfu
@ 2022-03-08 20:59 ` Alex Williamson
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2022-03-08 20:59 UTC (permalink / raw)
  To: jianchunfu; +Cc: cohuck, kvm, linux-kernel

On Tue,  8 Mar 2022 17:49:46 +0800
jianchunfu <jianchunfu@cmss.chinamobile.com> wrote:

> Use braket to avoid identifying operators in function
> vfio_iova_dirty_bitmap() and vfio_dma_do_unmap()
> when there are too many field values.

s/braket/bracket/ but we're actually adding parenthesis.

"to avoid identifying operators", to avoid confusing operators?

s/function/functions/ but this only lists two of the three.

How many are too many field values?  Per this patch, apparently one?
These are not particularly confusing or unruly tests imo.  Thanks,

Alex


> Signed-off-by: jianchunfu <jianchunfu@cmss.chinamobile.com>
> ---
>  drivers/vfio/vfio_iommu_type1.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 9394aa944..199547012 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -1251,7 +1251,7 @@ static int vfio_iova_dirty_bitmap(u64 __user *bitmap, struct vfio_iommu *iommu,
>  		return -EINVAL;
>  
>  	dma = vfio_find_dma(iommu, iova + size - 1, 0);
> -	if (dma && dma->iova + dma->size != iova + size)
> +	if (dma && (dma->iova + dma->size) != (iova + size))
>  		return -EINVAL;
>  
>  	for (n = rb_first(&iommu->dma_list); n; n = rb_next(n)) {
> @@ -1363,7 +1363,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
>  			goto unlock;
>  
>  		dma = vfio_find_dma(iommu, iova + size - 1, 0);
> -		if (dma && dma->iova + dma->size != iova + size)
> +		if (dma && (dma->iova + dma->size) != (iova + size))
>  			goto unlock;
>  	}
>  
> @@ -2958,7 +2958,7 @@ static int vfio_iommu_type1_dirty_pages(struct vfio_iommu *iommu,
>  			ret = -EINVAL;
>  			goto out_unlock;
>  		}
> -		if (!range.size || range.size & (iommu_pgsize - 1)) {
> +		if (!range.size || (range.size & (iommu_pgsize - 1))) {
>  			ret = -EINVAL;
>  			goto out_unlock;
>  		}


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

end of thread, other threads:[~2022-03-08 20:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08  9:49 [PATCH] drivers:vfio: make the logic cleaner with braket jianchunfu
2022-03-08 20:59 ` Alex Williamson

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