From patchwork Wed Oct 4 17:31:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 729325 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a4e:0:b0:31d:da82:a3b4 with SMTP id v14csp481962wrs; Wed, 4 Oct 2023 10:43:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSSvoFzbCbEFgfwMy5cZ4oq9/iFCvxHMrGQ6g0g6N+TRYkmnimXanzmmUxzi/nDf5m/WXP X-Received: by 2002:a05:620a:2890:b0:775:aaf7:903f with SMTP id j16-20020a05620a289000b00775aaf7903fmr3110520qkp.67.1696441395954; Wed, 04 Oct 2023 10:43:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696441395; cv=none; d=google.com; s=arc-20160816; b=YgL8wqlRRa76LgoyFMPsMRhb0uGXsXIetDi2lxONmY5Ks/naBB3HMLXhh792nnohCO +HJhQDs61VPTJLPGuXMXmCACXCTG6eXWhx8h0ht51r+o2OqU9TBoEDmnwiPGTr1Kvl+E Yx+QyxamT8ARXni78eOAE4RlvA2nUaExoQ+yjGYpPxGtyzq0FOiD4eUfCSLnw9g66zL3 p29SXvRbZ7txcmFMfGtL0xTSz6SIl/1H9O5ulxWC2aQUQ/wm3BVM3mslleRe5xc6RfQG 5cwX340gTD+7EqMiRdAhS/7nwdruVOGsQcmYTTrZCSKTqYHDVjvZ1NQ581uOIeUcVnGt MTlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+PTJ/05sHPgcAUDGq2+BZ4afKq7cNyAKTrzR+aRyMME=; fh=HDVP4gLBJFPrlJPLcYFMfWtVNMZlEWZ6fKpeuNItzQI=; b=DRmN6HQoGZagEfINSAMj7uQ0khjjrLs2XUHDvUi8aMaJGquICms6aYnudy6zq7JBni MMs6nAvvqT7sUn6ei1HiY0nEQ9lmLjLmjvnuYCnsMEZtpGvORTMxL4JplJXZsD+K2Ufz G/oCc2oRcON3JsMnP1SdCBWiOk/B+BZU9ETdZJvcG5aEyiLoTjFxdINnbjr7U5Yni/dB Paeq4jGLBU8GiDcnAbzZiP1UNFQGFggC2itUsd/qz3TrFXUQV53euRYLSR29Al4pV7lw mvoVkCEBHDMDjSMF9yhUWKk0P1GAjWEgl5cFfEENnyM+sA0p/FSg2z+VtJWAOkVhiIm9 aOHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mvWjUJzc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q9-20020a05620a0d8900b00773a83f4976si1605234qkl.712.2023.10.04.10.43.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Oct 2023 10:43:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mvWjUJzc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo5kr-0004ho-Qm; Wed, 04 Oct 2023 13:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qo5kV-0004Gb-Ag for qemu-devel@nongnu.org; Wed, 04 Oct 2023 13:33:28 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qo5kO-0001AA-1b for qemu-devel@nongnu.org; Wed, 04 Oct 2023 13:33:26 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so369075e9.2 for ; Wed, 04 Oct 2023 10:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696440798; x=1697045598; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+PTJ/05sHPgcAUDGq2+BZ4afKq7cNyAKTrzR+aRyMME=; b=mvWjUJzcNPREtn226QaWJvZXizjmZYwgSqQ/TNs0fK6w8ixutMvMn1cFg3B92cK22K 0iLPYwrlEK5YlmPUcARlYGfGj1aVfOg6rU5TiUYkYMUw9gBb3/ncZzaf1F5QmU0ciZVn G/v9t/FHf14wIHqbvDHYU8VpaSqFEAFt0nKxn/8plgQelJGD2johb7PJJTMavfDM2qR0 PAM+0Vftfjv9KRjSXr4oIRZEnS2Hy4vkiggD2TE/0HRkewUAV6pETKYgY5zCyzTvZCb5 /ZugiuUNkwz1WN+LU23cu9Gc5eSJ0FiN36WHk7Z8/gzoOXEYlpammn4vM1SzXg7n9hhM T38w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696440798; x=1697045598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+PTJ/05sHPgcAUDGq2+BZ4afKq7cNyAKTrzR+aRyMME=; b=F4aJkKKPAiCm1+iDXk4+Om1ykW0GDhl4xKIXDiqZQdg6Fhyj/ws8CNlw/cEfMgTWS7 jbevPFiSejB8YQw9fPy+woao1yBzU34OzINNjOv18nSnQHaMSBOxUifoMgkexw6gbw4a LBHRCnmMahth+J0V1sio26RpE0yC+y/y5F/SE2rawRJGgalFHxPvPaqdGg6tR2NHqg/b /cyet61jNLzBKOlbmv/bipowxFhIc+hdKKATeTe9YPX/AG8dtxhEUpBTt+WTeRgFHxbT pzlem801yZS6Hrnt1a8e5hvaIrFZBVR2G9qgnFoXkJCFpXzHq631PyXic5xbiBbmNz4q dR4g== X-Gm-Message-State: AOJu0YzzOc2aY71FusOgKI7eFh/5h7zPMl4YE+e1gIA05bQ210E/go/k yG4MWHktpsQyBur2wBNw38m9CbmO6giO8v4TNJQ= X-Received: by 2002:a1c:6a0d:0:b0:3fc:1a6:7764 with SMTP id f13-20020a1c6a0d000000b003fc01a67764mr2834064wmc.16.1696440798375; Wed, 04 Oct 2023 10:33:18 -0700 (PDT) Received: from m1x-phil.lan (5ep85-h01-176-173-163-52.dslam.bbox.fr. [176.173.163.52]) by smtp.gmail.com with ESMTPSA id f20-20020a1c6a14000000b00405959bbf4fsm2000368wmc.19.2023.10.04.10.33.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 04 Oct 2023 10:33:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Markus Armbruster Cc: qemu-block@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Michael Roth Subject: [PATCH 11/21] qapi: Inline QERR_INVALID_PARAMETER_VALUE definition (constant param) Date: Wed, 4 Oct 2023 19:31:46 +0200 Message-ID: <20231004173158.42591-12-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231004173158.42591-1-philmd@linaro.org> References: <20231004173158.42591-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Address the comment added in commit 4629ed1e98 ("qerror: Finally unused, clean up"), from 2015: /* * These macros will go away, please don't use * in new code, and do not add new ones! */ Mechanical transformation using the following coccinelle semantic patch: @match@ identifier errp; expression param; // not constant constant value; @@ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, param, value); @script:python strformat depends on match@ param << match.param; value << match.value; fixedfmt; // new var @@ fixedfmt = f"\"Parameter '%s' expects {value[1:-1]}\"" coccinelle.fixedfmt = cocci.make_ident(fixedfmt) @replace@ identifier match.errp; expression match.param; constant match.value; identifier strformat.fixedfmt; @@ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, param, value); + error_setg(errp, fixedfmt, param); Signed-off-by: Philippe Mathieu-Daudé --- hw/core/qdev-properties-system.c | 5 +++-- qapi/opts-visitor.c | 3 +-- qapi/qapi-util.c | 3 +-- qapi/qobject-input-visitor.c | 18 ++++++++---------- qapi/string-input-visitor.c | 18 ++++++++++-------- util/qemu-option.c | 7 ++++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 688340610e..7752c5fda5 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -769,8 +769,9 @@ static void set_pci_devfn(Object *obj, Visitor *v, const char *name, return; } if (value < -1 || value > 255) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "a value between -1 and 255"); + error_setg(errp, + "Parameter '%s' expects a value between -1 and 255", + name ? name : "null"); return; } *ptr = value; diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 3d1a28b419..0393704a73 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -515,8 +515,7 @@ opts_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp) err = qemu_strtosz(opt->str ? opt->str : "", NULL, obj); if (err < 0) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, opt->name, - "a size value"); + error_setg(errp, "Parameter '%s' expects a size value", opt->name); return false; } diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c index 63596e11c5..82c3425566 100644 --- a/qapi/qapi-util.c +++ b/qapi/qapi-util.c @@ -101,8 +101,7 @@ bool qapi_bool_parse(const char *name, const char *value, bool *obj, Error **err return true; } - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, - "'on' or 'off'"); + error_setg(errp, "Parameter '%s' expects 'on' or 'off'", name); return false; } diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index f110a804b2..f5fa6c1878 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -424,8 +424,8 @@ static bool qobject_input_type_int64_keyval(Visitor *v, const char *name, if (qemu_strtoi64(str, NULL, 0, obj) < 0) { /* TODO report -ERANGE more nicely */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - full_name(qiv, name), "integer"); + error_setg(errp, "Parameter '%s' expects integer", + full_name(qiv, name)); return false; } return true; @@ -458,8 +458,7 @@ static bool qobject_input_type_uint64(Visitor *v, const char *name, } err: - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - full_name(qiv, name), "uint64"); + error_setg(errp, "Parameter '%s' expects uint64", full_name(qiv, name)); return false; } @@ -475,8 +474,8 @@ static bool qobject_input_type_uint64_keyval(Visitor *v, const char *name, if (qemu_strtou64(str, NULL, 0, obj) < 0) { /* TODO report -ERANGE more nicely */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - full_name(qiv, name), "integer"); + error_setg(errp, "Parameter '%s' expects integer", + full_name(qiv, name)); return false; } return true; @@ -514,8 +513,8 @@ static bool qobject_input_type_bool_keyval(Visitor *v, const char *name, } if (!qapi_bool_parse(name, str, obj, NULL)) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - full_name(qiv, name), "'on' or 'off'"); + error_setg(errp, "Parameter '%s' expects 'on' or 'off'", + full_name(qiv, name)); return false; } return true; @@ -643,8 +642,7 @@ static bool qobject_input_type_size_keyval(Visitor *v, const char *name, if (qemu_strtosz(str, NULL, obj) < 0) { /* TODO report -ERANGE more nicely */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - full_name(qiv, name), "size"); + error_setg(errp, "Parameter '%s' expects size", full_name(qiv, name)); return false; } return true; diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 3f1b9e9b41..6ea6a0c676 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -189,16 +189,17 @@ static bool parse_type_int64(Visitor *v, const char *name, int64_t *obj, case LM_NONE: /* just parse a simple int64, bail out if not completely consumed */ if (qemu_strtoi64(siv->string, NULL, 0, &val)) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "int64"); + error_setg(errp, "Parameter '%s' expects int64", + name ? name : "null"); return false; } *obj = val; return true; case LM_UNPARSED: if (try_parse_int64_list_entry(siv, obj)) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "list of int64 values or ranges"); + error_setg(errp, + "Parameter '%s' expects list of int64 values or ranges", + name ? name : "null"); return false; } assert(siv->lm == LM_INT64_RANGE); @@ -279,16 +280,17 @@ static bool parse_type_uint64(Visitor *v, const char *name, uint64_t *obj, case LM_NONE: /* just parse a simple uint64, bail out if not completely consumed */ if (qemu_strtou64(siv->string, NULL, 0, &val)) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "uint64"); + error_setg(errp, "Parameter '%s' expects uint64", + name ? name : "null"); return false; } *obj = val; return true; case LM_UNPARSED: if (try_parse_uint64_list_entry(siv, obj)) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", - "list of uint64 values or ranges"); + error_setg(errp, + "Parameter '%s' expects list of uint64 values or ranges", + name ? name : "null"); return false; } assert(siv->lm == LM_UINT64_RANGE); diff --git a/util/qemu-option.c b/util/qemu-option.c index 62dd80a5ae..9440224e5b 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -101,7 +101,7 @@ static bool parse_option_number(const char *name, const char *value, return false; } if (err) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number"); + error_setg(errp, "Parameter '%s' expects a number", name); return false; } *ret = number; @@ -142,8 +142,9 @@ bool parse_option_size(const char *name, const char *value, return false; } if (err) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, - "a non-negative number below 2^64"); + error_setg(errp, + "Parameter '%s' expects a non-negative number below 2^64", + name); error_append_hint(errp, "Optional suffix k, M, G, T, P or E means" " kilo-, mega-, giga-, tera-, peta-\n" "and exabytes, respectively.\n");