Re: [PATCH 03/41] cpu: Detect arch when parsing CPU data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 08, 2016 at 14:36:30 +0200, Peter Krempa wrote:
> On Wed, Jun 08, 2016 at 10:22:17 +0200, Jiri Denemark wrote:
> > A CPU data XML file already contains the architecture, let the parser
> > use it to detect which CPU driver should be used to parse the rest of
> > the file.
> > 
> > Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
> > ---
> >  src/cpu/cpu.c     | 54 ++++++++++++++++++++++++++++++++++++++++++++----------
> >  src/cpu/cpu.h     |  7 +++----
> >  src/cpu/cpu_x86.c | 15 ++-------------
> >  3 files changed, 49 insertions(+), 27 deletions(-)
> > 
> > diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
> > index dbd0987..8c3d39d 100644
> > --- a/src/cpu/cpu.c
> > +++ b/src/cpu/cpu.c
> 
> [...]
> 
> > @@ -675,24 +689,44 @@ cpuDataFormat(const virCPUData *data)
> >   * Returns internal CPU data structure parsed from the XML or NULL on error.
> >   */
> >  virCPUDataPtr
> > -cpuDataParse(virArch arch,
> > -             const char *xmlStr)
> > +cpuDataParse(const char *xmlStr)
> >  {
> >      struct cpuArchDriver *driver;
> > +    xmlDocPtr xml = NULL;
> > +    xmlXPathContextPtr ctxt = NULL;
> > +    virCPUDataPtr data = NULL;
> > +    char *arch;
> 
> 'arch' can be freed uninitialized.
> 
> >  
> > -    VIR_DEBUG("arch=%s, xmlStr=%s", virArchToString(arch), xmlStr);
> > +    VIR_DEBUG("xmlStr=%s", xmlStr);
> >  
> > -    if (!(driver = cpuGetSubDriver(arch)))
> > -        return NULL;
> > +    if (!(xml = virXMLParseStringCtxt(xmlStr, _("CPU data"), &ctxt))) {
> > +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> > +                       _("cannot parse CPU data"));
> > +        goto cleanup;
> > +    }
> > +
> > +    if (!(arch = virXPathString("string(/cpudata/@arch)", ctxt))) {
> > +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> > +                       _("missing CPU data architecture"));
> > +        goto cleanup;
> > +    }
> > +
> > +    if (!(driver = cpuGetSubDriverByName(arch)))
> > +        goto cleanup;
> 
> This doesn't report errors.

Oops, cpuGetSubDriverByName in this patch cannot even return NULL since
it wrongly fallbacks to a default driver. I removed the fallback and let
cpuGetSubDriverByName report a proper error.

Jirka

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]