return (void *)((unsigned long)node | 2);
}
-static inline void ma_set_alloc_cnt(struct maple_state *ms, int count)
+static inline struct maple_node *ma_get_alloc(const struct maple_state *ms)
{
- ms->alloc = (struct maple_node *)((unsigned long)ms->alloc & ~0x03);
- ms->alloc = (struct maple_node *)((unsigned long)ms->alloc | count);
+ return (struct maple_node *)((unsigned long)ms->alloc & ~0x0F);
}
static inline int ma_get_alloc_cnt(const struct maple_state *ms)
{
- return (int)((unsigned long)ms->alloc & 3);
+ struct maple_node *node = ma_get_alloc(ms);
+
+ if (!node)
+ return 0;
+ if (!node->slot[0])
+ return 1;
+ if (!node->slot[1])
+ return 2;
+ return 3;
}
static inline void ma_set_alloc_req(struct maple_state *ms, int count)
{
- ms->alloc = (struct maple_node *)((unsigned long)ms->alloc & ~0x0C);
- ms->alloc = (struct maple_node *)((unsigned long)ms->alloc |
- (count << 2));
+ ms->alloc = (struct maple_node *)((unsigned long)ms->alloc & ~0x03);
+ ms->alloc = (struct maple_node *)((unsigned long)ms->alloc | count);
}
static inline int ma_get_alloc_req(const struct maple_state *ms)
{
- return (int)(((unsigned long)ms->alloc & 0x0C) >> 2);
-}
-static inline struct maple_node *ma_get_alloc(const struct maple_state *ms)
-{
- return (struct maple_node *)((unsigned long)ms->alloc & ~0x0F);
+ return (int)(((unsigned long)ms->alloc & 0x03));
}
static inline struct maple_node *ma_next_alloc(struct maple_state *ms)
{
} else {
smn = (struct maple_node*)mn->slot[cnt - 1];
mn->slot[cnt - 1] = NULL;
- ma_set_alloc_cnt(ms, cnt);
mn = smn;
}
slot = allocated - 1;
while (req > 0) {
- req--;
smn = kzalloc(sizeof(*mn), gfp);
if (!smn)
goto slot_failed;
smn->parent = NULL;
mn->slot[slot++] = smn;
+ req--;
allocated++;
}
slot_failed:
ms->alloc = mn;
- ma_set_alloc_cnt(ms, allocated);
ma_set_alloc_req(ms, req);
list_failed: