From patchwork Tue Jun 23 14:01:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 50226 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 022B521575 for ; Tue, 23 Jun 2015 14:02:01 +0000 (UTC) Received: by laar3 with SMTP id r3sf3208428laa.1 for ; Tue, 23 Jun 2015 07:02:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=/kOqKUUiUN2uhhnTRfvyVV2nysjX9oTxkcQqnCxp+aY=; b=BqAdoywLVVooLchUxxMRhNGqONDq8Gmu6n1BJlD62kNFuAT/a/6MTdtOiQhc+QjqzI iGb9+l42+hcwma5VfS9zwcq+d153Aik+/LCAiv+1vlr/BgfE/UIUiVgX0mVB+1fAJ3Jb GPmLMKfREONV96r9Y2ZmqUJTJJSsGq2Rs2hMbTIU/yCOr7R5VoGKNQwuWjabBInoYNar g+Luc+tKXLaq589AvmUXdf+W+3wYdQCA7wSkUGKSasAdzn+YFQkkMUSWUVd0HQK/zGfD cqOLKPCoerrVJtISvkLDgh89Y6n+X6G5L6r2KJOOAnOi91nKDIRnro+qA21/xoINJaW3 +bqA== X-Gm-Message-State: ALoCoQlB9vY6iE4R7ZmyEZJ0xW5yRpDwI//2sr82iuEW7LVAv3diknmFP8Ycn99q50mTzCmIVVwI X-Received: by 10.152.87.146 with SMTP id ay18mr9773001lab.6.1435068119945; Tue, 23 Jun 2015 07:01:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.40 with SMTP id kv8ls49315lac.94.gmail; Tue, 23 Jun 2015 07:01:59 -0700 (PDT) X-Received: by 10.152.3.33 with SMTP id 1mr35292964laz.109.1435068119803; Tue, 23 Jun 2015 07:01:59 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id g1si19403608lbs.32.2015.06.23.07.01.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 07:01:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbnk3 with SMTP id k3so7341876lbn.1 for ; Tue, 23 Jun 2015 07:01:59 -0700 (PDT) X-Received: by 10.152.206.75 with SMTP id lm11mr34509647lac.41.1435068119542; Tue, 23 Jun 2015 07:01:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3096912lbb; Tue, 23 Jun 2015 07:01:57 -0700 (PDT) X-Received: by 10.66.136.39 with SMTP id px7mr54838134pab.130.1435068115039; Tue, 23 Jun 2015 07:01:55 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id lv5si34839891pab.102.2015.06.23.07.01.52 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 23 Jun 2015 07:01:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Z7Oln-0003Hf-EI; Tue, 23 Jun 2015 15:01:47 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Markus Armbruster , Kevin Wolf , qemu-block@nongnu.org Subject: [PATCH v2 for-2.4 1/3] qdev-properties-system: Change set_pointer's parse callback to use Error Date: Tue, 23 Jun 2015 15:01:45 +0100 Message-Id: <1435068107-12594-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1435068107-12594-1-git-send-email-peter.maydell@linaro.org> References: <1435068107-12594-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Instead of having set_pointer() call a parse callback which returns an error number that we then convert to an Error string with error_set_from_qdev_prop_error(), make the parse callback take an Error** and set the error itself. This will allow parse routines to provide more helpful error messages than the generic ones. Signed-off-by: Peter Maydell --- hw/core/qdev-properties-system.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 0309fe5..56954b4 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -35,15 +35,15 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, } static void set_pointer(Object *obj, Visitor *v, Property *prop, - int (*parse)(DeviceState *dev, const char *str, - void **ptr), + void (*parse)(DeviceState *dev, const char *str, + void **ptr, const char *propname, + Error **errp), const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Error *local_err = NULL; void **ptr = qdev_get_prop_ptr(dev, prop); char *str; - int ret; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); @@ -60,26 +60,29 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, *ptr = NULL; return; } - ret = parse(dev, str, ptr); - error_set_from_qdev_prop_error(errp, ret, dev, prop, str); + parse(dev, str, ptr, prop->name, errp); g_free(str); } /* --- drive --- */ -static int parse_drive(DeviceState *dev, const char *str, void **ptr) +static void parse_drive(DeviceState *dev, const char *str, void **ptr, + const char *propname, Error **errp) { BlockBackend *blk; blk = blk_by_name(str); if (!blk) { - return -ENOENT; + error_setg(errp, "Property '%s.%s' can't find value '%s'", + object_get_typename(OBJECT(dev)), propname, str); + return; } if (blk_attach_dev(blk, dev) < 0) { - return -EEXIST; + error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use", + object_get_typename(OBJECT(dev)), propname, str); + return; } *ptr = blk; - return 0; } static void release_drive(Object *obj, const char *name, void *opaque) @@ -121,17 +124,21 @@ PropertyInfo qdev_prop_drive = { /* --- character device --- */ -static int parse_chr(DeviceState *dev, const char *str, void **ptr) +static void parse_chr(DeviceState *dev, const char *str, void **ptr, + const char *propname, Error **errp) { CharDriverState *chr = qemu_chr_find(str); if (chr == NULL) { - return -ENOENT; + error_setg(errp, "Property '%s.%s' can't find value '%s'", + object_get_typename(OBJECT(dev)), propname, str); + return; } if (qemu_chr_fe_claim(chr) != 0) { - return -EEXIST; + error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use", + object_get_typename(OBJECT(dev)), propname, str); + return; } *ptr = chr; - return 0; } static void release_chr(Object *obj, const char *name, void *opaque)