* [PATCH] vfio_iommu_type1: increase the validity check of function parameters
@ 2022-12-23 7:24 Li kunyu
2022-12-23 13:28 ` Alex Williamson
0 siblings, 1 reply; 2+ messages in thread
From: Li kunyu @ 2022-12-23 7:24 UTC (permalink / raw)
To: alex.williamson, cohuck; +Cc: kvm, linux-kernel, Li kunyu
Added validity check for count variable, return if count variable does
not meet the execution condition (do not execute mutex_lock and
mutex_unlock function).
Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
drivers/vfio/vfio_iommu_type1.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 23c24fe98c00..9bdf96d932e4 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -3137,6 +3137,9 @@ static int vfio_iommu_type1_dma_rw(void *iommu_data, dma_addr_t user_iova,
int ret = 0;
size_t done;
+ if (count <= 0)
+ return ret;
+
mutex_lock(&iommu->lock);
while (count > 0) {
ret = vfio_iommu_type1_dma_rw_chunk(iommu, user_iova, data,
--
2.18.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] vfio_iommu_type1: increase the validity check of function parameters
2022-12-23 7:24 [PATCH] vfio_iommu_type1: increase the validity check of function parameters Li kunyu
@ 2022-12-23 13:28 ` Alex Williamson
0 siblings, 0 replies; 2+ messages in thread
From: Alex Williamson @ 2022-12-23 13:28 UTC (permalink / raw)
To: Li kunyu; +Cc: cohuck, kvm, linux-kernel
On Fri, 23 Dec 2022 15:24:18 +0800
Li kunyu <kunyu@nfschina.com> wrote:
> Added validity check for count variable, return if count variable does
> not meet the execution condition (do not execute mutex_lock and
> mutex_unlock function).
>
> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> ---
> drivers/vfio/vfio_iommu_type1.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index 23c24fe98c00..9bdf96d932e4 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -3137,6 +3137,9 @@ static int vfio_iommu_type1_dma_rw(void *iommu_data, dma_addr_t user_iova,
> int ret = 0;
> size_t done;
>
> + if (count <= 0)
> + return ret;
> +
> mutex_lock(&iommu->lock);
> while (count > 0) {
> ret = vfio_iommu_type1_dma_rw_chunk(iommu, user_iova, data,
This is only optimizing a case that shouldn't exist, the return value
is the same. Callers should be smart enough not to call the function
with such values. As an internal API, we assume reasonable behavior by
the caller. Thanks,
Alex
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-23 13:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-23 7:24 [PATCH] vfio_iommu_type1: increase the validity check of function parameters Li kunyu
2022-12-23 13:28 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox