diff mbox series

vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()

Message ID 79b2f48a-f6a1-4bfc-9a8d-cb09777f2a07@web.de (mailing list archive)
State Rejected
Headers show
Series vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Markus Elfring Sept. 25, 2024, 6:48 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 drivers/vhost/vdpa.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

--
2.46.1

Comments

Al Viro Sept. 25, 2024, 8:50 p.m. UTC | #1
On Wed, Sep 25, 2024 at 08:48:16PM +0200, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.

Ugly and unidiomatic.

> This issue was detected by using the Coccinelle software.

What issue?

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Nevermind (and I really need more coffee, seeing that I'd missed the
obvious indicator of garbage and failed to hit delete)...
Markus Elfring Sept. 26, 2024, 6:04 a.m. UTC | #2
>> 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.
>
> Ugly and unidiomatic.
>
>> This issue was detected by using the Coccinelle software.
>
> What issue?

Opportunities for the reduction of duplicate source code.

Regards,
Markus
diff mbox series

Patch

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,