Skip to content

Commit e4c52c5

Browse files
committed
libdrgn: linux_kernel: use names for kmod index constants
This makes it much easier to follow along with the code and understand the format.
1 parent 03d8cb0 commit e4c52c5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libdrgn/linux_kernel.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,15 +820,19 @@ static struct drgn_error *kmod_index_init(struct kmod_index *index,
820820

821821
static const char *kmod_index_find(struct kmod_index *index, const char *key)
822822
{
823+
static const uint32_t INDEX_NODE_MASK = UINT32_C(0x0fffffff);
824+
static const uint32_t INDEX_NODE_CHILDS = UINT32_C(0x20000000);
825+
static const uint32_t INDEX_NODE_VALUES = UINT32_C(0x40000000);
826+
static const uint32_t INDEX_NODE_PREFIX = UINT32_C(0x80000000);
823827
const char *ptr = index->ptr + 8;
824828
uint32_t offset;
825829

826830
for (;;) {
827831
if (!read_be32(&ptr, index->end, &offset))
828832
return NULL;
829-
ptr = index->ptr + (offset & 0x0fffffffU);
833+
ptr = index->ptr + (offset & INDEX_NODE_MASK);
830834

831-
if (offset & 0x80000000U) {
835+
if (offset & INDEX_NODE_PREFIX) {
832836
const char *prefix;
833837
size_t prefix_len;
834838

@@ -840,7 +844,7 @@ static const char *kmod_index_find(struct kmod_index *index, const char *key)
840844
key += prefix_len;
841845
}
842846

843-
if (offset & 0x20000000U) {
847+
if (offset & INDEX_NODE_CHILDS) {
844848
uint8_t first, last;
845849

846850
if (!read_u8(&ptr, index->end, &first) ||
@@ -864,7 +868,7 @@ static const char *kmod_index_find(struct kmod_index *index, const char *key)
864868
break;
865869
}
866870
}
867-
if (!(offset & 0x40000000U))
871+
if (!(offset & INDEX_NODE_VALUES))
868872
return NULL;
869873
return ptr;
870874
}

0 commit comments

Comments
 (0)