netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: paul.moore@hp.com
To: netdev@vger.kernel.org, selinux@tycho.nsa.gov
Cc: jmorris@namei.org, sds@tycho.nsa.gov, akpm@osdl.org,
	Paul Moore <paul.moore@hp.com>
Subject: [PATCH 4/6] NetLabel: cleanup ebitmap_import()
Date: Tue, 29 Aug 2006 10:42:55 -0400	[thread overview]
Message-ID: <20060829144446.324001000@hp.com> (raw)
In-Reply-To: 20060829144251.452774000@hp.com

[-- Attachment #1: netlabel-loop_fixups --]
[-- Type: text/plain, Size: 2306 bytes --]

Rewrite ebitmap_import() so it is a bit cleaner and easier to read.

Signed-off-by: Paul Moore <paul.moore@hp.com>
---
 security/selinux/ss/ebitmap.c |   36 ++++++++++++++++--------------------
 1 files changed, 16 insertions(+), 20 deletions(-)

Index: net-2.6.19/security/selinux/ss/ebitmap.c
===================================================================
--- net-2.6.19.orig/security/selinux/ss/ebitmap.c
+++ net-2.6.19/security/selinux/ss/ebitmap.c
@@ -145,29 +145,28 @@ int ebitmap_import(const unsigned char *
 		   struct ebitmap *dst)
 {
 	size_t src_off = 0;
+	size_t node_limit;
 	struct ebitmap_node *node_new;
 	struct ebitmap_node *node_last = NULL;
-	size_t iter;
-	size_t iter_bit;
-	size_t iter_limit;
+	u32 i_byte;
+	u32 i_bit;
 	unsigned char src_byte;
 
-	do {
-		iter_limit = src_len - src_off;
-		if (iter_limit >= sizeof(MAPTYPE)) {
+	while (src_off < src_len) {
+		if (src_len - src_off >= sizeof(MAPTYPE)) {
 			if (*(MAPTYPE *)&src[src_off] == 0) {
 				src_off += sizeof(MAPTYPE);
 				continue;
 			}
-			iter_limit = sizeof(MAPTYPE);
+			node_limit = sizeof(MAPTYPE);
 		} else {
-			iter = src_off;
-			src_byte = 0;
-			do {
-				src_byte |= src[iter++];
-			} while (iter < src_len && src_byte == 0);
+			for (src_byte = 0, i_byte = src_off;
+			     i_byte < src_len && src_byte == 0;
+			     i_byte++)
+				src_byte |= src[i_byte];
 			if (src_byte == 0)
 				break;
+			node_limit = src_len - src_off;
 		}
 
 		node_new = kzalloc(sizeof(*node_new), GFP_ATOMIC);
@@ -176,24 +175,21 @@ int ebitmap_import(const unsigned char *
 			return -ENOMEM;
 		}
 		node_new->startbit = src_off * 8;
-		iter = 0;
-		do {
+		for (i_byte = 0; i_byte < node_limit; i_byte++) {
 			src_byte = src[src_off++];
-			iter_bit = iter++ * 8;
-			while (src_byte != 0) {
+			for (i_bit = i_byte * 8; src_byte != 0; i_bit++) {
 				if (src_byte & 0x80)
-					node_new->map |= MAPBIT << iter_bit;
-				iter_bit++;
+					node_new->map |= MAPBIT << i_bit;
 				src_byte <<= 1;
 			}
-		} while (iter < iter_limit);
+		}
 
 		if (node_last != NULL)
 			node_last->next = node_new;
 		else
 			dst->node = node_new;
 		node_last = node_new;
-	} while (src_off < src_len);
+	}
 
 	if (likely(node_last != NULL))
 		dst->highbit = node_last->startbit + MAPSIZE;

--
paul moore
linux security @ hp

  parent reply	other threads:[~2006-08-29 14:44 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-29 14:42 [PATCH 0/6] Various NetLabel fixes and cleanups paul.moore
2006-08-29 14:42 ` [PATCH 1/6] NetLabel: correctly initialize the NetLabel fields paul.moore
2006-08-29 16:51   ` James Morris
2006-08-29 17:56     ` Paul Moore
2006-08-29 19:17       ` James Morris
2006-08-29 20:21         ` Paul Moore
2006-08-29 17:01   ` James Morris
2006-08-29 14:42 ` [PATCH 2/6] NetLabel: remove unused function prototypes paul.moore
2006-08-29 16:56   ` James Morris
2006-08-29 14:42 ` [PATCH 3/6] NetLabel: comment corrections paul.moore
2006-08-29 16:57   ` James Morris
2006-08-29 14:42 ` paul.moore [this message]
2006-08-29 16:58   ` [PATCH 4/6] NetLabel: cleanup ebitmap_import() James Morris
2006-08-29 14:42 ` [PATCH 5/6] NetLabel: uninline selinux_netlbl_inode_permission() paul.moore
2006-08-29 16:54   ` James Morris
2006-08-29 14:42 ` [PATCH 6/6] NetLabel: add some missing #includes to various header files paul.moore
2006-08-29 16:56   ` James Morris
2006-08-30  0:56 ` [PATCH 0/6] Various NetLabel fixes and cleanups David Miller
2006-08-30 13:18   ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060829144446.324001000@hp.com \
    --to=paul.moore@hp.com \
    --cc=akpm@osdl.org \
    --cc=jmorris@namei.org \
    --cc=netdev@vger.kernel.org \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).