Skip to content

Commit dd695f3

Browse files
yuchuyanglijinxia
authored andcommitted
HV: Moving operators out from conditions
To follow the Misra-c standard, any operators should be done outside the conditions. Removed the prefix, postfix and bitwise shift from conditions. Signed-off-by: Yang, Yu-chu <yu-chu.yang@intel.com>
1 parent 078178b commit dd695f3

File tree

10 files changed

+41
-21
lines changed

10 files changed

+41
-21
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,8 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic)
11071107
"Sending SIPI from VCPU %d to %hu with vector %d",
11081108
vlapic->vcpu->vcpu_id, vcpu_id, vec);
11091109

1110-
if (--target_vcpu->arch_vcpu.nr_sipi > 0)
1110+
target_vcpu->arch_vcpu.nr_sipi--;
1111+
if (target_vcpu->arch_vcpu.nr_sipi > 0)
11111112
continue;
11121113

11131114
target_vcpu->arch_vcpu.cpu_mode = CPU_MODE_REAL;

hypervisor/arch/x86/timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ void timer_softirq(uint16_t pcpu_id)
191191
list_for_each_safe(pos, n, &cpu_timer->timer_list) {
192192
timer = list_entry(pos, struct timer, node);
193193
/* timer expried */
194-
if (timer->fire_tsc <= current_tsc && --tries > 0) {
194+
tries--;
195+
if (timer->fire_tsc <= current_tsc && tries > 0) {
195196
del_timer(timer);
196197

197198
run_timer(timer);

hypervisor/arch/x86/vtd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,10 +1167,11 @@ void suspend_iommu(void)
11671167
/* If the number of real iommu devices is larger than we
11681168
* defined in kconfig.
11691169
*/
1170-
if (iommu_idx++ > CONFIG_MAX_IOMMU_NUM) {
1170+
if (iommu_idx > CONFIG_MAX_IOMMU_NUM) {
11711171
pr_err("iommu dev number is larger than pre-defined");
11721172
break;
11731173
}
1174+
iommu_idx++;
11741175
}
11751176
}
11761177

@@ -1206,10 +1207,11 @@ void resume_iommu(void)
12061207
/* If the number of real iommu devices is larger than we
12071208
* defined in kconfig.
12081209
*/
1209-
if (iommu_idx++ > CONFIG_MAX_IOMMU_NUM) {
1210+
if (iommu_idx > CONFIG_MAX_IOMMU_NUM) {
12101211
pr_err("iommu dev number is larger than pre-defined");
12111212
break;
12121213
}
1214+
iommu_idx++;
12131215
}
12141216
}
12151217

hypervisor/debug/printf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ static int charout(int cmd, const char *s, int sz, void *hnd)
2828
/* fill mode */
2929
else {
3030
*nchars += sz;
31-
while ((sz--) != 0)
31+
while (sz != 0) {
3232
console_putc(*s);
33+
sz--;
34+
}
3335
}
3436

3537
return *nchars;

hypervisor/debug/serial.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ static struct uart *get_uart_by_id(const char *uart_id, uint32_t *index)
2222
break;
2323

2424
/* No device is found if index reaches end of array. */
25-
if (++(*index) == SERIAL_MAX_DEVS)
25+
(*index)++;
26+
if (*index == SERIAL_MAX_DEVS)
2627
return NULL;
2728

2829
}

hypervisor/debug/shell_internal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ static int string_to_argv(char *argv_str, void *p_argv_mem,
7979
*/
8080
*p_ch = 0;
8181
/* Remove all space in middile of cmdline */
82-
while (*++p_ch == ' ')
83-
;
82+
p_ch++;
83+
while (*p_ch == ' ')
84+
p_ch++;
8485
}
8586
}
8687

hypervisor/lib/div.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ static int do_udiv32(uint32_t dividend, uint32_t divisor,
2727
res->q.dwords.low |= mask;
2828
}
2929
divisor >>= 1U;
30-
} while (((mask >>= 1U) != 0U) && (dividend != 0U));
30+
mask >>= 1U;
31+
} while ((mask != 0U) && (dividend != 0U));
3132
/* dividend now contains the reminder */
3233
res->r.dwords.low = dividend;
3334
return 0;

hypervisor/lib/mdelay.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
void mdelay(uint32_t loop_count)
1010
{
1111
/* Loop until done */
12-
while (loop_count-- != 0) {
12+
while (loop_count != 0) {
1313
/* Delay for 1 ms */
1414
udelay(1000);
15+
loop_count--;
1516
}
1617
}

hypervisor/lib/memory.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
9595
*/
9696
for (i = 1; i < requested_buffs; i++) {
9797
/* Check if tmp_bit_idx is out-of-range */
98-
if (++tmp_bit_idx == BITMAP_WORD_SIZE) {
98+
tmp_bit_idx++;
99+
if (tmp_bit_idx == BITMAP_WORD_SIZE) {
99100
/* Break the loop if tmp_idx is
100101
* out-of-range
101102
*/
102-
if (++tmp_idx == pool->bmp_size)
103+
tmp_idx++;
104+
if (tmp_idx == pool->bmp_size)
103105
break;
104106
/* Reset tmp_bit_idx */
105107
tmp_bit_idx = 0U;
@@ -153,7 +155,8 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
153155
}
154156

155157
/* Check if bit_idx is out-of-range */
156-
if (++bit_idx == BITMAP_WORD_SIZE) {
158+
bit_idx++;
159+
if (bit_idx == BITMAP_WORD_SIZE) {
157160
/* Increment idx */
158161
idx++;
159162
/* Reset bit_idx */
@@ -306,8 +309,9 @@ void *memchr(const void *void_s, int c, size_t n)
306309

307310
while (ptr < end) {
308311

309-
if (*ptr++ == val)
310-
return ((void *)(ptr - 1));
312+
if (*ptr == val)
313+
return ((void *)ptr);
314+
ptr++;
311315
}
312316

313317
return NULL;

hypervisor/lib/sprintf.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ static const char *get_length_modifier(const char *s,
147147
{
148148
/* check for h[h] (char/short) */
149149
if (*s == 'h') {
150-
if (*++s == 'h') {
150+
s++;
151+
if (*s == 'h') {
151152
*flags |= PRINT_FLAG_CHAR;
152153
*mask = 0x000000FF;
153154
++s;
@@ -158,7 +159,8 @@ static const char *get_length_modifier(const char *s,
158159
}
159160
/* check for l[l] (long/long long) */
160161
else if (*s == 'l') {
161-
if (*++s == 'l') {
162+
s++;
163+
if (*s == 'l') {
162164
*flags |= PRINT_FLAG_LONG_LONG;
163165
++s;
164166
} else
@@ -297,8 +299,10 @@ static int print_pow2(struct print_param *param,
297299

298300
/* determine digits from right to left */
299301
do {
300-
*--pos = digits[(v & mask)];
301-
} while ((v >>= shift) != 0UL);
302+
pos--;
303+
*pos = digits[(v & mask)];
304+
v >>= shift;
305+
} while (v != 0UL);
302306

303307
/* assign parameter and apply width and precision */
304308
param->vars.value = pos;
@@ -365,8 +369,10 @@ static int print_decimal(struct print_param *param, int64_t value)
365369
* 10.
366370
*/
367371
nv.dwords.low = v.dwords.low / 10;
368-
*--pos = (v.dwords.low - (10 * nv.dwords.low)) + '0';
369-
} while ((v.dwords.low = nv.dwords.low) != 0);
372+
pos--;
373+
*pos = (v.dwords.low - (10 * nv.dwords.low)) + '0';
374+
v.dwords.low = nv.dwords.low;
375+
} while (v.dwords.low != 0);
370376

371377
/* assign parameter and apply width and precision */
372378
param->vars.value = pos;

0 commit comments

Comments
 (0)