qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH] pc-dimm: fix error handling in pc_dimm_check_memdev_is_busy()
Date: Tue, 1 Mar 2016 10:40:12 +0100	[thread overview]
Message-ID: <20160301104012.5e6973b4@nial.brq.redhat.com> (raw)
In-Reply-To: <87d1rftlhw.fsf@blackfin.pond.sub.org>

On Mon, 29 Feb 2016 19:33:15 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> Igor Mammedov <imammedo@redhat.com> writes:
> 
> > if host_memory_backend_get_memory() were to return error and  
> 
> Start sentences with a capital letter, please.
> 
> > NULL MemoryRegion, pc_dimm_check_memdev_is_busy() would crash
> > dereferrencing null pointer in memory_region_is_mapped()  
> 
> dereferencing
> 
> >
> > Also pc_dimm_check_memdev_is_busy():error_setg() would assert
> > if caller passes NULL errp, but assert shouldn't happen as
> > the check is typically performed during hotplug.  
> 
> Huh?
Yep, this paragraph is wrong, I'll drop it.

> 
> >
> > To avoid above issues use typical error handling pattern
> > for property setters:
> >
> > Error *local_error = NULL;
> > ...
> > error_propagate(errp, local_err);
> >
> > Reported-by: Markus Armbruster <armbru@redhat.com>  
> 
> The latent bug I reported was actually that if
> host_memory_backend_get_memory() sets an error and we then reach
> error_setg(), we fail the "error already set" assertion in error_setv()
> unless errp is null.
> 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  hw/mem/pc-dimm.c | 13 ++++++++++---
> >  1 file changed, 10 insertions(+), 3 deletions(-)
> >
> > diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> > index 650f0f8..973bf20 100644
> > --- a/hw/mem/pc-dimm.c
> > +++ b/hw/mem/pc-dimm.c
> > @@ -364,15 +364,22 @@ static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name,
> >                                        Object *val, Error **errp)
> >  {
> >      MemoryRegion *mr;
> > +    Error *local_err = NULL;
> >  
> > -    mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), errp);
> > +    mr = host_memory_backend_get_memory(MEMORY_BACKEND(val), &local_err);
> > +    if (local_err) {
> > +        goto out;
> > +    }
> >      if (memory_region_is_mapped(mr)) {
> >          char *path = object_get_canonical_path_component(val);
> > -        error_setg(errp, "can't use already busy memdev: %s", path);
> > +        error_setg(&local_err, "can't use already busy memdev: %s", path);
> >          g_free(path);
> >      } else {
> > -        qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
> > +        qdev_prop_allow_set_link_before_realize(obj, name, val, &local_err);
> >      }
> > +
> > +out:
> > +    error_propagate(errp, local_err);
> >  }
> >  
> >  static void pc_dimm_init(Object *obj)  
> 
> I'd error_propagate() + return instead of goto.  But your version isn't
> wrong, so:
> 
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> 
> Preferably with an improved commit message, of course :)
Thanks, I'll respin v2 with fixed commit message.

      reply	other threads:[~2016-03-01  9:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-29 13:01 [Qemu-devel] [PATCH] pc-dimm: fix error handling in pc_dimm_check_memdev_is_busy() Igor Mammedov
2016-02-29 18:33 ` Markus Armbruster
2016-03-01  9:40   ` Igor Mammedov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160301104012.5e6973b4@nial.brq.redhat.com \
    --to=imammedo@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).