On Fri, Oct 10, 2025 at 10:31:41AM +0100, Daniel P. Berrangé wrote:
> On Fri, Oct 10, 2025 at 11:27:36AM +0200, Gerd Hoffmann wrote:
> > > > +static void handle_ovmf_log_range(GString *out,
> > > > +                                  dma_addr_t start,
> > > > +                                  dma_addr_t end,
> > > > +                                  Error **errp)
> > > > +{
> > 
> > > How about eliminating the intermediate buffer alloocation / printf by
> > > reading straight into the GString buf ? Something like
> > > 
> > >    size_t len = end - start;
> > >    g_string_set_size(out, out->len + len);
> > >    if (dma_memory_read(&address_space_memory, start,
> > >                        out->str + (out->len - len),
> > >                  len, MEMTXATTRS_UNSPECIFIED)) {
> > >        ...
> > >    }
> > 
> > There are two ranges in the wrap-around case, and I don't think I can
> > put multiple chunks into a single gstring.
> 
> I'm not sure I understand ?  The code I've suggest here satisfies the
> existing API contract you've got for handle_ovmf_log_range, so should
> be happy with being called multiple times.

I've missed the detail that the g_string_set_size() call actually
/expands/ the string.  Tried, works fine.

take care,
  Gerd


Reply via email to