From: Ian Campbell Subject: Re: [PATCH v3 14/14] libxl: build a device tree for ARM guests Date: Fri, 8 Nov 2013 09:30:20 +0000 Message-ID: <1383903020.3189.38.camel@kazak.uk.xensource.com> References: <1383842678.3189.15.camel@kazak.uk.xensource.com> <1383842696-8598-14-git-send-email-ian.campbell@citrix.com> <21115.52782.630571.603241@mariner.uk.xensource.com> <1383846095.3189.27.camel@kazak.uk.xensource.com> <21115.53794.622439.875372@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21115.53794.622439.875372@mariner.uk.xensource.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: Ian Jackson Cc: stefano.stabellini@eu.citrix.com, tim@xen.org, julien.grall@linaro.org, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Thu, 2013-11-07 at 17:47 +0000, Ian Jackson wrote: > Ian Campbell writes ("Re: [PATCH v3 14/14] libxl: build a device tree for ARM guests"): > > On Thu, 2013-11-07 at 17:30 +0000, Ian Jackson wrote: > > > > + if (fdt_size) { > > > > + fdt_size <<= 1; > > > > + LOG(DEBUG, "Increasing FDT size to %zd and retrying", fdt_size); > > > > + } else { > > > > + fdt_size = 4096; > > > > + } > > > > > > Can we rule out this loop getting out of control ? > > > > The FDT macro has a check and error if it gets too big. I'll see about > > moving the <<= into the macro, which I suspect will seem more natural > > with a loop called "retry". > > Oh, please don't do that. I much prefer to keep anything out of a > macro that doesn't have to be there. OK. > The fdt_size increase is part of the loop control. Now you can't put > it inside the for(;;) brackets but putting it at the top of the loop > will make it nice and obvious. > > Personally I normally do something like this > fdt_size += 4096; > fdt_size <<= 2; > which avoids the if (fdt_size). The only downside is that the > answers aren't uniformly powers of 2. TBH I could just go with += and avoid the <<=, I don't actually expect an FDT to be so large that exponentially increasing size is that important. How would for(fdt_size = 4096; fdt_size < FDT_SIZE_MAX; fdt_size <<= 2) and use continue on error in the macro, with a break at the bottom of the loop (success) sit with you? Ian.