Skip to content

Commit 83e7e18

Browse files
cgzonespcmoore
authored andcommitted
selinux: rename comparison functions for clarity
The functions context_cmp(), mls_context_cmp() and ebitmap_cmp() are not traditional C style compare functions returning -1, 0, and 1 for less than, equal, and greater than; they only return whether their arguments are equal. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 5e99b81 commit 83e7e18

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

security/selinux/ss/context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ u32 context_compute_hash(const struct context *c)
2020
* context struct with only the len & str set (and vice versa)
2121
* under a given policy. Since context structs from different
2222
* policies should never meet, it is safe to hash valid and
23-
* invalid contexts differently. The context_cmp() function
23+
* invalid contexts differently. The context_equal() function
2424
* already operates under the same assumption.
2525
*/
2626
if (c->len)

security/selinux/ss/context.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ static inline int mls_context_glblub(struct context *dst,
132132
return rc;
133133
}
134134

135-
static inline int mls_context_cmp(const struct context *c1,
136-
const struct context *c2)
135+
static inline bool mls_context_equal(const struct context *c1,
136+
const struct context *c2)
137137
{
138138
return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
139-
ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
139+
ebitmap_equal(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
140140
(c1->range.level[1].sens == c2->range.level[1].sens) &&
141-
ebitmap_cmp(&c1->range.level[1].cat, &c2->range.level[1].cat));
141+
ebitmap_equal(&c1->range.level[1].cat, &c2->range.level[1].cat));
142142
}
143143

144144
static inline void mls_context_destroy(struct context *c)
@@ -188,15 +188,15 @@ static inline void context_destroy(struct context *c)
188188
mls_context_destroy(c);
189189
}
190190

191-
static inline int context_cmp(const struct context *c1,
192-
const struct context *c2)
191+
static inline bool context_equal(const struct context *c1,
192+
const struct context *c2)
193193
{
194194
if (c1->len && c2->len)
195195
return (c1->len == c2->len && !strcmp(c1->str, c2->str));
196196
if (c1->len || c2->len)
197197
return 0;
198198
return ((c1->user == c2->user) && (c1->role == c2->role) &&
199-
(c1->type == c2->type) && mls_context_cmp(c1, c2));
199+
(c1->type == c2->type) && mls_context_equal(c1, c2));
200200
}
201201

202202
u32 context_compute_hash(const struct context *c);

security/selinux/ss/ebitmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
static struct kmem_cache *ebitmap_node_cachep __ro_after_init;
2727

28-
int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
28+
bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2)
2929
{
3030
const struct ebitmap_node *n1, *n2;
3131

3232
if (e1->highbit != e2->highbit)
33-
return 0;
33+
return false;
3434

3535
n1 = e1->node;
3636
n2 = e2->node;
@@ -41,9 +41,9 @@ int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
4141
}
4242

4343
if (n1 || n2)
44-
return 0;
44+
return false;
4545

46-
return 1;
46+
return true;
4747
}
4848

4949
int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src)

security/selinux/ss/ebitmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n, u32 bit)
120120
(bit) < ebitmap_length(e); \
121121
(bit) = ebitmap_next_positive(e, &(n), bit))
122122

123-
int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2);
123+
bool ebitmap_equal(const struct ebitmap *e1, const struct ebitmap *e2);
124124
int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src);
125125
int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1,
126126
const struct ebitmap *e2);

security/selinux/ss/mls_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct mls_range {
2929
static inline int mls_level_eq(const struct mls_level *l1,
3030
const struct mls_level *l2)
3131
{
32-
return ((l1->sens == l2->sens) && ebitmap_cmp(&l1->cat, &l2->cat));
32+
return ((l1->sens == l2->sens) && ebitmap_equal(&l1->cat, &l2->cat));
3333
}
3434

3535
static inline int mls_level_dom(const struct mls_level *l1,

security/selinux/ss/services.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,7 @@ int security_net_peersid_resolve(u32 nlbl_sid, u32 nlbl_type,
33313331
__func__, xfrm_sid);
33323332
goto out;
33333333
}
3334-
rc = (mls_context_cmp(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
3334+
rc = (mls_context_equal(nlbl_ctx, xfrm_ctx) ? 0 : -EACCES);
33353335
if (rc)
33363336
goto out;
33373337

security/selinux/ss/sidtab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static u32 context_to_sid(struct sidtab *s, struct context *context, u32 hash)
6666
hash_for_each_possible_rcu(s->context_to_sid, entry, list, hash) {
6767
if (entry->hash != hash)
6868
continue;
69-
if (context_cmp(&entry->context, context)) {
69+
if (context_equal(&entry->context, context)) {
7070
sid = entry->sid;
7171
break;
7272
}

0 commit comments

Comments
 (0)