Date: Mon, 14 Mar 2016 17:21:48 -0700 From: Gleb Smirnoff <glebius@FreeBSD.org> To: Mateusz Guzik <mjguzik@gmail.com> 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> In-Reply-To: <20160315001638.GA29505@dft-labs.eu> References: <201603150005.u2F050ps086390@repo.freebsd.org> <20160315001638.GA29505@dft-labs.eu>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160315002148.GP1328>
