2018-01-10 19:23:44

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/7] VMCI: Adjustments for several function implementations

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 20:13:45 +0100

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

Markus Elfring (7):
Delete error messages for a failed memory allocation in seven functions
Improve a size determination in two functions
Update a word in five comment lines
Delete an unnecessary null pointer check in qp_broker_create()
Delete an unnecessary variable initialisation in qp_broker_create()
Less function calls in qp_broker_create() after error detection
Adjust 32 checks for null pointers

drivers/misc/vmw_vmci/vmci_context.c | 24 +++++++-------
drivers/misc/vmw_vmci/vmci_datagram.c | 14 ++++----
drivers/misc/vmw_vmci/vmci_doorbell.c | 8 ++---
drivers/misc/vmw_vmci/vmci_guest.c | 16 +++------
drivers/misc/vmw_vmci/vmci_host.c | 10 ++----
drivers/misc/vmw_vmci/vmci_queue_pair.c | 57 ++++++++++++++++-----------------
6 files changed, 54 insertions(+), 75 deletions(-)

--
2.15.1


2018-01-10 19:25:17

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/7] VMCI: Delete error messages for a failed memory allocation in seven functions

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 17:33:39 +0100

Omit extra messages for a memory allocation failure in these functions.

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_datagram.c | 4 +---
drivers/misc/vmw_vmci/vmci_doorbell.c | 4 +---
drivers/misc/vmw_vmci/vmci_guest.c | 14 +++-----------
drivers/misc/vmw_vmci/vmci_host.c | 6 +-----
5 files changed, 6 insertions(+), 24 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
index 21d0fa592145..c0ea68255340 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -111,7 +111,6 @@ struct vmci_ctx *vmci_ctx_create(u32 cid, u32 priv_flags,

context = kzalloc(sizeof(*context), GFP_KERNEL);
if (!context) {
- pr_warn("Failed to allocate memory for VMCI context\n");
error = -EINVAL;
goto err_out;
}
@@ -318,7 +317,6 @@ int vmci_ctx_enqueue_datagram(u32 cid, struct vmci_datagram *dg)
/* Allocate guest call entry and add it to the target VM's queue. */
dq_entry = kmalloc(sizeof(*dq_entry), GFP_KERNEL);
if (dq_entry == NULL) {
- pr_warn("Failed to allocate memory for datagram\n");
vmci_ctx_put(context);
return VMCI_ERROR_NO_MEM;
}
diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c
index 8a4b6bbe1bee..fbe145e2d125 100644
--- a/drivers/misc/vmw_vmci/vmci_datagram.c
+++ b/drivers/misc/vmw_vmci/vmci_datagram.c
@@ -80,10 +80,8 @@ static int dg_create_handle(u32 resource_id,
handle = vmci_make_handle(context_id, resource_id);

entry = kmalloc(sizeof(*entry), GFP_KERNEL);
- if (!entry) {
- pr_warn("Failed allocating memory for datagram entry\n");
+ if (!entry)
return VMCI_ERROR_NO_MEM;
- }

entry->run_delayed = (flags & VMCI_FLAG_DG_DELAYED_CB) ? true : false;
entry->flags = flags;
diff --git a/drivers/misc/vmw_vmci/vmci_doorbell.c b/drivers/misc/vmw_vmci/vmci_doorbell.c
index b3fa738ae005..46607ffc94db 100644
--- a/drivers/misc/vmw_vmci/vmci_doorbell.c
+++ b/drivers/misc/vmw_vmci/vmci_doorbell.c
@@ -423,10 +423,8 @@ int vmci_doorbell_create(struct vmci_handle *handle,
return VMCI_ERROR_INVALID_ARGS;

entry = kmalloc(sizeof(*entry), GFP_KERNEL);
- if (entry == NULL) {
- pr_warn("Failed allocating memory for datagram entry\n");
+ if (!entry)
return VMCI_ERROR_NO_MEM;
- }

if (vmci_handle_is_invalid(*handle)) {
u32 context_id = vmci_get_context_id();
diff --git a/drivers/misc/vmw_vmci/vmci_guest.c b/drivers/misc/vmw_vmci/vmci_guest.c
index dad5abee656e..ba18e727c401 100644
--- a/drivers/misc/vmw_vmci/vmci_guest.c
+++ b/drivers/misc/vmw_vmci/vmci_guest.c
@@ -170,10 +170,8 @@ static int vmci_check_host_caps(struct pci_dev *pdev)
struct vmci_datagram *check_msg;

check_msg = kmalloc(msg_size, GFP_KERNEL);
- if (!check_msg) {
- dev_err(&pdev->dev, "%s: Insufficient memory\n", __func__);
+ if (!check_msg)
return -ENOMEM;
- }

check_msg->dst = vmci_make_handle(VMCI_HYPERVISOR_CONTEXT_ID,
VMCI_RESOURCES_QUERY);
@@ -457,11 +455,8 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
(unsigned long)iobase, pdev->irq);

vmci_dev = devm_kzalloc(&pdev->dev, sizeof(*vmci_dev), GFP_KERNEL);
- if (!vmci_dev) {
- dev_err(&pdev->dev,
- "Can't allocate memory for VMCI device\n");
+ if (!vmci_dev)
return -ENOMEM;
- }

vmci_dev->dev = &pdev->dev;
vmci_dev->exclusive_vectors = false;
@@ -473,11 +468,8 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
vmci_process_bitmap, (unsigned long)vmci_dev);

vmci_dev->data_buffer = vmalloc(VMCI_MAX_DG_SIZE);
- if (!vmci_dev->data_buffer) {
- dev_err(&pdev->dev,
- "Can't allocate memory for datagram buffer\n");
+ if (!vmci_dev->data_buffer)
return -ENOMEM;
- }

pci_set_master(pdev); /* To enable queue_pair functionality. */

diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 6640e7651533..4246a033de18 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -755,12 +755,8 @@ static int vmci_host_do_ctx_set_cpt_state(struct vmci_host_dev *vmci_host_dev,
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);
+ if (!cpt_buf)
return -ENOMEM;
- }

if (copy_from_user(cpt_buf, (void __user *)(uintptr_t)set_info.cpt_buf,
set_info.buf_size)) {
--
2.15.1

2018-01-10 19:26:25

by SF Markus Elfring

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

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 17:47:40 +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 c0ea68255340..c7085ff76327 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -618,7 +618,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 4246a033de18..14da8210fd34 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.15.1

2018-01-10 19:27:43

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/7] VMCI: Update a word in five comment lines

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 18:15:43 +0100

Adjust words in these descriptions.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_datagram.c | 2 +-
drivers/misc/vmw_vmci/vmci_doorbell.c | 2 +-
drivers/misc/vmw_vmci/vmci_queue_pair.c | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c
index fbe145e2d125..88f39305b32e 100644
--- a/drivers/misc/vmw_vmci/vmci_datagram.c
+++ b/drivers/misc/vmw_vmci/vmci_datagram.c
@@ -438,7 +438,7 @@ EXPORT_SYMBOL_GPL(vmci_datagram_create_handle_priv);
* @out_handle: vmci_handle that is populated as a result of this function.
*
* Creates a host context datagram endpoint and returns a handle to
- * it. Same as vmci_datagram_create_handle_priv without the priviledge
+ * it. Same as vmci_datagram_create_handle_priv without the privilege
* flags argument.
*/
int vmci_datagram_create_handle(u32 resource_id,
diff --git a/drivers/misc/vmw_vmci/vmci_doorbell.c b/drivers/misc/vmw_vmci/vmci_doorbell.c
index 46607ffc94db..c0f9aa2c0abc 100644
--- a/drivers/misc/vmw_vmci/vmci_doorbell.c
+++ b/drivers/misc/vmw_vmci/vmci_doorbell.c
@@ -571,7 +571,7 @@ EXPORT_SYMBOL_GPL(vmci_doorbell_destroy);
/*
* vmci_doorbell_notify() - Ring the doorbell (and hide in the bushes).
* @dst: The handlle identifying the doorbell resource
- * @priv_flags: Priviledge flags.
+ * @priv_flags: Privilege flags.
*
* Generates a notification on the doorbell identified by the
* handle. For host side generation of notifications, the caller
diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 0339538c182d..381e25c69c1f 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -2532,7 +2532,7 @@ static bool qp_wait_for_ready_queue(struct vmci_qp *qpair)
* VMCI_ERROR_QUEUEPAIR_NOSPACE if no space was available to enqueue
* data, VMCI_ERROR_INVALID_SIZE, if any queue pointer is outside the
* queue (as defined by the queue size), VMCI_ERROR_INVALID_ARGS, if
- * an error occured when accessing the buffer,
+ * an error occurred when accessing the buffer,
* VMCI_ERROR_QUEUEPAIR_NOTATTACHED, if the queue pair pages aren't
* available. Otherwise, the number of bytes written to the queue is
* returned. Updates the tail pointer of the produce queue.
@@ -2592,7 +2592,7 @@ static ssize_t qp_enqueue_locked(struct vmci_queue *produce_q,
* VMCI_ERROR_QUEUEPAIR_NODATA if no data was available to dequeue.
* VMCI_ERROR_INVALID_SIZE, if any queue pointer is outside the queue
* (as defined by the queue size).
- * VMCI_ERROR_INVALID_ARGS, if an error occured when accessing the buffer.
+ * VMCI_ERROR_INVALID_ARGS, if an error occurred when accessing the buffer.
* Otherwise the number of bytes dequeued is returned.
* Side effects:
* Updates the head pointer of the consume queue.
@@ -2656,7 +2656,7 @@ static ssize_t qp_dequeue_locked(struct vmci_queue *produce_q,
* @consume_qsize: Desired size of the consumer queue.
* @peer: ContextID of the peer.
* @flags: VMCI flags.
- * @priv_flags: VMCI priviledge flags.
+ * @priv_flags: VMCI privilege flags.
*
* This is the client interface for allocating the memory for a
* vmci_qp structure and then attaching to the underlying
--
2.15.1

2018-01-10 19:29:03

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/7] VMCI: Delete an unnecessary null pointer check in qp_broker_create()

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 19:00:24 +0100

The exception handling code should usually only be reached with a valid
pointer in the local variable "entry" at the end of this function.
Thus remove an extra null pointer check here.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_queue_pair.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 381e25c69c1f..7d4437240099 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -1434,12 +1434,9 @@ static int qp_broker_create(struct vmci_handle handle,
return VMCI_SUCCESS;

error:
- if (entry != NULL) {
- qp_host_free_queue(entry->produce_q, guest_produce_size);
- qp_host_free_queue(entry->consume_q, guest_consume_size);
- kfree(entry);
- }
-
+ qp_host_free_queue(entry->produce_q, guest_produce_size);
+ qp_host_free_queue(entry->consume_q, guest_consume_size);
+ kfree(entry);
return result;
}

--
2.15.1

2018-01-10 19:30:07

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/7] VMCI: Delete an unnecessary variable initialisation in qp_broker_create()

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 19:09:10 +0100

The local variable "entry" will eventually be set to an appropriate pointer
a bit later. Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_queue_pair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 7d4437240099..5546274dec5d 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -1291,7 +1291,7 @@ static int qp_broker_create(struct vmci_handle handle,
vmci_event_release_cb wakeup_cb,
void *client_data, struct qp_broker_entry **ent)
{
- struct qp_broker_entry *entry = NULL;
+ struct qp_broker_entry *entry;
const u32 context_id = vmci_ctx_get_id(context);
bool is_local = flags & VMCI_QPFLAG_LOCAL;
int result;
--
2.15.1

2018-01-10 19:31:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 6/7] VMCI: Less function calls in qp_broker_create() after error detection

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 19:39:45 +0100

The function "qp_host_free_queue" was called in two cases
by the function "qp_broker_create" during error handling even if
the passed data structure member contained a null pointer.

Adjust jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_queue_pair.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 5546274dec5d..9b7dcad38f3d 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -1358,12 +1358,12 @@ static int qp_broker_create(struct vmci_handle handle,
entry->produce_q = qp_host_alloc_queue(guest_produce_size);
if (entry->produce_q == NULL) {
result = VMCI_ERROR_NO_MEM;
- goto error;
+ goto free_entry;
}
entry->consume_q = qp_host_alloc_queue(guest_consume_size);
if (entry->consume_q == NULL) {
result = VMCI_ERROR_NO_MEM;
- goto error;
+ goto free_produce_queue;
}

qp_init_queue_mutex(entry->produce_q, entry->consume_q);
@@ -1377,7 +1377,7 @@ static int qp_broker_create(struct vmci_handle handle,
PAGE_SIZE, GFP_KERNEL);
if (entry->local_mem == NULL) {
result = VMCI_ERROR_NO_MEM;
- goto error;
+ goto free_consume_queue;
}
entry->state = VMCIQPB_CREATED_MEM;
entry->produce_q->q_header = entry->local_mem;
@@ -1393,7 +1393,7 @@ static int qp_broker_create(struct vmci_handle handle,
entry->produce_q,
entry->consume_q);
if (result < VMCI_SUCCESS)
- goto error;
+ goto free_consume_queue;

entry->state = VMCIQPB_CREATED_MEM;
} else {
@@ -1418,7 +1418,7 @@ static int qp_broker_create(struct vmci_handle handle,
if (result != VMCI_SUCCESS) {
pr_warn("Failed to add new resource (handle=0x%x:0x%x), error: %d",
handle.context, handle.resource, result);
- goto error;
+ goto free_consume_queue;
}

entry->qp.handle = vmci_resource_handle(&entry->resource);
@@ -1433,9 +1433,11 @@ static int qp_broker_create(struct vmci_handle handle,

return VMCI_SUCCESS;

- error:
- qp_host_free_queue(entry->produce_q, guest_produce_size);
+free_consume_queue:
qp_host_free_queue(entry->consume_q, guest_consume_size);
+free_produce_queue:
+ qp_host_free_queue(entry->produce_q, guest_produce_size);
+free_entry:
kfree(entry);
return result;
}
--
2.15.1

2018-01-10 19:32:43

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 7/7] VMCI: Adjust 32 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Wed, 10 Jan 2018 20:04:02 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written …

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/vmw_vmci/vmci_context.c | 20 ++++++++++----------
drivers/misc/vmw_vmci/vmci_datagram.c | 8 ++++----
drivers/misc/vmw_vmci/vmci_doorbell.c | 2 +-
drivers/misc/vmw_vmci/vmci_guest.c | 2 +-
drivers/misc/vmw_vmci/vmci_host.c | 2 +-
drivers/misc/vmw_vmci/vmci_queue_pair.c | 26 ++++++++++++--------------
6 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
index c7085ff76327..055e4491093c 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -212,7 +212,7 @@ static int ctx_fire_notification(u32 context_id, u32 priv_flags)
* scanning through all contexts.
*/
subscriber_array = vmci_handle_arr_create(0);
- if (subscriber_array == NULL)
+ if (!subscriber_array)
return VMCI_ERROR_NO_MEM;

/*
@@ -279,7 +279,7 @@ int vmci_ctx_pending_datagrams(u32 cid, u32 *pending)
struct vmci_ctx *context;

context = vmci_ctx_get(cid);
- if (context == NULL)
+ if (!context)
return VMCI_ERROR_INVALID_ARGS;

spin_lock(&context->lock);
@@ -316,7 +316,7 @@ int vmci_ctx_enqueue_datagram(u32 cid, struct vmci_datagram *dg)

/* Allocate guest call entry and add it to the target VM's queue. */
dq_entry = kmalloc(sizeof(*dq_entry), GFP_KERNEL);
- if (dq_entry == NULL) {
+ if (!dq_entry) {
vmci_ctx_put(context);
return VMCI_ERROR_NO_MEM;
}
@@ -860,7 +860,7 @@ int vmci_ctx_rcv_notifications_get(u32 context_id,
int result = VMCI_SUCCESS;

context = vmci_ctx_get(context_id);
- if (context == NULL)
+ if (!context)
return VMCI_ERROR_NOT_FOUND;

spin_lock(&context->lock);
@@ -944,7 +944,7 @@ int vmci_ctx_dbell_create(u32 context_id, struct vmci_handle handle)
return VMCI_ERROR_INVALID_ARGS;

context = vmci_ctx_get(context_id);
- if (context == NULL)
+ if (!context)
return VMCI_ERROR_NOT_FOUND;

spin_lock(&context->lock);
@@ -974,7 +974,7 @@ int vmci_ctx_dbell_destroy(u32 context_id, struct vmci_handle handle)
return VMCI_ERROR_INVALID_ARGS;

context = vmci_ctx_get(context_id);
- if (context == NULL)
+ if (!context)
return VMCI_ERROR_NOT_FOUND;

spin_lock(&context->lock);
@@ -1002,7 +1002,7 @@ int vmci_ctx_dbell_destroy_all(u32 context_id)
return VMCI_ERROR_INVALID_ARGS;

context = vmci_ctx_get(context_id);
- if (context == NULL)
+ if (!context)
return VMCI_ERROR_NOT_FOUND;

spin_lock(&context->lock);
@@ -1121,7 +1121,7 @@ int vmci_ctx_qp_create(struct vmci_ctx *context, struct vmci_handle handle)
{
int result;

- if (context == NULL || vmci_handle_is_invalid(handle))
+ if (!context || vmci_handle_is_invalid(handle))
return VMCI_ERROR_INVALID_ARGS;

if (!vmci_handle_arr_has_entry(context->queue_pair_array, handle)) {
@@ -1143,7 +1143,7 @@ int vmci_ctx_qp_destroy(struct vmci_ctx *context, struct vmci_handle handle)
{
struct vmci_handle hndl;

- if (context == NULL || vmci_handle_is_invalid(handle))
+ if (!context || vmci_handle_is_invalid(handle))
return VMCI_ERROR_INVALID_ARGS;

hndl = vmci_handle_arr_remove_entry(context->queue_pair_array, handle);
@@ -1158,7 +1158,7 @@ int vmci_ctx_qp_destroy(struct vmci_ctx *context, struct vmci_handle handle)
*/
bool vmci_ctx_qp_exists(struct vmci_ctx *context, struct vmci_handle handle)
{
- if (context == NULL || vmci_handle_is_invalid(handle))
+ if (!context || vmci_handle_is_invalid(handle))
return false;

return vmci_handle_arr_has_entry(context->queue_pair_array, handle);
diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c
index 88f39305b32e..e3f97fc72565 100644
--- a/drivers/misc/vmw_vmci/vmci_datagram.c
+++ b/drivers/misc/vmw_vmci/vmci_datagram.c
@@ -275,7 +275,7 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg)

/* We make a copy to enqueue. */
new_dg = kmemdup(dg, dg_size, GFP_KERNEL);
- if (new_dg == NULL)
+ if (!new_dg)
return VMCI_ERROR_NO_MEM;

retval = vmci_ctx_enqueue_datagram(dg->dst.context, new_dg);
@@ -413,10 +413,10 @@ int vmci_datagram_create_handle_priv(u32 resource_id,
void *client_data,
struct vmci_handle *out_handle)
{
- if (out_handle == NULL)
+ if (!out_handle)
return VMCI_ERROR_INVALID_ARGS;

- if (recv_cb == NULL) {
+ if (!recv_cb) {
pr_devel("Client callback needed when creating datagram\n");
return VMCI_ERROR_INVALID_ARGS;
}
@@ -492,7 +492,7 @@ EXPORT_SYMBOL_GPL(vmci_datagram_destroy_handle);
*/
int vmci_datagram_send(struct vmci_datagram *msg)
{
- if (msg == NULL)
+ if (!msg)
return VMCI_ERROR_INVALID_ARGS;

return vmci_datagram_dispatch(VMCI_INVALID_ID, msg, false);
diff --git a/drivers/misc/vmw_vmci/vmci_doorbell.c b/drivers/misc/vmw_vmci/vmci_doorbell.c
index c0f9aa2c0abc..aacf6ab52c20 100644
--- a/drivers/misc/vmw_vmci/vmci_doorbell.c
+++ b/drivers/misc/vmw_vmci/vmci_doorbell.c
@@ -92,7 +92,7 @@ static u32 last_notify_idx_released = PAGE_SIZE;
*/
int vmci_dbell_get_priv_flags(struct vmci_handle handle, u32 *priv_flags)
{
- if (priv_flags == NULL || handle.context == VMCI_INVALID_ID)
+ if (!priv_flags || handle.context == VMCI_INVALID_ID)
return VMCI_ERROR_INVALID_ARGS;

if (handle.context == VMCI_HOST_CONTEXT_ID) {
diff --git a/drivers/misc/vmw_vmci/vmci_guest.c b/drivers/misc/vmw_vmci/vmci_guest.c
index ba18e727c401..6ea3dd9de644 100644
--- a/drivers/misc/vmw_vmci/vmci_guest.c
+++ b/drivers/misc/vmw_vmci/vmci_guest.c
@@ -100,7 +100,7 @@ int vmci_send_datagram(struct vmci_datagram *dg)
int result;

/* Check args. */
- if (dg == NULL)
+ if (!dg)
return VMCI_ERROR_INVALID_ARGS;

/*
diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 14da8210fd34..903d877415cd 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -125,7 +125,7 @@ static int vmci_host_open(struct inode *inode, struct file *filp)
struct vmci_host_dev *vmci_host_dev;

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

vmci_host_dev->ct_type = VMCIOBJ_NOT_SET;
diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 9b7dcad38f3d..fd86e97cc966 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -755,15 +755,15 @@ static int qp_host_map_queues(struct vmci_queue *produce_q,
if (produce_q->q_header != consume_q->q_header)
return VMCI_ERROR_QUEUEPAIR_MISMATCH;

- if (produce_q->kernel_if->u.h.header_page == NULL ||
- *produce_q->kernel_if->u.h.header_page == NULL)
+ if (!produce_q->kernel_if->u.h.header_page ||
+ !*produce_q->kernel_if->u.h.header_page)
return VMCI_ERROR_UNAVAILABLE;

headers[0] = *produce_q->kernel_if->u.h.header_page;
headers[1] = *consume_q->kernel_if->u.h.header_page;

produce_q->q_header = vmap(headers, 2, VM_MAP, PAGE_KERNEL);
- if (produce_q->q_header != NULL) {
+ if (produce_q->q_header) {
consume_q->q_header =
(struct vmci_queue_header *)((u8 *)
produce_q->q_header +
@@ -1356,12 +1356,12 @@ static int qp_broker_create(struct vmci_handle handle,
entry->wakeup_cb = wakeup_cb;
entry->client_data = client_data;
entry->produce_q = qp_host_alloc_queue(guest_produce_size);
- if (entry->produce_q == NULL) {
+ if (!entry->produce_q) {
result = VMCI_ERROR_NO_MEM;
goto free_entry;
}
entry->consume_q = qp_host_alloc_queue(guest_consume_size);
- if (entry->consume_q == NULL) {
+ if (!entry->consume_q) {
result = VMCI_ERROR_NO_MEM;
goto free_produce_queue;
}
@@ -1375,7 +1375,7 @@ static int qp_broker_create(struct vmci_handle handle,

entry->local_mem = kcalloc(QPE_NUM_PAGES(entry->qp),
PAGE_SIZE, GFP_KERNEL);
- if (entry->local_mem == NULL) {
+ if (!entry->local_mem) {
result = VMCI_ERROR_NO_MEM;
goto free_consume_queue;
}
@@ -1408,7 +1408,7 @@ static int qp_broker_create(struct vmci_handle handle,
}

qp_list_add_entry(&qp_broker_list, &entry->qp);
- if (ent != NULL)
+ if (ent)
*ent = entry;

/* Add to resource obj */
@@ -1626,7 +1626,7 @@ static int qp_broker_attach(struct qp_broker_entry *entry,
if (entry->state != VMCIQPB_CREATED_NO_MEM)
return VMCI_ERROR_INVALID_ARGS;

- if (page_store != NULL) {
+ if (page_store) {
/*
* Patch up host state to point to guest
* supplied memory. The VMX already
@@ -1682,7 +1682,7 @@ static int qp_broker_attach(struct qp_broker_entry *entry,
if (!is_local)
vmci_ctx_qp_create(context, entry->qp.handle);

- if (ent != NULL)
+ if (ent)
*ent = entry;

return VMCI_SUCCESS;
@@ -2282,8 +2282,7 @@ static int qp_save_headers(struct qp_broker_entry *entry)
{
int result;

- if (entry->produce_q->saved_header != NULL &&
- entry->consume_q->saved_header != NULL) {
+ if (entry->produce_q->saved_header && entry->consume_q->saved_header) {
/*
* If the headers have already been saved, we don't need to do
* it again, and we don't want to map in the headers
@@ -2293,8 +2292,7 @@ static int qp_save_headers(struct qp_broker_entry *entry)
return VMCI_SUCCESS;
}

- if (NULL == entry->produce_q->q_header ||
- NULL == entry->consume_q->q_header) {
+ if (!entry->produce_q->q_header || !entry->consume_q->q_header) {
result = qp_host_map_queues(entry->produce_q, entry->consume_q);
if (result < VMCI_SUCCESS)
return result;
@@ -2448,7 +2446,7 @@ static int qp_map_queue_headers(struct vmci_queue *produce_q,
{
int result;

- if (NULL == produce_q->q_header || NULL == consume_q->q_header) {
+ if (!produce_q->q_header || !consume_q->q_header) {
result = qp_host_map_queues(produce_q, consume_q);
if (result < VMCI_SUCCESS)
return (produce_q->saved_header &&
--
2.15.1