From owner-svn-src-all@FreeBSD.ORG Tue Sep 10 14:29:52 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DD882118; Tue, 10 Sep 2013 14:29:52 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-oa0-x22b.google.com (mail-oa0-x22b.google.com [IPv6:2607:f8b0:4003:c02::22b]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7F0922EF5; Tue, 10 Sep 2013 14:29:52 +0000 (UTC) Received: by mail-oa0-f43.google.com with SMTP id i10so8050812oag.30 for ; Tue, 10 Sep 2013 07:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=c1owzkcVoCjN6kQy7R5KkCKPXfYI+Y16+w8X1rsOI0o=; b=AlV/dZMk3msDjK56H/j6pz3grqQKEVlayGTSLn7sTxk56JpgOdYtaqJ8s0+jG5Ov29 ZXUBSzlfSh1C8e3EsHLnM4h9UQWokTG8bF7VYplLwGs6DLySdzynbsLU6xSuyR1fOtWN ScBA1kEWU4h/GYN1Te1dOtVnP/neBtcfdCkxwLuYDEAZ1NIzvaVgwl6y8OpioqCwr4Y0 Ryyd1mimkH1J8bfyBW1qrTvwkEuTJB/cX39uR9I3CyguwJS1uT8P6vzohCh8ET81zqDD TymlBZSKKtG+ALtmlcjgSwyBcggIKnqYfNvH3QRGSMR3yl7P6wO4byqZmu1mYeFhBAuG XRkQ== MIME-Version: 1.0 X-Received: by 10.182.230.135 with SMTP id sy7mr15989760obc.24.1378823391731; Tue, 10 Sep 2013 07:29:51 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.182.75.9 with HTTP; Tue, 10 Sep 2013 07:29:51 -0700 (PDT) In-Reply-To: <201309100517.r8A5HrHY020358@svn.freebsd.org> References: <201309100517.r8A5HrHY020358@svn.freebsd.org> Date: Tue, 10 Sep 2013 07:29:51 -0700 X-Google-Sender-Auth: 1og7CEYaWU_-V1tJLGyD4dRaMQ0 Message-ID: Subject: Re: svn commit: r255439 - head/sys/dev/cpuctl From: Matthew Fleming To: Konstantin Belousov Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Sep 2013 14:29:52 -0000 On Mon, Sep 9, 2013 at 10:17 PM, Konstantin Belousov wrote: > Author: kib > Date: Tue Sep 10 05:17:53 2013 > New Revision: 255439 > URL: http://svnweb.freebsd.org/changeset/base/255439 > > Log: > Call free() on the pointer returned from malloc(). > > Reported and tested by: Oliver Pinter > Sponsored by: The FreeBSD Foundation > MFC after: 3 days > Approved by: re (delphij) > > Modified: > head/sys/dev/cpuctl/cpuctl.c > > Modified: head/sys/dev/cpuctl/cpuctl.c > > ============================================================================== > --- head/sys/dev/cpuctl/cpuctl.c Tue Sep 10 03:48:18 2013 > (r255438) > +++ head/sys/dev/cpuctl/cpuctl.c Tue Sep 10 05:17:53 2013 > (r255439) > @@ -295,10 +295,10 @@ cpuctl_do_update(int cpu, cpuctl_update_ > static int > update_intel(int cpu, cpuctl_update_args_t *args, struct thread *td) > { > - void *ptr = NULL; > + void *ptr; > uint64_t rev0, rev1; > uint32_t tmp[4]; > - int is_bound = 0; > + int is_bound; > int oldcpu; > int ret; > > @@ -312,10 +312,11 @@ update_intel(int cpu, cpuctl_update_args > } > > /* > - * 16 byte alignment required. > + * 16 byte alignment required. Rely on the fact that > + * malloc(9) always returns the pointer aligned at least on > + * the size of the allocation. > */ > ptr = malloc(args->size + 16, M_CPUCTL, M_WAITOK); > - ptr = (void *)(16 + ((intptr_t)ptr & ~0xf)); > if (copyin(args->data, ptr, args->size) != 0) { > DPRINTF("[cpuctl,%d]: copyin %p->%p of %zd bytes failed", > __LINE__, args->data, ptr, args->size); > @@ -408,10 +409,10 @@ fail: > static int > update_via(int cpu, cpuctl_update_args_t *args, struct thread *td) > { > - void *ptr = NULL; > + void *ptr; > uint64_t rev0, rev1, res; > uint32_t tmp[4]; > - int is_bound = 0; > + int is_bound; > int oldcpu; > int ret; > > @@ -427,8 +428,7 @@ update_via(int cpu, cpuctl_update_args_t > /* > * 4 byte alignment required. > */ > - ptr = malloc(args->size + 16, M_CPUCTL, M_WAITOK); > - ptr = (void *)(16 + ((intptr_t)ptr & ~0xf)); > + ptr = malloc(args->size, M_CPUCTL, M_WAITOK); > if (copyin(args->data, ptr, args->size) != 0) { > DPRINTF("[cpuctl,%d]: copyin %p->%p of %zd bytes failed", > __LINE__, args->data, ptr, args->size); > I don't know exactly what the stock malloc(9) will return, but memguard(9), under its default mode with vm.memguard.options having MG_GUARD_AROUND set will align the returned pointer to only 16 bytes. When I added that feature I almost made it 8 bytes, but I think I saw that uma(9) had a 16-byte alignment so I preserved that. I.e., this code does still work with malloc(9) and memguard(9). But why does this need 16 byte alignment? Especially when one of the comments says 4-byte alignment? Thanks, matthew