Commit 92ae9e82 authored by Eric Paris's avatar Eric Paris

SELinux: remove needless sel_div function

I'm not really sure what the idea behind the sel_div function is, but it's
useless.  Since a and b are both unsigned, it's impossible for a % b < 0.
That means that part of the function never does anything.  Thus it's just a
normal /.  Just do that instead.  I don't even understand what that operation
was supposed to mean in the signed case however....

If it was signed:
sel_div(-2, 4) == ((-2 / 4) - ((-2 % 4) < 0))
		  ((0)      - ((-2)     < 0))
		  ((0)      - (1))
		  (-1)

What actually happens:
sel_div(-2, 4) == ((18446744073709551614 / 4) - ((18446744073709551614 % 4) < 0))
		  ((4611686018427387903)      - ((2 < 0))
		  (4611686018427387903        - 0)
		  ((unsigned int)4611686018427387903)
		  (4294967295)

Neither makes a whole ton of sense to me.  So I'm getting rid of the
function entirely.
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
parent bb7081ab
...@@ -1533,11 +1533,6 @@ static int sel_make_initcon_files(struct dentry *dir) ...@@ -1533,11 +1533,6 @@ static int sel_make_initcon_files(struct dentry *dir)
return 0; return 0;
} }
static inline unsigned int sel_div(unsigned long a, unsigned long b)
{
return a / b - (a % b < 0);
}
static inline unsigned long sel_class_to_ino(u16 class) static inline unsigned long sel_class_to_ino(u16 class)
{ {
return (class * (SEL_VEC_MAX + 1)) | SEL_CLASS_INO_OFFSET; return (class * (SEL_VEC_MAX + 1)) | SEL_CLASS_INO_OFFSET;
...@@ -1545,7 +1540,7 @@ static inline unsigned long sel_class_to_ino(u16 class) ...@@ -1545,7 +1540,7 @@ static inline unsigned long sel_class_to_ino(u16 class)
static inline u16 sel_ino_to_class(unsigned long ino) static inline u16 sel_ino_to_class(unsigned long ino)
{ {
return sel_div(ino & SEL_INO_MASK, SEL_VEC_MAX + 1); return (ino & SEL_INO_MASK) / (SEL_VEC_MAX + 1);
} }
static inline unsigned long sel_perm_to_ino(u16 class, u32 perm) static inline unsigned long sel_perm_to_ino(u16 class, u32 perm)
......
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