From: Tim Deegan Subject: Re: [PATCH] xen/xenoprof: avoid division by 0 Date: Thu, 14 Feb 2013 16:50:03 +0000 Message-ID: <20130214165003.GR83752@ocelot.phlegethon.org> References: <68308aac7872c07631cb.1360858593@whitby.uk.xensource.com> <511D202E02000078000BE68A@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <511D202E02000078000BE68A@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org At 16:34 +0000 on 14 Feb (1360859678), Jan Beulich wrote: > >>> On 14.02.13 at 17:16, Tim Deegan wrote: > > --- a/xen/common/xenoprof.c Thu Feb 14 15:46:56 2013 +0000 > > +++ b/xen/common/xenoprof.c Thu Feb 14 16:16:17 2013 +0000 > > @@ -225,7 +225,7 @@ static int alloc_xenoprof_struct( > > #endif > > > > /* reduce max_samples if necessary to limit pages allocated */ > > - max_bufsize = (MAX_OPROF_SHARED_PAGES * PAGE_SIZE) / nvcpu; > > + max_bufsize = (MAX_OPROF_SHARED_PAGES * PAGE_SIZE) / (nvcpu ?: 1); > > max_max_samples = ( (max_bufsize - bufsize) / i ) + 1; > > if ( (unsigned)max_samples > max_max_samples ) > > max_samples = max_max_samples; > > I think the function would better return an error in that case. After > all there's little point in setting up anything when we for sure don't > know how many vCPU-s a domain is going to have. Grand so: # HG changeset patch # Parent 5a84cc531072378e6e5ff89b4c0e9a35000dc56f xen/xenoprof: avoid division by 0. Signed-off-by: Tim Deegan diff -r 5a84cc531072 xen/common/xenoprof.c --- a/xen/common/xenoprof.c Thu Feb 14 15:46:56 2013 +0000 +++ b/xen/common/xenoprof.c Thu Feb 14 16:48:49 2013 +0000 @@ -213,6 +213,9 @@ static int alloc_xenoprof_struct( for_each_vcpu ( d, v ) nvcpu++; + if ( !nvcpu ) + return -EINVAL; + bufsize = sizeof(struct xenoprof_buf); i = sizeof(struct event_log); #ifdef CONFIG_COMPAT