AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND] amdkfd: check ret code for ioctls
@ 2024-10-31 10:50 Zhu Lingshan
  2024-10-31 15:30 ` Felix Kuehling
  0 siblings, 1 reply; 9+ messages in thread
From: Zhu Lingshan @ 2024-10-31 10:50 UTC (permalink / raw)
  To: Felix.Kuehling, alexander.deucher; +Cc: ray.huang, amd-gfx, Zhu Lingshan

The ioctl functions may fail, causing the args unreliable.
Therefore, the args should not be copied to user space.

The return code provides enough information for
error handling in user space.

This commit checks the return code of the ioctl functions
and handles errors appropriately when they fail.

Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 3e6b4736a7fe..a184ca0023b5 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -3327,6 +3327,8 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 	}
 
 	retcode = func(filep, process, kdata);
+	if (retcode)
+		goto err_retcode;
 
 	if (cmd & IOC_OUT)
 		if (copy_to_user((void __user *)arg, kdata, usize) != 0)
@@ -3340,6 +3342,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 	if (kdata != stack_kdata)
 		kfree(kdata);
 
+err_retcode:
 	if (retcode)
 		dev_dbg(kfd_device, "ioctl cmd (#0x%x), arg 0x%lx, ret = %d\n",
 				nr, arg, retcode);
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-11-13  3:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-31 10:50 [RESEND] amdkfd: check ret code for ioctls Zhu Lingshan
2024-10-31 15:30 ` Felix Kuehling
2024-11-01  2:35   ` Zhu Lingshan
2024-11-04 20:50     ` Felix Kuehling
2024-11-11  8:08       ` Zhu Lingshan
2024-11-11 22:21         ` Felix Kuehling
2024-11-12  7:35           ` Zhu Lingshan
2024-11-12 23:46             ` Felix Kuehling
2024-11-13  3:35               ` Zhu Lingshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox