[PATCH 04/10] HV: remove few return statement in while loop of copy_gva function


YanLiang
 

From: Chaohong guo <chaohong.guo@...>

The coding style of multiple returns/exit in while loop is not MISRA
compatible. Remove the returns in while loop.

Signed-off-by: Chaohong guo <chaohong.guo@...>
---
hypervisor/arch/x86/guest/guest.c | 32 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/hypervisor/arch/x86/guest/guest.c b/hypervisor/arch/x86/guest/guest.c
index 5c0fd7dc..047f7d3d 100644
--- a/hypervisor/arch/x86/guest/guest.c
+++ b/hypervisor/arch/x86/guest/guest.c
@@ -391,33 +391,29 @@ static inline int32_t copy_gva(struct acrn_vcpu *vcpu, void *h_ptr_arg, uint64_t
{
void *h_ptr = h_ptr_arg;
uint64_t gpa = 0UL;
- int32_t ret;
+ int32_t ret = 0;
uint32_t len;
uint64_t gva = gva_arg;
uint32_t size = size_arg;

- while (size > 0U) {
+ while ((size > 0U) && (ret == 0)) {
ret = gva2gpa(vcpu, gva, &gpa, err_code);
- if (ret < 0) {
+ if (ret >= 0) {
+ len = local_copy_gpa(vcpu->vm, h_ptr, gpa, size, PAGE_SIZE_4K, cp_from_vm);
+ if (len != 0U) {
+ gva += len;
+ h_ptr += len;
+ size -= len;
+ } else {
+ ret = -EINVAL;
+ }
+ } else {
*fault_addr = gva;
- pr_err("error[%d] in GVA2GPA, err_code=0x%x",
- ret, *err_code);
- return ret;
+ pr_err("error[%d] in GVA2GPA, err_code=0x%x", ret, *err_code);
}
-
- len = local_copy_gpa(vcpu->vm, h_ptr, gpa, size,
- PAGE_SIZE_4K, cp_from_vm);
-
- if (len == 0U) {
- return -EINVAL;
- }
-
- gva += len;
- h_ptr += len;
- size -= len;
}

- return 0;
+ return ret;
}

/* @pre Caller(Guest) should make sure gpa is continuous.
--
2.19.0


Eddie Dong
 

Acked-by: Eddie Dong <eddie.dong@...>

-----Original Message-----
From: acrn-dev@...
[mailto:acrn-dev@...] On Behalf Of YanLiang
Sent: Friday, December 21, 2018 12:31 PM
To: acrn-dev@...
Cc: Guo, Chaohong <chaohong.guo@...>
Subject: [acrn-dev] [PATCH 04/10] HV: remove few return statement in while
loop of copy_gva function

From: Chaohong guo <chaohong.guo@...>

The coding style of multiple returns/exit in while loop is not MISRA
compatible. Remove the returns in while loop.

Signed-off-by: Chaohong guo <chaohong.guo@...>
---
hypervisor/arch/x86/guest/guest.c | 32 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/hypervisor/arch/x86/guest/guest.c
b/hypervisor/arch/x86/guest/guest.c
index 5c0fd7dc..047f7d3d 100644
--- a/hypervisor/arch/x86/guest/guest.c
+++ b/hypervisor/arch/x86/guest/guest.c
@@ -391,33 +391,29 @@ static inline int32_t copy_gva(struct acrn_vcpu
*vcpu, void *h_ptr_arg, uint64_t {
void *h_ptr = h_ptr_arg;
uint64_t gpa = 0UL;
- int32_t ret;
+ int32_t ret = 0;
uint32_t len;
uint64_t gva = gva_arg;
uint32_t size = size_arg;

- while (size > 0U) {
+ while ((size > 0U) && (ret == 0)) {
ret = gva2gpa(vcpu, gva, &gpa, err_code);
- if (ret < 0) {
+ if (ret >= 0) {
+ len = local_copy_gpa(vcpu->vm, h_ptr, gpa, size,
PAGE_SIZE_4K, cp_from_vm);
+ if (len != 0U) {
+ gva += len;
+ h_ptr += len;
+ size -= len;
+ } else {
+ ret = -EINVAL;
+ }
+ } else {
*fault_addr = gva;
- pr_err("error[%d] in GVA2GPA, err_code=0x%x",
- ret, *err_code);
- return ret;
+ pr_err("error[%d] in GVA2GPA, err_code=0x%x", ret,
*err_code);
}
-
- len = local_copy_gpa(vcpu->vm, h_ptr, gpa, size,
- PAGE_SIZE_4K, cp_from_vm);
-
- if (len == 0U) {
- return -EINVAL;
- }
-
- gva += len;
- h_ptr += len;
- size -= len;
}

- return 0;
+ return ret;
}

/* @pre Caller(Guest) should make sure gpa is continuous.
--
2.19.0