#endif
 
 struct policydb_compat_info {
-       int version;
-       int sym_num;
-       int ocon_num;
+       unsigned int version;
+       unsigned int sym_num;
+       unsigned int ocon_num;
 };
 
 /* These need to be updated if SYM_NUM or OCON_NUM changes */
        },
 };
 
-static const struct policydb_compat_info *policydb_lookup_compat(int version)
+static const struct policydb_compat_info *policydb_lookup_compat(unsigned int version)
 {
-       int i;
+       unsigned int i;
 
        for (i = 0; i < ARRAY_SIZE(policydb_compat); i++) {
                if (policydb_compat[i].version == version)
        return 0;
 }
 
-static void ocontext_destroy(struct ocontext *c, int i)
+static void ocontext_destroy(struct ocontext *c, unsigned int i)
 {
        if (!c)
                return;
 {
        struct ocontext *c, *ctmp;
        struct genfs *g, *gtmp;
-       int i;
+       u32 i;
        struct role_allow *ra, *lra = NULL;
 
        for (i = 0; i < SYM_NUM; i++) {
        char *key = NULL;
        struct common_datum *comdatum;
        __le32 buf[4];
-       u32 len, nel;
-       int i, rc;
+       u32 i, len, nel;
+       int rc;
 
        comdatum = kzalloc(sizeof(*comdatum), GFP_KERNEL);
        if (!comdatum)
 
 static int read_cons_helper(struct policydb *p,
                                struct constraint_node **nodep,
-                               int ncons, int allowxtarget, void *fp)
+                               u32 ncons, int allowxtarget, void *fp)
 {
        struct constraint_node *c, *lc;
        struct constraint_expr *e, *le;
        __le32 buf[3];
-       u32 nexpr;
-       int rc, i, j, depth;
+       u32 i, j, nexpr;
+       int rc, depth;
 
        lc = NULL;
        for (i = 0; i < ncons; i++) {
        char *key = NULL;
        struct class_datum *cladatum;
        __le32 buf[6];
-       u32 len, len2, ncons, nel;
-       int i, rc;
+       u32 i, len, len2, ncons, nel;
+       int rc;
 
        cladatum = kzalloc(sizeof(*cladatum), GFP_KERNEL);
        if (!cladatum)
 {
        char *key = NULL;
        struct role_datum *role;
-       int rc, to_read = 2;
+       int rc;
+       unsigned int to_read = 2;
        __le32 buf[3];
        u32 len;
 
 {
        char *key = NULL;
        struct type_datum *typdatum;
-       int rc, to_read = 3;
+       int rc;
+       unsigned int to_read = 3;
        __le32 buf[4];
        u32 len;
 
 {
        char *key = NULL;
        struct user_datum *usrdatum;
-       int rc, to_read = 2;
+       int rc;
+       unsigned int to_read = 2;
        __le32 buf[3];
        u32 len;
 
        upper = user = datum;
        while (upper->bounds) {
                struct ebitmap_node *node;
-               unsigned long bit;
+               u32 bit;
 
                if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
                        pr_err("SELinux: user %s: "
        upper = role = datum;
        while (upper->bounds) {
                struct ebitmap_node *node;
-               unsigned long bit;
+               u32 bit;
 
                if (++depth == POLICYDB_BOUNDS_MAXDEPTH) {
                        pr_err("SELinux: role %s: "
 {
        struct range_trans *rt = NULL;
        struct mls_range *r = NULL;
-       int i, rc;
+       int rc;
        __le32 buf[2];
-       u32 nel;
+       u32 i, nel;
 
        if (p->policyvers < POLICYDB_VERSION_MLS)
                return 0;
 
 static int filename_trans_read(struct policydb *p, void *fp)
 {
-       u32 nel;
+       u32 nel, i;
        __le32 buf[1];
-       int rc, i;
+       int rc;
 
        if (p->policyvers < POLICYDB_VERSION_FILENAME_TRANS)
                return 0;
 
 static int genfs_read(struct policydb *p, void *fp)
 {
-       int i, j, rc;
-       u32 nel, nel2, len, len2;
+       int rc;
+       u32 i, j, nel, nel2, len, len2;
        __le32 buf[1];
        struct ocontext *l, *c;
        struct ocontext *newc = NULL;
 static int ocontext_read(struct policydb *p, const struct policydb_compat_info *info,
                         void *fp)
 {
-       int i, j, rc;
-       u32 nel, len;
+       int rc;
+       unsigned int i;
+       u32 j, nel, len;
        __be64 prefixbuf[1];
        __le32 buf[3];
        struct ocontext *l, *c;
        struct role_allow *ra, *lra;
        struct role_trans_key *rtk = NULL;
        struct role_trans_datum *rtd = NULL;
-       int i, j, rc;
+       int rc;
        __le32 buf[4];
-       u32 len, nprim, nel, perm;
+       u32 i, j, len, nprim, nel, perm;
 
        char *policydb_str;
        const struct policydb_compat_info *info;
 static int ocontext_write(struct policydb *p, const struct policydb_compat_info *info,
                          void *fp)
 {
-       unsigned int i, j, rc;
+       unsigned int i, j;
+       int rc;
        size_t nel, len;
        __be64 prefixbuf[1];
        __le32 buf[3];
  */
 int policydb_write(struct policydb *p, void *fp)
 {
-       unsigned int i, num_syms;
+       unsigned int num_syms;
        int rc;
        __le32 buf[4];
-       u32 config;
+       u32 config, i;
        size_t len;
        const struct policydb_compat_info *info;