2018-03-05 16:20:52

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] VMCI: Adjustments for three function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 5 Mar 2018 17:12:34 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use memdup_user() rather than duplicating its implementation
Improve a size determination in two functions

drivers/misc/vmw_vmci/vmci_context.c | 2 +-
drivers/misc/vmw_vmci/vmci_host.c | 21 +++++----------------
2 files changed, 6 insertions(+), 17 deletions(-)

--
2.16.2



2018-03-05 16:22:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] VMCI: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Mon, 5 Mar 2018 16:40:29 +0100

* Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

* Return directly after this function call failed at the beginning.

* Delete the label "out" which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_host.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 83e0c95d20a4..fb3d92a21afa 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -754,27 +754,16 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev,
if (copy_from_user(&set_info, uptr, sizeof(set_info)))
return -EFAULT;

- cpt_buf = kmalloc(set_info.buf_size, GFP_KERNEL);
- if (!cpt_buf) {
- vmci_ioctl_err(
- "cannot allocate memory to set cpt state (type=%d)\n",
- set_info.cpt_type);
- return -ENOMEM;
- }
-
- if (copy_from_user(cpt_buf, (void __user *)(uintptr_t)set_info.cpt_buf,
- set_info.buf_size)) {
- retval = -EFAULT;
- goto out;
- }
+ cpt_buf = memdup_user((void __user *)(uintptr_t)set_info.cpt_buf,
+ set_info.buf_size);
+ if (IS_ERR(cpt_buf))
+ return PTR_ERR(cpt_buf);

cid = vmci_ctx_get_id(vmci_host_dev->context);
set_info.result = vmci_ctx_set_chkpt_state(cid, set_info.cpt_type,
set_info.buf_size, cpt_buf);

retval = copy_to_user(uptr, &set_info, sizeof(set_info)) ? -EFAULT : 0;
-
-out:
kfree(cpt_buf);
return retval;
}
--
2.16.2


2018-03-05 16:24:25

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] VMCI: Improve a size determination in two functions

From: Markus Elfring <[email protected]>
Date: Mon, 5 Mar 2018 17:00:19 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_context.c | 2 +-
drivers/misc/vmw_vmci/vmci_host.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
index 21d0fa592145..18404318dd71 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -620,7 +620,7 @@ int vmci_ctx_add_notification(u32 context_id, u32 remote_cid)
goto out;
}

- notifier = kmalloc(sizeof(struct vmci_handle_list), GFP_KERNEL);
+ notifier = kmalloc(sizeof(*notifier), GFP_KERNEL);
if (!notifier) {
result = VMCI_ERROR_NO_MEM;
goto out;
diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index fb3d92a21afa..12419f97681d 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -124,7 +124,7 @@ static int vmci_host_open(struct inode *inode, struct file *filp)
{
struct vmci_host_dev *vmci_host_dev;

- vmci_host_dev = kzalloc(sizeof(struct vmci_host_dev), GFP_KERNEL);
+ vmci_host_dev = kzalloc(sizeof(*vmci_host_dev), GFP_KERNEL);
if (vmci_host_dev == NULL)
return -ENOMEM;

--
2.16.2