Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAY BUG @ kernel/core/tos_bitmap.c #303

Open
wants to merge 1 commit into
base: ver2.4.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions kernel/core/tos_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ __API__ k_err_t tos_bitmap_set(k_bitmap_t *bitmap, uint32_t bit)
TOS_PTR_SANITY_CHECK(bitmap);
TOS_OBJ_VERIFY(bitmap, KNL_OBJ_TYPE_BITMAP);

if (bit > bitmap->bit_max) {
if (bit >= bitmap->bit_max) {
return K_ERR_BITMAP_EXCEED;
}

Expand All @@ -83,7 +83,7 @@ __API__ k_err_t tos_bitmap_reset(k_bitmap_t *bitmap, uint32_t bit)
TOS_PTR_SANITY_CHECK(bitmap);
TOS_OBJ_VERIFY(bitmap, KNL_OBJ_TYPE_BITMAP);

if (bit > bitmap->bit_max) {
if (bit >= bitmap->bit_max) {
return K_ERR_BITMAP_EXCEED;
}

Expand All @@ -97,7 +97,7 @@ __API__ int tos_bitmap_is_set(k_bitmap_t *bitmap, uint32_t bit)
TOS_PTR_SANITY_CHECK_RC(bitmap, K_FALSE);
TOS_OBJ_VERIFY_RC(bitmap, KNL_OBJ_TYPE_BITMAP, K_FALSE);

if (bit > bitmap->bit_max) {
if (bit >= bitmap->bit_max) {
return K_FALSE;
}

Expand All @@ -109,7 +109,7 @@ __API__ int tos_bitmap_is_reset(k_bitmap_t *bitmap, uint32_t bit)
TOS_PTR_SANITY_CHECK_RC(bitmap, K_FALSE);
TOS_OBJ_VERIFY_RC(bitmap, KNL_OBJ_TYPE_BITMAP, K_FALSE);

if (bit > bitmap->bit_max) {
if (bit >= bitmap->bit_max) {
return K_FALSE;
}

Expand All @@ -126,18 +126,18 @@ __API__ int tos_bitmap_lsb(k_bitmap_t *bitmap)

bitmap_tbl = bitmap->bitmap_tbl;

for (i = 0; i < bitmap->bit_ndx_max - 1; ++i) {
for (i = 0; i < bitmap->bit_ndx_max; ++i) {
if (*bitmap_tbl == 0) {
lsb += K_BITMAP_SLOT_SIZE;
++bitmap_tbl;
}
else{
lsb = i * K_BITMAP_SLOT_SIZE;
lsb += tos_cpu_clz(*bitmap_tbl);
return lbs;
}
}

lsb += tos_cpu_clz(*bitmap_tbl);
if (lsb > bitmap->bit_max) {
return bitmap->bit_max + 1;
}

return lsb;

// 如果没找到为什么不返回 -1(not_exist) 之类的值
return bitmap->bit_max;
}