Skip to content

Commit

Permalink
selinux: Return an error code only as a constant in sidtab_insert()
Browse files Browse the repository at this point in the history
* Return an error code without storing it in an intermediate variable.

* Delete the local variable "rc" and the jump label "out" which became
  unnecessary with this refactoring.

Signed-off-by: Markus Elfring <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
  • Loading branch information
elfring authored and pcmoore committed May 23, 2017
1 parent 62934ff commit 46be14d
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions security/selinux/ss/sidtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ int sidtab_init(struct sidtab *s)

int sidtab_insert(struct sidtab *s, u32 sid, struct context *context)
{
int hvalue, rc = 0;
int hvalue;
struct sidtab_node *prev, *cur, *newnode;

if (!s) {
rc = -ENOMEM;
goto out;
}
if (!s)
return -ENOMEM;

hvalue = SIDTAB_HASH(sid);
prev = NULL;
Expand All @@ -48,21 +46,17 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context)
cur = cur->next;
}

if (cur && sid == cur->sid) {
rc = -EEXIST;
goto out;
}
if (cur && sid == cur->sid)
return -EEXIST;

newnode = kmalloc(sizeof(*newnode), GFP_ATOMIC);
if (!newnode) {
rc = -ENOMEM;
goto out;
}
if (!newnode)
return -ENOMEM;

newnode->sid = sid;
if (context_cpy(&newnode->context, context)) {
kfree(newnode);
rc = -ENOMEM;
goto out;
return -ENOMEM;
}

if (prev) {
Expand All @@ -78,8 +72,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context)
s->nel++;
if (sid >= s->next_sid)
s->next_sid = sid + 1;
out:
return rc;
return 0;
}

static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)
Expand Down

0 comments on commit 46be14d

Please sign in to comment.