From owner-svn-src-stable-8@FreeBSD.ORG Tue Jan 11 17:31:59 2011 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D5D0106564A; Tue, 11 Jan 2011 17:31:59 +0000 (UTC) (envelope-from mdf@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5C7668FC12; Tue, 11 Jan 2011 17:31:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p0BHVxJl027763; Tue, 11 Jan 2011 17:31:59 GMT (envelope-from mdf@svn.freebsd.org) Received: (from mdf@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0BHVxBL027761; Tue, 11 Jan 2011 17:31:59 GMT (envelope-from mdf@svn.freebsd.org) Message-Id: <201101111731.p0BHVxBL027761@svn.freebsd.org> From: Matthew D Fleming Date: Tue, 11 Jan 2011 17:31:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r217271 - stable/8/sys/kern X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jan 2011 17:31:59 -0000 Author: mdf Date: Tue Jan 11 17:31:59 2011 New Revision: 217271 URL: http://svn.freebsd.org/changeset/base/217271 Log: MFC r216058 and r216059: r216058: Use the SYSCTL_CHILDREN macro in kern_sysctl.c to help de-obfuscate the code. r216059: Slightly modify the logic in sysctl_find_oid to reduce the indentation. There should be no functional change. Modified: stable/8/sys/kern/kern_sysctl.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/kern/kern_sysctl.c ============================================================================== --- stable/8/sys/kern/kern_sysctl.c Tue Jan 11 17:29:34 2011 (r217270) +++ stable/8/sys/kern/kern_sysctl.c Tue Jan 11 17:31:59 2011 (r217271) @@ -675,7 +675,7 @@ sysctl_sysctl_name(SYSCTL_HANDLER_ARGS) if (oid->oid_handler) break; - lsp2 = (struct sysctl_oid_list *)oid->oid_arg1; + lsp2 = SYSCTL_CHILDREN(oid); break; } lsp = lsp2; @@ -706,7 +706,7 @@ sysctl_sysctl_next_ls(struct sysctl_oid_ if (oidp->oid_handler) /* We really should call the handler here...*/ return (0); - lsp = (struct sysctl_oid_list *)oidp->oid_arg1; + lsp = SYSCTL_CHILDREN(oidp); if (!sysctl_sysctl_next_ls(lsp, 0, 0, next+1, len, level+1, oidpp)) return (0); @@ -721,7 +721,7 @@ sysctl_sysctl_next_ls(struct sysctl_oid_ return (0); if (oidp->oid_handler) return (0); - lsp = (struct sysctl_oid_list *)oidp->oid_arg1; + lsp = SYSCTL_CHILDREN(oidp); if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, len, level+1, oidpp)) return (0); @@ -733,7 +733,7 @@ sysctl_sysctl_next_ls(struct sysctl_oid_ if (oidp->oid_handler) continue; - lsp = (struct sysctl_oid_list *)oidp->oid_arg1; + lsp = SYSCTL_CHILDREN(oidp); if (!sysctl_sysctl_next_ls(lsp, name+1, namelen-1, next+1, len, level+1, oidpp)) return (0); @@ -811,7 +811,7 @@ name2oid(char *name, int *oid, int *len, if (oidp->oid_handler) break; - lsp = (struct sysctl_oid_list *)oidp->oid_arg1; + lsp = SYSCTL_CHILDREN(oidp); oidp = SLIST_FIRST(lsp); name = p+1; for (p = name; *p && *p != '.'; p++) @@ -1302,37 +1302,39 @@ int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, int *nindx, struct sysctl_req *req) { + struct sysctl_oid_list *lsp; struct sysctl_oid *oid; int indx; SYSCTL_ASSERT_LOCKED(); - oid = SLIST_FIRST(&sysctl__children); + lsp = &sysctl__children; indx = 0; - while (oid && indx < CTL_MAXNAME) { - if (oid->oid_number == name[indx]) { - indx++; - if (oid->oid_kind & CTLFLAG_NOLOCK) - req->lock = REQ_UNLOCKED; - if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) { - if (oid->oid_handler != NULL || - indx == namelen) { - *noid = oid; - if (nindx != NULL) - *nindx = indx; - return (0); - } - oid = SLIST_FIRST( - (struct sysctl_oid_list *)oid->oid_arg1); - } else if (indx == namelen) { + while (indx < CTL_MAXNAME) { + SLIST_FOREACH(oid, lsp, oid_link) { + if (oid->oid_number == name[indx]) + break; + } + if (oid == NULL) + return (ENOENT); + + indx++; + if (oid->oid_kind & CTLFLAG_NOLOCK) + req->lock = REQ_UNLOCKED; + if ((oid->oid_kind & CTLTYPE) == CTLTYPE_NODE) { + if (oid->oid_handler != NULL || indx == namelen) { *noid = oid; if (nindx != NULL) *nindx = indx; return (0); - } else { - return (ENOTDIR); } + lsp = SYSCTL_CHILDREN(oid); + } else if (indx == namelen) { + *noid = oid; + if (nindx != NULL) + *nindx = indx; + return (0); } else { - oid = SLIST_NEXT(oid, oid_link); + return (ENOTDIR); } } return (ENOENT);