vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()
Subsystems (6)
PATCH 1/1 vhost-vdpa: Refactor copy_to_user() usage in vhost_vdpa_get_config()
From: Markus Elfring <[email protected]>
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.
--- drivers/vhost/vdpa.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/vhost/vdpa.c +3 -5
@@ -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
Quoted 6 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 25 Sep 2024 20:36:35 +0200Assign the return value from a
copy_to_user()call to an additional local variable so that akvfree()call and return statement can be omitted accordingly.
Ugly and unidiomatic.
Quoted 1 line
This issue was detected by using the Coccinelle software.
What issue?
Quoted 1 line
Signed-off-by Markus Elfring <[email protected]>
Nevermind (and I really need more coffee, seeing that I'd missed the obvious indicator of garbage and failed to hit delete)...
Quoted 9 lines
Quoted 3 lines
Assign the return value from a
copy_to_user()call to an additional local variable so that akvfree()call and return statement can be omitted accordingly.Ugly and unidiomatic.
Quoted 1 line
This issue was detected by using the Coccinelle software.
What issue?
Opportunities for the reduction of duplicate source code.
Regards,
Markus