Skip to content

Commit fc328c8

Browse files
gscuipcmoore
authored andcommitted
selinux: refactor code to return ERR_PTR in selinux_netlbl_sock_genattr
Refactor the code in selinux_netlbl_sock_genattr to return ERR_PTR when an error occurs. Signed-off-by: Gaosheng Cui <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent da2d413 commit fc328c8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

security/selinux/netlabel.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int selinux_netlbl_sidlookup_cached(struct sk_buff *skb,
6262
* Description:
6363
* Generate the NetLabel security attributes for a socket, making full use of
6464
* the socket's attribute cache. Returns a pointer to the security attributes
65-
* on success, NULL on failure.
65+
* on success, or an ERR_PTR on failure.
6666
*
6767
*/
6868
static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk)
@@ -76,11 +76,12 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk)
7676

7777
secattr = netlbl_secattr_alloc(GFP_ATOMIC);
7878
if (secattr == NULL)
79-
return NULL;
79+
return ERR_PTR(-ENOMEM);
80+
8081
rc = security_netlbl_sid_to_secattr(sksec->sid, secattr);
8182
if (rc != 0) {
8283
netlbl_secattr_free(secattr);
83-
return NULL;
84+
return ERR_PTR(rc);
8485
}
8586
sksec->nlbl_secattr = secattr;
8687

@@ -400,8 +401,8 @@ int selinux_netlbl_socket_post_create(struct sock *sk, u16 family)
400401
return 0;
401402

402403
secattr = selinux_netlbl_sock_genattr(sk);
403-
if (secattr == NULL)
404-
return -ENOMEM;
404+
if (IS_ERR(secattr))
405+
return PTR_ERR(secattr);
405406
/* On socket creation, replacement of IP options is safe even if
406407
* the caller does not hold the socket lock.
407408
*/
@@ -561,10 +562,9 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk,
561562
return rc;
562563
}
563564
secattr = selinux_netlbl_sock_genattr(sk);
564-
if (secattr == NULL) {
565-
rc = -ENOMEM;
566-
return rc;
567-
}
565+
if (IS_ERR(secattr))
566+
return PTR_ERR(secattr);
567+
568568
rc = netlbl_conn_setattr(sk, addr, secattr);
569569
if (rc == 0)
570570
sksec->nlbl_state = NLBL_CONNLABELED;

0 commit comments

Comments
 (0)