Commit 7b3bbb92 authored by Paul Moore's avatar Paul Moore Committed by David S. Miller

[NetLabel]: Cleanup ebitmap_import()

Rewrite ebitmap_import() so it is a bit cleaner and easier to read.
Signed-off-by: default avatarPaul Moore <paul.moore@hp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c1b14c0a
...@@ -145,29 +145,28 @@ int ebitmap_import(const unsigned char *src, ...@@ -145,29 +145,28 @@ int ebitmap_import(const unsigned char *src,
struct ebitmap *dst) struct ebitmap *dst)
{ {
size_t src_off = 0; size_t src_off = 0;
size_t node_limit;
struct ebitmap_node *node_new; struct ebitmap_node *node_new;
struct ebitmap_node *node_last = NULL; struct ebitmap_node *node_last = NULL;
size_t iter; u32 i_byte;
size_t iter_bit; u32 i_bit;
size_t iter_limit;
unsigned char src_byte; unsigned char src_byte;
do { while (src_off < src_len) {
iter_limit = src_len - src_off; if (src_len - src_off >= sizeof(MAPTYPE)) {
if (iter_limit >= sizeof(MAPTYPE)) {
if (*(MAPTYPE *)&src[src_off] == 0) { if (*(MAPTYPE *)&src[src_off] == 0) {
src_off += sizeof(MAPTYPE); src_off += sizeof(MAPTYPE);
continue; continue;
} }
iter_limit = sizeof(MAPTYPE); node_limit = sizeof(MAPTYPE);
} else { } else {
iter = src_off; for (src_byte = 0, i_byte = src_off;
src_byte = 0; i_byte < src_len && src_byte == 0;
do { i_byte++)
src_byte |= src[iter++]; src_byte |= src[i_byte];
} while (iter < src_len && src_byte == 0);
if (src_byte == 0) if (src_byte == 0)
break; break;
node_limit = src_len - src_off;
} }
node_new = kzalloc(sizeof(*node_new), GFP_ATOMIC); node_new = kzalloc(sizeof(*node_new), GFP_ATOMIC);
...@@ -176,24 +175,21 @@ int ebitmap_import(const unsigned char *src, ...@@ -176,24 +175,21 @@ int ebitmap_import(const unsigned char *src,
return -ENOMEM; return -ENOMEM;
} }
node_new->startbit = src_off * 8; node_new->startbit = src_off * 8;
iter = 0; for (i_byte = 0; i_byte < node_limit; i_byte++) {
do {
src_byte = src[src_off++]; src_byte = src[src_off++];
iter_bit = iter++ * 8; for (i_bit = i_byte * 8; src_byte != 0; i_bit++) {
while (src_byte != 0) {
if (src_byte & 0x80) if (src_byte & 0x80)
node_new->map |= MAPBIT << iter_bit; node_new->map |= MAPBIT << i_bit;
iter_bit++;
src_byte <<= 1; src_byte <<= 1;
} }
} while (iter < iter_limit); }
if (node_last != NULL) if (node_last != NULL)
node_last->next = node_new; node_last->next = node_new;
else else
dst->node = node_new; dst->node = node_new;
node_last = node_new; node_last = node_new;
} while (src_off < src_len); }
if (likely(node_last != NULL)) if (likely(node_last != NULL))
dst->highbit = node_last->startbit + MAPSIZE; dst->highbit = node_last->startbit + MAPSIZE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment