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: 1843542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=mvWjUJzc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S12776FZHz1yqD for ; Thu, 5 Oct 2023 04:41:39 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo5kj-0004Rd-KI; Wed, 04 Oct 2023 13:33:43 -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 1qo5kU-0004Bk-6J for qemu-ppc@nongnu.org; Wed, 04 Oct 2023 13:33:26 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qo5kN-0001A4-QQ for qemu-ppc@nongnu.org; Wed, 04 Oct 2023 13:33:25 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-405361bb9f7so369025e9.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=GrxOiW4sJGeK2lwqUpaoRoPWbSo5ualBjntczhA4723YbbQ+3VIRJuYrYwMCAssrXR oHrUSOZbatPzRfaUQK23em+8gBze1Hvm4/kbY8xS3XIj5y/MHqU9Dhtu9w2AJ64fF+bx xS+KP3uCqI9QPvIuQQaqFQLQt9R9AY7QABpsSI/xdJbCEOxzP0qE550FQTi5AQgt0Dxo jsGx4/jKfYhzFdC/jpH/nlzQG6eECdUGIJKLMoStNVPpGQcUazo4j/Q0rF7lFL14/6cB i5g9hhy3D0jdsjHPHH/Bswi2QMOBpVFx5JNih0IJshuBZVxzKmrPdHykcF6kY2CzwBl6 ZouQ== X-Gm-Message-State: AOJu0Yz6eGRRH3Xnzimf4LfoyT4XYU13V3zJPCx69TrI/myac5NxKrAT 4xt8WnOQOuAwT6WniPWDyhTh/g== X-Google-Smtp-Source: AGHT+IE/j2If/Gbt/uu6G49MkbYtXRXJLnIk2q+N2YvjSnfYB1EQJdeMTX3lxGs4d/rNGGoaqB6pVQ== 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::336; envelope-from=philmd@linaro.org; helo=mail-wm1-x336.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-ppc@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-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-ppc-bounces+incoming=patchwork.ozlabs.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");