• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #include "tee_bitmap.h"
14 
15 #define INVALID_BIT (-1)
16 
get_valid_bit(const uint8_t * bitmap,uint32_t bit_max)17 int32_t get_valid_bit(const uint8_t *bitmap, uint32_t bit_max)
18 {
19     uint32_t index1;
20     uint32_t index2;
21     int32_t  valid_bit = INVALID_BIT;
22 
23     if (bitmap == NULL)
24         return valid_bit;
25 
26     for (index1 = 0; index1 < (bit_max >> MOVE_BIT); index1++) {
27         if (bitmap[index1] == BITMAP_MASK)
28             continue;
29         for (index2 = 0; index2 < INDEX_MAX; index2++) {
30             if (!(bitmap[index1] & (0x1U << index2))) {
31                 valid_bit = index1 * INDEX_MAX + index2;
32                 break;
33             }
34         }
35         if (valid_bit != INVALID_BIT)
36             break;
37     }
38 
39     return valid_bit;
40 }
41