Skip to content

Commit d3ad411

Browse files
Shawnshhlijinxia
authored andcommitted
HV:lib:add suffix U to the numeric constant
Add suffix U to the numeric constant Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent d3bd514 commit d3ad411

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

hypervisor/lib/memory.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static uint32_t Malloc_Heap_Contiguity_Bitmap[MALLOC_HEAP_BITMAP_SIZE];
2222

2323
struct mem_pool Memory_Pool = {
2424
.start_addr = Malloc_Heap,
25-
.spinlock = {.head = 0, .tail = 0},
25+
.spinlock = {.head = 0U, .tail = 0U},
2626
.size = CONFIG_HEAP_SIZE,
2727
.buff_size = MALLOC_HEAP_BUFF_SIZE,
2828
.total_buffs = MALLOC_HEAP_TOTAL_BUFF,
@@ -46,7 +46,7 @@ static uint32_t Paging_Heap_Contiguity_Bitmap[MALLOC_HEAP_BITMAP_SIZE];
4646

4747
struct mem_pool Paging_Memory_Pool = {
4848
.start_addr = Paging_Heap,
49-
.spinlock = {.head = 0, .tail = 0},
49+
.spinlock = {.head = 0U, .tail = 0U},
5050
.size = CONFIG_NUM_ALLOC_PAGES * CPU_PAGE_SIZE,
5151
.buff_size = PAGING_HEAP_BUFF_SIZE,
5252
.total_buffs = PAGING_HEAP_TOTAL_BUFF,
@@ -73,7 +73,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
7373
/* Calculate number of buffers to be allocated from memory pool */
7474
requested_buffs = INT_DIV_ROUNDUP(num_bytes, pool->buff_size);
7575

76-
for (idx = 0; idx < pool->bmp_size; idx++) {
76+
for (idx = 0U; idx < pool->bmp_size; idx++) {
7777
/* Find the first occurrence of requested_buffs number of free
7878
* buffers. The 0th bit in bitmap represents a free buffer.
7979
*/
@@ -125,7 +125,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
125125
/* Update allocation bitmaps information for
126126
* selected buffers
127127
*/
128-
for (i = 0; i < requested_buffs; i++) {
128+
for (i = 0U; i < requested_buffs; i++) {
129129
/* Set allocation bit in bitmap for
130130
* this buffer
131131
*/
@@ -157,7 +157,7 @@ static void *allocate_mem(struct mem_pool *pool, unsigned int num_bytes)
157157
/* Increment idx */
158158
idx++;
159159
/* Reset bit_idx */
160-
bit_idx = 0;
160+
bit_idx = 0U;
161161
}
162162
}
163163

@@ -343,7 +343,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
343343
uint8_t *dest8;
344344
uint8_t *src8;
345345

346-
if (slen == 0 || dmax == 0 || dmax < slen) {
346+
if (slen == 0U || dmax == 0U || dmax < slen) {
347347
pr_err("%s: invalid src, dest buffer or length.", __func__);
348348
return NULL;
349349
}
@@ -362,7 +362,7 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
362362
src8 = (uint8_t *)s;
363363

364364
/*small data block*/
365-
if (slen < 8) {
365+
if (slen < 8U) {
366366
while (slen != 0U) {
367367
*dest8++ = *src8++;
368368
slen--;
@@ -378,15 +378,15 @@ void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
378378
}
379379

380380
/*copy main data blocks, with rep prefix*/
381-
if (slen > 8) {
381+
if (slen > 8U) {
382382
uint32_t ecx;
383383

384384
asm volatile ("cld; rep; movsq"
385385
: "=&c"(ecx), "=&D"(dest8), "=&S"(src8)
386386
: "0" (slen / 8), "1" (dest8), "2" (src8)
387387
: "memory");
388388

389-
slen = slen % 8;
389+
slen = slen % 8U;
390390
}
391391

392392
/*tail bytes*/
@@ -406,7 +406,7 @@ void *memset(void *base, uint8_t v, size_t n)
406406

407407
dest_p = (uint8_t *)base;
408408

409-
if ((dest_p == NULL) || (n == 0))
409+
if ((dest_p == NULL) || (n == 0U))
410410
return NULL;
411411

412412
/*do the few bytes to get uint64_t alignment*/
@@ -415,11 +415,11 @@ void *memset(void *base, uint8_t v, size_t n)
415415
*dest_p++ = v;
416416

417417
/*64-bit mode*/
418-
n_q = count >> 3;
418+
n_q = count >> 3U;
419419
asm volatile("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb"
420420
: "+c"(n_q), "+D"(dest_p)
421421
: "a" (v * 0x0101010101010101U),
422-
"r"((unsigned int)count & 7));
422+
"r"((unsigned int)count & 7U));
423423

424424
return (void *)dest_p;
425425
}

hypervisor/lib/sprintf.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ static int format_number(struct print_param *param)
180180
int res;
181181

182182
/* initialize variables */
183-
p = w = 0;
183+
p = 0U;
184+
w = 0U;
184185
res = 0;
185186
width = param->vars.valuelen + param->vars.prefixlen;
186187

@@ -215,7 +216,7 @@ static int format_number(struct print_param *param)
215216

216217
/* invalidate prefix */
217218
param->vars.prefix = NULL;
218-
param->vars.prefixlen = 0;
219+
param->vars.prefixlen = 0U;
219220
}
220221

221222
/* fill the width with the padding character, return early if
@@ -273,7 +274,7 @@ static int print_pow2(struct print_param *param,
273274
int ret;
274275

275276
/* calculate mask */
276-
mask = (1UL << shift) - 1;
277+
mask = (1UL << shift) - 1UL;
277278

278279
/* determine digit translation table */
279280
digits = ((param->vars.flags & PRINT_FLAG_UPPER) != 0) ?
@@ -283,21 +284,21 @@ static int print_pow2(struct print_param *param,
283284
v &= param->vars.mask;
284285

285286
/* determine prefix for alternate form */
286-
if ((v == 0) && ((param->vars.flags & PRINT_FLAG_ALTERNATE_FORM) != 0)) {
287+
if ((v == 0UL) && ((param->vars.flags & PRINT_FLAG_ALTERNATE_FORM) != 0)) {
287288
prefix[0] = '0';
288289
param->vars.prefix = prefix;
289-
param->vars.prefixlen = 1;
290+
param->vars.prefixlen = 1U;
290291

291-
if (shift == 4) {
292-
param->vars.prefixlen = 2;
292+
if (shift == 4U) {
293+
param->vars.prefixlen = 2U;
293294
prefix[1] = digits[16];
294295
}
295296
}
296297

297298
/* determine digits from right to left */
298299
do {
299300
*--pos = digits[(v & mask)];
300-
} while ((v >>= shift) != 0);
301+
} while ((v >>= shift) != 0UL);
301302

302303
/* assign parameter and apply width and precision */
303304
param->vars.value = pos;
@@ -306,7 +307,7 @@ static int print_pow2(struct print_param *param,
306307
ret = format_number(param);
307308

308309
param->vars.value = NULL;
309-
param->vars.valuelen = 0;
310+
param->vars.valuelen = 0U;
310311

311312
return ret;
312313
}
@@ -350,7 +351,7 @@ static int print_decimal(struct print_param *param, int64_t value)
350351
}
351352

352353
/* process 64 bit value as long as needed */
353-
while (v.dwords.high != 0) {
354+
while (v.dwords.high != 0U) {
354355
/* determine digits from right to left */
355356
udiv64(v.qword, 10, &d);
356357
*--pos = d.r.dwords.low + '0';
@@ -374,7 +375,7 @@ static int print_decimal(struct print_param *param, int64_t value)
374375
ret = format_number(param);
375376

376377
param->vars.value = NULL;
377-
param->vars.valuelen = 0;
378+
param->vars.valuelen = 0U;
378379

379380
return ret;
380381
}
@@ -390,7 +391,7 @@ static int print_string(struct print_param *param, const char *s)
390391
/* the last result of the emit function */
391392
int res;
392393

393-
w = 0;
394+
w = 0U;
394395
len = -1;
395396

396397
/* we need the length of the string if either width or precision is

hypervisor/lib/string.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen)
262262
return NULL;
263263
}
264264

265-
if (dmax == 0 || slen == 0) {
265+
if (dmax == 0U || slen == 0U) {
266266
pr_err("%s: invlaid length of src or dest buffer", __func__);
267267
return NULL;
268268
}
@@ -282,7 +282,7 @@ char *strncpy_s(char *d, size_t dmax, const char *s, size_t slen)
282282
return NULL;
283283
}
284284

285-
if (slen == 0) {
285+
if (slen == 0U) {
286286
*d = '\0';
287287
return dest_base;
288288
}
@@ -333,9 +333,9 @@ size_t strnlen_s(const char *str, size_t maxlen)
333333
if (str == NULL)
334334
return 0;
335335

336-
count = 0;
336+
count = 0U;
337337
while ((*str) != 0) {
338-
if (maxlen == 0)
338+
if (maxlen == 0U)
339339
break;
340340

341341
count++;

0 commit comments

Comments
 (0)