Re: [RFC PATCH] vfio: type1: fix kthread use case

From: Markus Elfring
Date: Mon Jul 06 2020 - 09:34:49 EST


>> Can it be helpful to convert initialisations for these variables
>> into later assignments?
>
> Perhaps. Then it looks like the below.


â
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2798,9 +2798,12 @@ static int vfio_iommu_type1_dma_rw_chunk
â
> - bool kthread = current->mm == NULL;
> + bool kthread;
> + bool use_mm;

I would prefer the following variable declarations then.

+ bool kthread, use_mm;


> size_t offset;
>
> + kthread = current->flags & PF_KTHREAD;
> + use_mm = current->mm == NULL;

I propose to move such assignments directly before the corresponding check.


â
> if (!mm)
> return -EPERM;


+ kthread = current->flags & PF_KTHREAD;
+ use_mm = !current->mm;

> - if (kthread)
> + if (kthread && use_mm)
> kthread_use_mm(mm);
â

Regards,
Markus