From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:57609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW2iD-0006jI-90 for qemu-devel@nongnu.org; Thu, 01 Dec 2011 04:13:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RW2iB-0008LE-V8 for qemu-devel@nongnu.org; Thu, 01 Dec 2011 04:13:48 -0500 Received: from mail-ey0-f173.google.com ([209.85.215.173]:53852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RW2iB-0008JU-NU for qemu-devel@nongnu.org; Thu, 01 Dec 2011 04:13:47 -0500 Received: by mail-ey0-f173.google.com with SMTP id i10so2138247eaa.4 for ; Thu, 01 Dec 2011 01:13:47 -0800 (PST) Date: Thu, 1 Dec 2011 08:33:16 +0000 From: Stefan Hajnoczi Message-ID: <20111201083316.GD29861@stefanha-thinkpad.localdomain> References: <1322687028-29714-1-git-send-email-aliguori@us.ibm.com> <1322687028-29714-3-git-send-email-aliguori@us.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1322687028-29714-3-git-send-email-aliguori@us.ibm.com> Subject: Re: [Qemu-devel] [PATCH 02/18] qom: register legacy properties as new style properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Jan Kiszka , qemu-devel@nongnu.org, Markus Armbruster , Luiz Capitulino On Wed, Nov 30, 2011 at 03:03:32PM -0600, Anthony Liguori wrote: > +static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque, > + const char *name, Error **errp) > +{ > + Property *prop = opaque; > + > + if (dev->state != DEV_STATE_CREATED) { > + error_set(errp, QERR_PERMISSION_DENIED); > + return; > + } > + > + if (prop->info->parse) { > + Error *local_err = NULL; > + char *ptr = NULL; > + > + visit_type_str(v, &ptr, name, &local_err); > + if (!local_err) { > + int ret; > + ret = prop->info->parse(dev, prop, ptr); > + if (ret != 0) { > + error_set(errp, QERR_INVALID_PARAMETER_VALUE, > + name, prop->info->name); > + } > + g_free(ptr); > + } else { > + error_propagate(errp, local_err); > + } I noticed something subtle about Error** here. Your code is correct but I (incorrectly) wanted to eliminate local_err and use errp directly: if (prop->info->parse) { char *ptr = NULL; visit_type_str(v, &ptr, name, errp); if (!error_is_set(errp)) { int ret; ret = prop->info->parse(dev, prop, ptr); if (ret != 0) { error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, prop->info->name); } g_free(ptr); } } else { ... Turns out you cannot do this because error_is_set(errp) will be false if the caller passed in a NULL errp. That means we wouldn't detect the error from visit_type_str()! So it's not okay to depend on the caller's errp. We always need to juggle around a local_err with propagation :(. Just wanted to share.