From owner-p4-projects@FreeBSD.ORG Wed Feb 23 21:56:11 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7CA3C16A4D1; Wed, 23 Feb 2005 21:56:11 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0EEEA16A4CE for ; Wed, 23 Feb 2005 21:56:11 +0000 (GMT) Received: from mail27.sea5.speakeasy.net (mail27.sea5.speakeasy.net [69.17.117.29]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8E41243D31 for ; Wed, 23 Feb 2005 21:56:10 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: (qmail 10076 invoked from network); 23 Feb 2005 21:56:10 -0000 Received: from server.baldwin.cx ([216.27.160.63]) (envelope-sender )AES256-SHA encrypted SMTP for ; 23 Feb 2005 21:56:09 -0000 Received: from [10.50.40.202] (gw1.twc.weather.com [216.133.140.1]) (authenticated bits=0) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id j1NLu3Lm025532; Wed, 23 Feb 2005 16:56:04 -0500 (EST) (envelope-from jhb@FreeBSD.org) From: John Baldwin To: Robert Watson Date: Wed, 23 Feb 2005 16:49:10 -0500 User-Agent: KMail/1.6.2 References: <200502231910.j1NJAfu3078510@repoman.freebsd.org> In-Reply-To: <200502231910.j1NJAfu3078510@repoman.freebsd.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200502231649.10125.jhb@FreeBSD.org> X-Spam-Status: No, score=-102.8 required=4.2 tests=ALL_TRUSTED, USER_IN_WHITELIST autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx cc: Perforce Change Reviews Subject: Re: PERFORCE change 71680 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Feb 2005 21:56:12 -0000 On Wednesday 23 February 2005 02:10 pm, Robert Watson wrote: > http://perforce.freebsd.org/chv.cgi?CH=71680 > > Change 71680 by rwatson@rwatson_paprika on 2005/02/23 19:10:39 > > Re-lay out mac_bsdextended sysctl to copyin, lock+dowork+unlock, > copyout. > > Suggested by: jhb > > Affected files ... > > .. > //depot/projects/trustedbsd/mac/sys/security/mac_bsdextended/mac_bsdextende >d.c#87 edit > > Differences ... > > ==== > //depot/projects/trustedbsd/mac/sys/security/mac_bsdextended/mac_bsdextende >d.c#87 (text+ko) ==== > > @@ -152,69 +152,68 @@ > if (index > MAC_BSDEXTENDED_MAXRULES) > return (ENOENT); > > + ruleptr = NULL; > + if (req->newptr) { > + error = SYSCTL_IN(req, &temprule, sizeof(temprule)); > + if (error) > + return (error); > + MALLOC(ruleptr, struct mac_bsdextended_rule *, > + sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | M_ZERO); > + } > + > + mtx_lock(&mac_bsdextended_mtx); > + > if (req->oldptr) { > - mtx_lock(&mac_bsdextended_mtx); > if (index < 0 || index > rule_slots + 1) { > - mtx_unlock(&mac_bsdextended_mtx); > - return (ENOENT); > + error = ENOENT; > + goto out; > } > - > if (rules[index] == NULL) { > - mtx_unlock(&mac_bsdextended_mtx); > - return (ENOENT); > + error = ENOENT; > + goto out; > } > - > temprule = *rules[index]; > - mtx_unlock(&mac_bsdextended_mtx); > - > - error = SYSCTL_OUT(req, &temprule, sizeof(temprule)); > - > - if (error) > - return (error); > } > > - if (req->newptr) { > - if (req->newlen == 0) { > - /* printf("deletion\n"); */ > - mtx_lock(&mac_bsdextended_mtx); > - ruleptr = rules[index]; > - if (ruleptr == NULL) { > - mtx_unlock(&mac_bsdextended_mtx); > - return (ENOENT); > - } > - rule_count--; > - rules[index] = NULL; > - mtx_unlock(&mac_bsdextended_mtx); > - FREE(ruleptr, M_MACBSDEXTENDED); > - return(0); > + if (req->newptr && req->newlen == 0) { > + /* printf("deletion\n"); */ > + FREE(ruleptr, M_MACBSDEXTENDED); > + ruleptr = rules[index]; > + if (ruleptr == NULL) { > + error = ENOENT; > + goto out; > } > - error = SYSCTL_IN(req, &temprule, sizeof(temprule)); > - if (error) > - return (error); > - > + rule_count--; > + rules[index] = NULL; > + } else if (req->newptr) { > error = mac_bsdextended_rule_valid(&temprule); > if (error) > - return (error); > + goto out; > > - MALLOC(ruleptr, struct mac_bsdextended_rule *, > - sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | M_ZERO); > - mtx_lock(&mac_bsdextended_mtx); > if (rules[index] == NULL) { > /* printf("addition\n"); */ > *ruleptr = temprule; > rules[index] = ruleptr; > + ruleptr = NULL; > if (index + 1 > rule_slots) > rule_slots = index + 1; > rule_count++; > - mtx_unlock(&mac_bsdextended_mtx); > } else { > /* printf("replacement\n"); */ > *rules[index] = temprule; > - mtx_unlock(&mac_bsdextended_mtx); > - FREE(ruleptr, M_MACBSDEXTENDED); > } > } > > +out: > + mtx_unlock(&mac_bsdextended_mtx); > + if (ruleptr != NULL) > + FREE(ruleptr, M_MACBSDEXTENDED); > + if (req->oldptr && error == 0) { > + error = SYSCTL_OUT(req, &temprule, sizeof(temprule)); > + if (error) > + return (error); > + } > + > return (0); > } You can simplify this last bit by making the function 'return (error);' and dropping the whole 'if (error) return (error);' after the SYSCTL_OUT(). :) Purely optional of course. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org