diff options
author | Paul Moore <paul.moore@hp.com> | 2006-08-29 20:55:11 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 18:18:37 -0400 |
commit | 7b3bbb926f4b3dd3a007dcf8dfa00203f52cb58d (patch) | |
tree | 1ee2ab452f5c94ce4779171d6ebaa07f7d1fcd21 | |
parent | c1b14c0a46232246f61d3157bac1201e1e102227 (diff) |
[NetLabel]: Cleanup ebitmap_import()
Rewrite ebitmap_import() so it is a bit cleaner and easier to read.
Signed-off-by: Paul Moore <paul.moore@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | security/selinux/ss/ebitmap.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c index 4b915eb60c45..cfed1d30fa6a 100644 --- a/security/selinux/ss/ebitmap.c +++ b/security/selinux/ss/ebitmap.c | |||
@@ -145,29 +145,28 @@ int ebitmap_import(const unsigned char *src, | |||
145 | struct ebitmap *dst) | 145 | struct ebitmap *dst) |
146 | { | 146 | { |
147 | size_t src_off = 0; | 147 | size_t src_off = 0; |
148 | size_t node_limit; | ||
148 | struct ebitmap_node *node_new; | 149 | struct ebitmap_node *node_new; |
149 | struct ebitmap_node *node_last = NULL; | 150 | struct ebitmap_node *node_last = NULL; |
150 | size_t iter; | 151 | u32 i_byte; |
151 | size_t iter_bit; | 152 | u32 i_bit; |
152 | size_t iter_limit; | ||
153 | unsigned char src_byte; | 153 | unsigned char src_byte; |
154 | 154 | ||
155 | do { | 155 | while (src_off < src_len) { |
156 | iter_limit = src_len - src_off; | 156 | if (src_len - src_off >= sizeof(MAPTYPE)) { |
157 | if (iter_limit >= sizeof(MAPTYPE)) { | ||
158 | if (*(MAPTYPE *)&src[src_off] == 0) { | 157 | if (*(MAPTYPE *)&src[src_off] == 0) { |
159 | src_off += sizeof(MAPTYPE); | 158 | src_off += sizeof(MAPTYPE); |
160 | continue; | 159 | continue; |
161 | } | 160 | } |
162 | iter_limit = sizeof(MAPTYPE); | 161 | node_limit = sizeof(MAPTYPE); |
163 | } else { | 162 | } else { |
164 | iter = src_off; | 163 | for (src_byte = 0, i_byte = src_off; |
165 | src_byte = 0; | 164 | i_byte < src_len && src_byte == 0; |
166 | do { | 165 | i_byte++) |
167 | src_byte |= src[iter++]; | 166 | src_byte |= src[i_byte]; |
168 | } while (iter < src_len && src_byte == 0); | ||
169 | if (src_byte == 0) | 167 | if (src_byte == 0) |
170 | break; | 168 | break; |
169 | node_limit = src_len - src_off; | ||
171 | } | 170 | } |
172 | 171 | ||
173 | node_new = kzalloc(sizeof(*node_new), GFP_ATOMIC); | 172 | node_new = kzalloc(sizeof(*node_new), GFP_ATOMIC); |
@@ -176,24 +175,21 @@ int ebitmap_import(const unsigned char *src, | |||
176 | return -ENOMEM; | 175 | return -ENOMEM; |
177 | } | 176 | } |
178 | node_new->startbit = src_off * 8; | 177 | node_new->startbit = src_off * 8; |
179 | iter = 0; | 178 | for (i_byte = 0; i_byte < node_limit; i_byte++) { |
180 | do { | ||
181 | src_byte = src[src_off++]; | 179 | src_byte = src[src_off++]; |
182 | iter_bit = iter++ * 8; | 180 | for (i_bit = i_byte * 8; src_byte != 0; i_bit++) { |
183 | while (src_byte != 0) { | ||
184 | if (src_byte & 0x80) | 181 | if (src_byte & 0x80) |
185 | node_new->map |= MAPBIT << iter_bit; | 182 | node_new->map |= MAPBIT << i_bit; |
186 | iter_bit++; | ||
187 | src_byte <<= 1; | 183 | src_byte <<= 1; |
188 | } | 184 | } |
189 | } while (iter < iter_limit); | 185 | } |
190 | 186 | ||
191 | if (node_last != NULL) | 187 | if (node_last != NULL) |
192 | node_last->next = node_new; | 188 | node_last->next = node_new; |
193 | else | 189 | else |
194 | dst->node = node_new; | 190 | dst->node = node_new; |
195 | node_last = node_new; | 191 | node_last = node_new; |
196 | } while (src_off < src_len); | 192 | } |
197 | 193 | ||
198 | if (likely(node_last != NULL)) | 194 | if (likely(node_last != NULL)) |
199 | dst->highbit = node_last->startbit + MAPSIZE; | 195 | dst->highbit = node_last->startbit + MAPSIZE; |