From: Peter Senna Tschudin <peter.senna@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Senna Tschudin <peter.senna@gmail.com>,
kernel-janitors@vger.kernel.org, dan.carpenter@oracle.com
Subject: [PATCH 1/4 V2] VMCI: Remove redundant error check and code cleanup
Date: Sat, 17 May 2014 21:20:19 +0000 [thread overview]
Message-ID: <1400361619-5323-1-git-send-email-peter.senna@gmail.com> (raw)
Remove double checks, and move the call to pr_devel. Remove the
initialization of the result variable, and return VMCI_SUCCESS on
success. Fix the condition of the for loop. Replace break with a
return. The simplified version of the coccinelle semantic patch
that find the redundant check issue is as follows:
// <smpl>
@@
expression E; identifier pr; expression list es;
@@
for(...;...;...){
...
- if (E) break;
+ if (E){
+ pr(es);
+ break;
+ }
...
}
- if(E) pr(es);
// </smpl>
Tested by compilation only.
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
---
Changes from V1:
- Removed initialization of result
- Return VMCI_SUCCESS instead of result on success
- Fixed the for loop condition
- Replaced break with a return
drivers/misc/vmw_vmci/vmci_context.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/misc/vmw_vmci/vmci_context.c b/drivers/misc/vmw_vmci/vmci_context.c
index f866a4b..78c1165 100644
--- a/drivers/misc/vmw_vmci/vmci_context.c
+++ b/drivers/misc/vmw_vmci/vmci_context.c
@@ -816,7 +816,7 @@ int vmci_ctx_set_chkpt_state(u32 context_id,
{
u32 i;
u32 current_id;
- int result = VMCI_SUCCESS;
+ int result;
u32 num_ids = buf_size / sizeof(u32);
if (cpt_type = VMCI_WELLKNOWN_CPT_STATE && num_ids > 0) {
@@ -833,17 +833,17 @@ int vmci_ctx_set_chkpt_state(u32 context_id,
return VMCI_ERROR_INVALID_ARGS;
}
- for (i = 0; i < num_ids && result = VMCI_SUCCESS; i++) {
+ for (i = 0; i < num_ids; i++) {
current_id = ((u32 *)cpt_buf)[i];
result = vmci_ctx_add_notification(context_id, current_id);
- if (result != VMCI_SUCCESS)
- break;
+ if (result != VMCI_SUCCESS) {
+ pr_devel("Failed to set cpt state (type=%d) (error=%d)\n",
+ cpt_type, result);
+ return result;
+ }
}
- if (result != VMCI_SUCCESS)
- pr_devel("Failed to set cpt state (type=%d) (error=%d)\n",
- cpt_type, result);
- return result;
+ return VMCI_SUCCESS;
}
/*
reply other threads:[~2014-05-17 21:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400361619-5323-1-git-send-email-peter.senna@gmail.com \
--to=peter.senna@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox