[PATCH v5 1/4] kernfs: add a WARN_ON_ONCE if ->close is set

From: Martin Oliveira
Date: Thu Aug 08 2024 - 14:34:09 EST


The next patch is going to remove .page_mkwrite from kernfs and will
WARN if an mmap implementation sets .page_mkwrite.

In preparation for that change, and to make it consistent, add a WARN to
the ->close check.

Co-developed-by: Logan Gunthorpe <logang@xxxxxxxxxxxx>
Signed-off-by: Logan Gunthorpe <logang@xxxxxxxxxxxx>
Signed-off-by: Martin Oliveira <martin.oliveira@xxxxxxxxxxxxx>
---
fs/kernfs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index 8502ef68459b..72cc51dcf870 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -479,7 +479,7 @@ static int kernfs_fop_mmap(struct file *file, struct vm_area_struct *vma)
* It is not possible to successfully wrap close.
* So error if someone is trying to use close.
*/
- if (vma->vm_ops && vma->vm_ops->close)
+ if (WARN_ON_ONCE(vma->vm_ops && vma->vm_ops->close))
goto out_put;

rc = 0;
--
2.43.0