iommufd/selftest: Use fdget() and fdput()
PATCH 1/1 iommufd/selftest: Use fdget() and fdput()
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
Signed-off-by Ye Xingchen <[email protected]>
--- drivers/iommu/iommufd/selftest.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/iommu/iommufd/selftest.c +5 -6
@@ -583,17 +583,16 @@ static const struct file_operations iommfd_test_staccess_fops;static struct selftest_access *iommufd_access_get (int fd) { -struct file *file; +struct fd f =fdget (fd); - file =fget (fd); -if (!file) +if (!f.file)return ERR_PTR (-EBADFD ); -if (file->f_op != &iommfd_test_staccess_fops) { -fput (file); +if (f.file->f_op != &iommfd_test_staccess_fops) { +fdput (f);return ERR_PTR (-EBADFD ); } -return file->private_data; +return f.file->private_data; } static void iommufd_test_access_unmap(void *data, unsigned long iova,
Signature · 1 line
2.25.1
Quoted 14 lines · On Fri, May 05, 2023 at 02:12:39PM +0800, [email protected] wrote:
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
Signed-off-by Ye Xingchen <[email protected]>--- drivers/iommu/iommufd/selftest.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/iommu/iommufd/selftest.c +0
-0
drivers/iommu/iommufd/selftest.c static const struct file_operations iommfd_test_staccess_fops; · line 589
Quoted 10 lines
drivers/iommu/iommufd/selftest.c +2
-3@@ -583,17 +583,16 @@ static const struct file_operations iommfd_test_staccess_fops;static struct selftest_access *iommufd_access_get (int fd) { -struct file *file; +struct fd f =fdget (fd); - file =fget (fd); -if (!file) +if (!f.file)return ERR_PTR (-EBADFD );
Why are you doing these conversions? This is wrong, fdget has to be paired with fdput(), since the struct fd doesn't leave the stack frame it cannot be correct.
I see your other patches have the same problem.
Jason