Re: [PATCH v2 3/3] userfaultfd: remove redundant check in vm_uffd_ops()
From: Lorenzo Stoakes
Date: Thu May 28 2026 - 09:16:29 EST
On Wed, May 27, 2026 at 09:47:51PM +0300, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx>
>
> Lorenzo says:
>
> static const struct vm_uffd_ops *vma_uffd_ops(struct vm_area_struct *vma)
> {
> if (vma_is_anonymous(vma))
> return &anon_uffd_ops;
> return vma->vm_ops ? vma->vm_ops->uffd_ops : NULL;
> }
>
> This is doing a redundant check _and_ making life confusing, as if
> !vma->vm_ops is a condition that can be reached there, it can't, as
> vma_is_anonymous() is literally a !vma->vm_ops check :)
>
> Remove the redundant check.
>
> Suggested-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> Fixes: 0f48947c4232 ("userfaultfd: introduce vm_uffd_ops")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
:) thanks! LGTM so:
Reviewed-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> ---
> mm/userfaultfd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index 2872c71bbf36..80cc8be5725f 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -68,7 +68,7 @@ static const struct vm_uffd_ops *vma_uffd_ops(struct vm_area_struct *vma)
> {
> if (vma_is_anonymous(vma))
> return &anon_uffd_ops;
> - return vma->vm_ops ? vma->vm_ops->uffd_ops : NULL;
> + return vma->vm_ops->uffd_ops;
> }
>
> static __always_inline
> --
> 2.53.0
>
Cheers, Lorenzo