* [PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()
@ 2024-09-25 18:48 Markus Elfring
2024-09-25 20:50 ` Al Viro
0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2024-09-25 18:48 UTC (permalink / raw)
To: virtualization, kvm, netdev, Eugenio Pérez, Jason Wang,
Michael S. Tsirkin, Tiwei Bie
Cc: LKML, kernel-janitors
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(-)
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()
2024-09-25 18:48 [PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config() Markus Elfring
@ 2024-09-25 20:50 ` Al Viro
2024-09-26 6:04 ` Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2024-09-25 20:50 UTC (permalink / raw)
To: Markus Elfring
Cc: virtualization, kvm, netdev, Eugenio Pérez, Jason Wang,
Michael S. Tsirkin, Tiwei Bie, LKML, kernel-janitors
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)...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()
2024-09-25 20:50 ` Al Viro
@ 2024-09-26 6:04 ` Markus Elfring
0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-09-26 6:04 UTC (permalink / raw)
To: Al Viro, virtualization, kvm, netdev, Eugenio Pérez,
Jason Wang, Michael S. Tsirkin
Cc: LKML, kernel-janitors
>> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-26 6:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25 18:48 [PATCH] vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config() Markus Elfring
2024-09-25 20:50 ` Al Viro
2024-09-26 6:04 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).