From patchwork Wed Apr 2 09:40:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 387 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id A78C73600B4 for ; Wed, 2 Apr 2014 02:39:36 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14307373) id 65CE24483864; Wed, 2 Apr 2014 02:39:36 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 353AD4483847 for ; Wed, 2 Apr 2014 02:39:36 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=Jr1x s29PjJyeHrv5mjSexC7vZKPaORyJNVPeB4MQ926woNU5c7iZYY/A+ku7B0HJZgZU ykbNdtMiczaB/O9IRk0kjetzINmE4Soiu0mfCbCUwPrAWKXQKbCHt18kVv2eenUv RgpqO7BhhqGD/AhSMHm2Gw6zgt2Tj7Ubmv9EbJE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=9fx75RT4Dy 3Gj2UTJjPoDKq3hmU=; b=MoAQiW688FdCff08mYe9DtZyZaO9TEopcwmv5ThJjb y/2W3jqpZxD3PWPy1ZquQ6VBvuUKVLJcJ3KWYePLZSThcTq9lyUowPRnJ7tClmY3 33RM8gJmJNI4S4aUMdN5+223k/YJDetIW19emryTQe392zjmCDTk02bWjmOviMmG 8= Received: (qmail 4228 invoked by alias); 2 Apr 2014 09:39:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 4216 invoked by uid 89); 2 Apr 2014 09:39:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Wed, 2 Apr 2014 15:10:12 +0530 From: Siddhesh Poyarekar To: Mike Frysinger Cc: libc-alpha@sourceware.org, Roland McGrath Subject: Re: [PATCH 2/2] Initialize all of datahead structure in nscd [BZ #16791] Message-ID: <20140402094011.GD23931@spoyarek.pnq.redhat.com> References: <20140401164104.GH16484@spoyarek.pnq.redhat.com> <20140401182616.1F17C7449A@topped-with-meat.com> <20140402045355.GA23931@spoyarek.pnq.redhat.com> <24966439.irburZmzZi@vapier> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <24966439.irburZmzZi@vapier> User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) X-DH-Original-To: glibc@patchwork.siddhesh.in On Wed, Apr 02, 2014 at 05:33:44AM -0400, Mike Frysinger wrote: > On Wed 02 Apr 2014 10:23:55 Siddhesh Poyarekar wrote: > > On Tue, Apr 01, 2014 at 11:26:16AM -0700, Roland McGrath wrote: > > > If you bzero before explicitly filling fields, does the compiler optimize > > > to only zeroing the one unused field? If so, that seems more futureproof. > > > > It doesn't quite, but (now that I checked) it really only results in a > > couple of additional instructions (as opposed to a function call that > > I had implicitly assumed), so I'll add it anyway if you think it is > > OK. This obviously also needs the previous patch that consolidates > > the head initialization code. > > as a general thing, can we not use bzero ? like ever ? memset should be > exactly the same. Yeah, sorry. Here: diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h index c069bf6..954fe99 100644 --- a/nscd/nscd-client.h +++ b/nscd/nscd-client.h @@ -240,6 +240,10 @@ static inline time_t datahead_init_common (struct datahead *head, nscd_ssize_t allocsize, nscd_ssize_t recsize, uint32_t ttl) { + /* Initialize so that we don't write out junk in uninitialized data to the + cache. */ + memset (head, 0, sizeof (*head)); + head->allocsize = allocsize; head->recsize = recsize; head->usable = true; @@ -253,18 +257,21 @@ static inline time_t datahead_init_pos (struct datahead *head, nscd_ssize_t allocsize, nscd_ssize_t recsize, uint8_t nreloads, uint32_t ttl) { + time_t ret = datahead_init_common (head, allocsize, recsize, ttl); head->notfound = false; head->nreloads = nreloads; - return datahead_init_common (head, allocsize, recsize, ttl); + return ret; } static inline time_t datahead_init_neg (struct datahead *head, nscd_ssize_t allocsize, nscd_ssize_t recsize, uint32_t ttl) { + time_t ret = datahead_init_common (head, allocsize, recsize, ttl); + /* We don't need to touch nreloads here since it is set to our desired value + (0) when we bzero the structure. */ head->notfound = true; - head->nreloads = 0; - return datahead_init_common (head, allocsize, recsize, ttl); + return ret; } /* Structure for one hash table entry. */