qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: xieyongji@bytedance.com, kwolf@redhat.com, hreitz@redhat.com,
	Coiby.Xu@gmail.com, pbonzini@redhat.com, berrange@redhat.com,
	eduardo@habkost.net, mark.cave-ayland@ilande.co.uk,
	michael.roth@amd.com, kkostiuk@redhat.com, qemu-block@nongnu.org
Subject: [PATCH 5/7] target/i386/cpu: Improve errors for out of bounds property values
Date: Thu, 10 Oct 2024 16:56:28 +0200	[thread overview]
Message-ID: <20241010145630.985335-6-armbru@redhat.com> (raw)
In-Reply-To: <20241010145630.985335-1-armbru@redhat.com>

The error message for a "stepping" value that is out of bounds is a
bit odd:

    $ qemu-system-x86_64 -cpu qemu64,stepping=16
    qemu-system-x86_64: can't apply global qemu64-x86_64-cpu.stepping=16: Property .stepping doesn't take value 16 (minimum: 0, maximum: 15)

The "can't apply global" part is an unfortunate artifact of -cpu's
implementation.  Left for another day.

The remainder feels overly verbose.  Change it to

    qemu64-x86_64-cpu: can't apply global qemu64-x86_64-cpu.stepping=16: parameter 'stepping' can be at most 15

Likewise for "family", "model", and "tsc-frequency".

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 target/i386/cpu.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 4f8fa60432..de2c7041c5 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -31,7 +31,6 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qapi/qapi-visit-machine.h"
-#include "qapi/qmp/qerror.h"
 #include "standard-headers/asm-x86/kvm_para.h"
 #include "hw/qdev-properties.h"
 #include "hw/i386/topology.h"
@@ -5455,8 +5454,8 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v,
         return;
     }
     if (value > max) {
-        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                   name ? name : "null", value, (int64_t)0, (int64_t)max);
+        error_setg(errp, "parameter '%s' can be at most %" PRIu64,
+                   name ? name : "null", max);
         return;
     }
 
@@ -5494,8 +5493,8 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v,
         return;
     }
     if (value > max) {
-        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                   name ? name : "null", value, (int64_t)0, (int64_t)max);
+        error_setg(errp, "parameter '%s' can be at most %" PRIu64,
+                   name ? name : "null", max);
         return;
     }
 
@@ -5528,8 +5527,8 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v,
         return;
     }
     if (value > max) {
-        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                   name ? name : "null", value, (int64_t)0, (int64_t)max);
+        error_setg(errp, "parameter '%s' can be at most %" PRIu64,
+                   name ? name : "null", max);
         return;
     }
 
@@ -5623,16 +5622,15 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
     X86CPU *cpu = X86_CPU(obj);
-    const int64_t min = 0;
     const int64_t max = INT64_MAX;
     int64_t value;
 
     if (!visit_type_int(v, name, &value, errp)) {
         return;
     }
-    if (value < min || value > max) {
-        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, "",
-                   name ? name : "null", value, min, max);
+    if (value < 0 || value > max) {
+        error_setg(errp, "parameter '%s' can be at most %" PRId64,
+                   name ? name : "null", max);
         return;
     }
 
-- 
2.46.0



  parent reply	other threads:[~2024-10-10 14:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 14:56 [PATCH 0/7] error: Eliminate QERR_PROPERTY_VALUE_OUT_OF_RANGE Markus Armbruster
2024-10-10 14:56 ` [PATCH 1/7] error: Drop superfluous #include "qapi/qmp/qerror.h" Markus Armbruster
2024-10-10 15:01   ` Daniel P. Berrangé
2024-10-10 14:56 ` [PATCH 2/7] block: Improve errors about block sizes Markus Armbruster
2024-10-10 15:05   ` Daniel P. Berrangé
2024-10-10 14:56 ` [PATCH 3/7] block: Adjust check_block_size() signature Markus Armbruster
2024-10-10 15:06   ` Daniel P. Berrangé
2024-10-10 14:56 ` [PATCH 4/7] target/i386/cpu: Avoid mixing signed and unsigned in property setters Markus Armbruster
2024-10-10 15:52   ` Daniel P. Berrangé
2024-10-10 14:56 ` Markus Armbruster [this message]
2024-10-10 15:56   ` [PATCH 5/7] target/i386/cpu: Improve errors for out of bounds property values Daniel P. Berrangé
2024-10-10 14:56 ` [PATCH 6/7] hw/intc/openpic: " Markus Armbruster
2024-10-10 15:56   ` Daniel P. Berrangé
2024-10-10 14:56 ` [PATCH 7/7] qerror: QERR_PROPERTY_VALUE_OUT_OF_RANGE is no longer used, drop Markus Armbruster
2024-10-10 15:57   ` Daniel P. Berrangé
2024-10-10 14:59 ` [PATCH 0/7] error: Eliminate QERR_PROPERTY_VALUE_OUT_OF_RANGE Markus Armbruster
2024-10-10 16:07   ` Daniel P. Berrangé
2024-10-10 17:03     ` Markus Armbruster

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=20241010145630.985335-6-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=berrange@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=hreitz@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=xieyongji@bytedance.com \
    /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).