Thread (3 messages) 3 messages, 2 authors, 2024-09-26
STALE621d

[PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()

From: Markus Elfring <hidden>
Date: 2024-09-25 18:48:37
Also in: kernel-janitors, kvm, lkml, virtualization
Subsystem: the rest, virtio host (vhost) · Maintainers: Linus Torvalds, "Michael S. Tsirkin", Jason Wang

From: Markus Elfring <redacted>
Date: Wed, 25 Sep 2024 20:36:35 +0200

Assign the return value from a copy_to_user() call to an additional
local variable so that a kvfree() call and return statement can be
omitted accordingly.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/vhost/vdpa.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 5a49b5a6d496..ca69527a822c 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -370,13 +370,11 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v,

 	vdpa_get_config(vdpa, config.off, buf, config.len);

-	if (copy_to_user(c->buf, buf, config.len)) {
+	{
+		unsigned long ctu = copy_to_user(c->buf, buf, config.len);
 		kvfree(buf);
-		return -EFAULT;
+		return ctu ? -EFAULT : 0;
 	}
-
-	kvfree(buf);
-	return 0;
 }

 static long vhost_vdpa_set_config(struct vhost_vdpa *v,
--
2.46.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help