From owner-svn-src-head@freebsd.org Tue Mar 15 00:21:50 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 01A63AD16A2; Tue, 15 Mar 2016 00:21:50 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (glebi.us [96.95.210.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id E03F51D51; Tue, 15 Mar 2016 00:21:49 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.15.2/8.15.2) with ESMTPS id u2F0LmXD063273 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 14 Mar 2016 17:21:49 -0700 (PDT) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebi.us (8.15.2/8.15.2/Submit) id u2F0Lmwa063272; Mon, 14 Mar 2016 17:21:48 -0700 (PDT) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@FreeBSD.org using -f Date: Mon, 14 Mar 2016 17:21:48 -0700 From: Gleb Smirnoff To: Mateusz Guzik Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r296880 - in head: share/man/man9 sys/kern sys/sys Message-ID: <20160315002148.GP1328@FreeBSD.org> References: <201603150005.u2F050ps086390@repo.freebsd.org> <20160315001638.GA29505@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160315001638.GA29505@dft-labs.eu> User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Mar 2016 00:21:50 -0000 On Tue, Mar 15, 2016 at 01:16:38AM +0100, Mateusz Guzik wrote: M> On Tue, Mar 15, 2016 at 12:05:00AM +0000, Gleb Smirnoff wrote: M> > +int M> > +sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS) M> > +{ M> > + uint64_t *out; M> > + int error; M> > + M> > + out = malloc(arg2 * sizeof(uint64_t), M_TEMP, M_WAITOK); M> > + for (int i = 0; i < arg2; i++) M> > + out[i] = counter_u64_fetch(((counter_u64_t *)arg1)[i]); M> > + M> > + error = SYSCTL_OUT(req, out, arg2 * sizeof(uint64_t)); M> > + M> > + if (error || !req->newptr) M> > + return (error); M> > + M> > + /* M> > + * Any write attempt to a counter zeroes it. M> > + */ M> > + for (int i = 0; i < arg2; i++) M> > + counter_u64_zero(((counter_u64_t *)arg1)[i]); M> > + M> > + return (0); M> > +} M> > M> M> This never frees tha allocated buffer. M> M> It would be better to just put stuff to userspace in a loop and avoid M> allocations entirely. but does not look like there are no friendly M> macros for that. Thanks, Mateusz! Pointy hat is mine. -- Totus tuus, Glebius.