Date: Sat, 17 Nov 2018 19:00:44 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r340504 - stable/12/sys/netinet Message-ID: <201811171900.wAHJ0iLV016195@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Sat Nov 17 19:00:44 2018 New Revision: 340504 URL: https://svnweb.freebsd.org/changeset/base/340504 Log: MFC r340004: Improve style in in_pcbinslbgrouphash() and related subroutines. Modified: stable/12/sys/netinet/in_pcb.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/netinet/in_pcb.c ============================================================================== --- stable/12/sys/netinet/in_pcb.c Sat Nov 17 18:58:06 2018 (r340503) +++ stable/12/sys/netinet/in_pcb.c Sat Nov 17 19:00:44 2018 (r340504) @@ -266,7 +266,7 @@ in_pcblbgroup_resize(struct inpcblbgrouphead *hdr, grp = in_pcblbgroup_alloc(hdr, old_grp->il_vflag, old_grp->il_lport, &old_grp->il_dependladdr, size); - if (!grp) + if (grp == NULL) return (NULL); KASSERT(old_grp->il_inpcnt < grp->il_inpsiz, @@ -288,21 +288,20 @@ static void in_pcblbgroup_reorder(struct inpcblbgrouphead *hdr, struct inpcblbgroup **grpp, int i) { - struct inpcblbgroup *grp = *grpp; + struct inpcblbgroup *grp, *new_grp; + grp = *grpp; for (; i + 1 < grp->il_inpcnt; ++i) grp->il_inp[i] = grp->il_inp[i + 1]; grp->il_inpcnt--; if (grp->il_inpsiz > INPCBLBGROUP_SIZMIN && - grp->il_inpcnt <= (grp->il_inpsiz / 4)) { + grp->il_inpcnt <= grp->il_inpsiz / 4) { /* Shrink this group. */ - struct inpcblbgroup *new_grp = - in_pcblbgroup_resize(hdr, grp, grp->il_inpsiz / 2); - if (new_grp) + new_grp = in_pcblbgroup_resize(hdr, grp, grp->il_inpsiz / 2); + if (new_grp != NULL) *grpp = new_grp; } - return; } /* @@ -316,9 +315,7 @@ in_pcbinslbgrouphash(struct inpcb *inp) struct inpcbinfo *pcbinfo; struct inpcblbgrouphead *hdr; struct inpcblbgroup *grp; - uint16_t hashmask, lport; - uint32_t group_index; - struct ucred *cred; + uint32_t idx; pcbinfo = inp->inp_pcbinfo; @@ -328,19 +325,10 @@ in_pcbinslbgrouphash(struct inpcb *inp) if (pcbinfo->ipi_lbgrouphashbase == NULL) return (0); - hashmask = pcbinfo->ipi_lbgrouphashmask; - lport = inp->inp_lport; - group_index = INP_PCBLBGROUP_PORTHASH(lport, hashmask); - hdr = &pcbinfo->ipi_lbgrouphashbase[group_index]; - /* * Don't allow jailed socket to join local group. */ - if (inp->inp_socket != NULL) - cred = inp->inp_socket->so_cred; - else - cred = NULL; - if (cred != NULL && jailed(cred)) + if (inp->inp_socket != NULL && jailed(inp->inp_socket->so_cred)) return (0); #ifdef INET6 @@ -354,24 +342,23 @@ in_pcbinslbgrouphash(struct inpcb *inp) } #endif - hdr = &pcbinfo->ipi_lbgrouphashbase[ - INP_PCBLBGROUP_PORTHASH(inp->inp_lport, - pcbinfo->ipi_lbgrouphashmask)]; + idx = INP_PCBLBGROUP_PORTHASH(inp->inp_lport, + pcbinfo->ipi_lbgrouphashmask); + hdr = &pcbinfo->ipi_lbgrouphashbase[idx]; CK_LIST_FOREACH(grp, hdr, il_list) { if (grp->il_vflag == inp->inp_vflag && grp->il_lport == inp->inp_lport && memcmp(&grp->il_dependladdr, - &inp->inp_inc.inc_ie.ie_dependladdr, - sizeof(grp->il_dependladdr)) == 0) { + &inp->inp_inc.inc_ie.ie_dependladdr, + sizeof(grp->il_dependladdr)) == 0) break; - } } if (grp == NULL) { /* Create new load balance group. */ grp = in_pcblbgroup_alloc(hdr, inp->inp_vflag, inp->inp_lport, &inp->inp_inc.inc_ie.ie_dependladdr, INPCBLBGROUP_SIZMIN); - if (!grp) + if (grp == NULL) return (ENOBUFS); } else if (grp->il_inpcnt == grp->il_inpsiz) { if (grp->il_inpsiz >= INPCBLBGROUP_SIZMAX) { @@ -383,13 +370,13 @@ in_pcbinslbgrouphash(struct inpcb *inp) /* Expand this local group. */ grp = in_pcblbgroup_resize(hdr, grp, grp->il_inpsiz * 2); - if (!grp) + if (grp == NULL) return (ENOBUFS); } KASSERT(grp->il_inpcnt < grp->il_inpsiz, - ("invalid local group size %d and count %d", - grp->il_inpsiz, grp->il_inpcnt)); + ("invalid local group size %d and count %d", grp->il_inpsiz, + grp->il_inpcnt)); grp->il_inp[grp->il_inpcnt] = inp; grp->il_inpcnt++;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811171900.wAHJ0iLV016195>