All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 19/45] qdev: add unsigned properties
Date: Fri, 02 Jun 2017 15:55:06 +0200	[thread overview]
Message-ID: <87y3tabikl.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20170531135709.345-20-marcandre.lureau@redhat.com> ("Marc-André Lureau"'s message of "Wed, 31 May 2017 17:56:43 +0400")

Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Add and use unsigned type for various properties.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

The commit message is a bit misleading.  We don't "add unsigned
properties", we clean up the property code to avoid type casts between
signed and unsigned.

I'm not sure that's worth the churn by itself.  But perhaps it helps
later in this series.  If yes, can you give me a hint?

> ---
>  include/hw/qdev-core.h       |  1 +
>  include/hw/qdev-properties.h | 51 +++++++++++++++++++++++++++-----------------
>  hw/core/qdev-properties.c    | 23 ++++++++++++--------
>  3 files changed, 46 insertions(+), 29 deletions(-)
>
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 784971b8d8..9d7c1c0e9b 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -228,6 +228,7 @@ struct Property {
>      uint8_t      bitnr;
>      union {
>          int64_t i;
> +        uint64_t u;
>      } defval;
>      int          arrayoffset;
>      PropertyInfo *arrayinfo;
> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
> index 6663a547ea..16d3ada8df 100644
> --- a/include/hw/qdev-properties.h
> +++ b/include/hw/qdev-properties.h
> @@ -37,6 +37,7 @@ extern PropertyInfo qdev_prop_arraylen;
>          .offset    = offsetof(_state, _field)                    \
>              + type_check(_type, typeof_field(_state, _field)),   \
>          }
> +
>  #define DEFINE_PROP_INT(_name, _state, _field, _defval, _prop, _type) { \
>          .name      = (_name),                                           \
>          .info      = &(_prop),                                          \
> @@ -44,29 +45,39 @@ extern PropertyInfo qdev_prop_arraylen;
>              + type_check(_type,typeof_field(_state, _field)),           \
>          .defval.i  = (_type)_defval,                                    \
>          }
> -#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) {  \
> -        .name      = (_name),                                    \
> -        .info      = &(qdev_prop_bit),                           \
> -        .bitnr    = (_bit),                                      \
> -        .offset    = offsetof(_state, _field)                    \
> -            + type_check(uint32_t,typeof_field(_state, _field)), \
> -        .defval.i  = (bool)_defval,                              \
> +
> +#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) {         \
> +        .name      = (_name),                                           \
> +        .info      = &(qdev_prop_bit),                                  \
> +        .bitnr    = (_bit),                                             \
> +        .offset    = offsetof(_state, _field)                           \
> +            + type_check(uint32_t, typeof_field(_state, _field)),        \
> +        .defval.u   = (bool)_defval,                                    \
>          }

Let's keep the backslashes where they are to reduce churn.

> +
> +#define DEFINE_PROP_UINT(_name, _state, _field, _defval, _prop, _type) { \
> +        .name      = (_name),                                           \
> +        .info      = &(_prop),                                          \
> +        .offset    = offsetof(_state, _field)                           \
> +            + type_check(_type, typeof_field(_state, _field)),          \
> +        .defval.u  = (_type)_defval,                                    \
> +        }
> +
>  #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) {       \
>          .name      = (_name),                                           \
>          .info      = &(qdev_prop_bit64),                                \
>          .bitnr    = (_bit),                                             \
>          .offset    = offsetof(_state, _field)                           \
>              + type_check(uint64_t, typeof_field(_state, _field)),       \
> -        .defval.i  = (bool)_defval,                                     \
> +        .defval.u  = (bool)_defval,                                     \
>          }
>  
> -#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {       \
> -        .name      = (_name),                                    \
> -        .info      = &(qdev_prop_bool),                          \
> -        .offset    = offsetof(_state, _field)                    \
> -            + type_check(bool, typeof_field(_state, _field)),    \
> -        .defval.i  = (bool)_defval,                              \
> +#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) {      \
> +        .name      = (_name),                                   \
> +        .info      = &(qdev_prop_bool),                         \
> +        .offset    = offsetof(_state, _field)                   \
> +            + type_check(bool, typeof_field(_state, _field)),   \
> +        .defval.u    = (bool)_defval,                           \
>          }

Likewise.

>  
>  #define PROP_ARRAY_LEN_PREFIX "len-"
> @@ -107,17 +118,17 @@ extern PropertyInfo qdev_prop_arraylen;
>          }
>  
>  #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
> -    DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
> +    DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
>  #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
> -    DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
> +    DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
>  #define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
> -    DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
> +    DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
>  #define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
>      DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
>  #define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
> -    DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
> +    DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
>  #define DEFINE_PROP_SIZE(_n, _s, _f, _d)                       \
> -    DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_size, uint64_t)
> +    DEFINE_PROP_UINT(_n, _s, _f, _d, qdev_prop_size, uint64_t)
>  #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)                   \
>      DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
>  
> @@ -163,7 +174,7 @@ extern PropertyInfo qdev_prop_arraylen;
>  #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
>      DEFINE_PROP_INT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
>  #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
> -    DEFINE_PROP_INT(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
> +    DEFINE_PROP_UINT(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
>  #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
>      DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
>  
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 952cda7758..92fb43cb0d 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -71,7 +71,7 @@ static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque,
>  
>  static void set_default_value_enum(Object *obj, const Property *prop)
>  {
> -    object_property_set_str(obj, prop->info->enum_table[prop->defval.i],
> +    object_property_set_str(obj, prop->info->enum_table[prop->defval.u],
>                              prop->name, &error_abort);
>  }
>  
> @@ -128,7 +128,7 @@ static void prop_set_bit(Object *obj, Visitor *v, const char *name,
>  
>  static void set_default_value_bool(Object *obj, const Property *prop)
>  {
> -    object_property_set_bool(obj, prop->defval.i, prop->name, &error_abort);
> +    object_property_set_bool(obj, prop->defval.u, prop->name, &error_abort);
>  }
>  
>  PropertyInfo qdev_prop_bit = {
> @@ -264,11 +264,16 @@ static void set_default_value_int(Object *obj, const Property *prop)
>      object_property_set_int(obj, prop->defval.i, prop->name, &error_abort);
>  }
>  
> +static void set_default_value_uint(Object *obj, const Property *prop)
> +{
> +    object_property_set_uint(obj, prop->defval.u, prop->name, &error_abort);
> +}
> +
>  PropertyInfo qdev_prop_uint8 = {
>      .name  = "uint8",
>      .get   = get_uint8,
>      .set   = set_uint8,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };
>  
>  /* --- 16bit integer --- */
> @@ -302,7 +307,7 @@ PropertyInfo qdev_prop_uint16 = {
>      .name  = "uint16",
>      .get   = get_uint16,
>      .set   = set_uint16,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };
>  
>  /* --- 32bit integer --- */
> @@ -361,7 +366,7 @@ PropertyInfo qdev_prop_uint32 = {
>      .name  = "uint32",
>      .get   = get_uint32,
>      .set   = set_uint32,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };
>  
>  PropertyInfo qdev_prop_int32 = {
> @@ -402,7 +407,7 @@ PropertyInfo qdev_prop_uint64 = {
>      .name  = "uint64",
>      .get   = get_uint64,
>      .set   = set_uint64,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };
>  
>  /* --- string --- */
> @@ -725,7 +730,7 @@ PropertyInfo qdev_prop_blocksize = {
>      .description = "A power of two between 512 and 32768",
>      .get   = get_uint16,
>      .set   = set_blocksize,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };
>  
>  /* --- pci host address --- */
> @@ -948,7 +953,7 @@ PropertyInfo qdev_prop_arraylen = {
>      .name = "uint32",
>      .get = get_uint32,
>      .set = set_prop_arraylen,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };
>  
>  /* --- public helpers --- */
> @@ -1185,5 +1190,5 @@ PropertyInfo qdev_prop_size = {
>      .name  = "size",
>      .get = get_size,
>      .set = set_size,
> -    .set_default_value = set_default_value_int,
> +    .set_default_value = set_default_value_uint,
>  };

  reply	other threads:[~2017-06-02 13:55 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 13:56 [Qemu-devel] [PATCH v2 00/45] qobject/qapi: add uint type Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 01/45] qobject-input-visitor: Reject non-finite numbers with keyval Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 02/45] qapi: Document visit_type_any() issues with keyval input Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 03/45] tests/qapi-schema: Avoid 'str' in alternate test cases Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 04/45] qapi: Reject alternates that can't work with keyval_parse() Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 05/45] qdev: remove PropertyInfo.qtype field Marc-André Lureau
2017-06-01 11:19   ` Markus Armbruster
2017-06-07 12:31     ` Peter Maydell
2017-06-07 13:09       ` Markus Armbruster
2017-06-07 13:44         ` Peter Maydell
2017-06-07 17:37           ` Markus Armbruster
2017-06-09 14:04             ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 06/45] object: fix potential leak in getters Marc-André Lureau
2017-06-01 11:32   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 07/45] tests: remove alt num-int cases Marc-André Lureau
2017-06-01 11:58   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 08/45] tests: add more int/number ranges checks Marc-André Lureau
2017-06-01 14:09   ` Markus Armbruster
2017-06-06 16:14     ` Marc-André Lureau
2017-06-06 19:08       ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 09/45] qapi: merge QInt and QFloat in QNum Marc-André Lureau
2017-06-02  7:03   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 10/45] qapi: Remove visit_start_alternate() parameter promote_int Marc-André Lureau
2017-06-02  7:57   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 11/45] tests: remove /qnum/destroy test Marc-André Lureau
2017-06-02  8:00   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 12/45] qnum: add uint type Marc-André Lureau
2017-06-02  8:05   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 13/45] json: learn to parse uint64 numbers Marc-André Lureau
2017-06-02  8:24   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 14/45] qapi: update the qobject visitor to use QNUM_U64 Marc-André Lureau
2017-06-02 11:18   ` Markus Armbruster
2017-06-02 11:20   ` Markus Armbruster
2017-06-02 11:34     ` Marc-André Lureau
2017-06-02 12:36       ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 15/45] object: add uint property setter/getter Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 16/45] q35: fix get_mmcfg_size to use uint64 visitor Marc-André Lureau
2017-06-02 11:34   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 17/45] object: use more specific property type names Marc-André Lureau
2017-06-02 13:38   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 18/45] qdev: make default property int Marc-André Lureau
2017-06-02 13:49   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 19/45] qdev: add unsigned properties Marc-André Lureau
2017-06-02 13:55   ` Markus Armbruster [this message]
2017-06-02 14:00     ` Marc-André Lureau
2017-06-02 14:05       ` Marc-André Lureau
2017-06-06 12:33         ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 20/45] apic-common: make "id" property a uint32 Marc-André Lureau
2017-06-02 14:05   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 21/45] qdev: use appropriate getter/setters type Marc-André Lureau
2017-06-02 14:51   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 22/45] isa: use get_uint() for "io-base" Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 23/45] pc-dimm: use get_uint() for dimm properties Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 24/45] pc-dimm: make "size" property uint64 Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 25/45] pcihp: use get_uint() for "bsel" property Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 26/45] aspeed: use {set, get}_uint() for "ram-size" property Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 27/45] bcm2835_fb: use {get, set}_uint() for "vcram-size" and "vcram-base" Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 28/45] platform-bus: use get_uint() for "addr" property Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 29/45] acpi: use get_uint() for "acpi-pcihp-io*" properties Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 30/45] acpi: use get_uint() for various acpi properties Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 31/45] acpi: use get_uint() for "pci-hole*" properties Marc-André Lureau
2017-06-06 12:24   ` Markus Armbruster
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 32/45] pc: use get_uint() for "iobase" property Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 33/45] pc: use get_uint() for "apic-id" property Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 34/45] pc: use get_uint() for "hpet-intcap" property Marc-André Lureau
2017-05-31 13:56 ` [Qemu-devel] [PATCH v2 35/45] xen: use get_uint() for "max-ram-below-4g" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 36/45] arm: use get_uint() for "mp-affinity" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 37/45] auxbus: use get_uint() for "addr" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 38/45] pvpanic: use get_uint() for "ioport" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 39/45] pnv-core: use get_uint() for "core-pir" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 40/45] numa: use get_uint() for "size" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 41/45] i386/cpu: use get_uint() for "min-level"/"min-xlevel" properties Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 42/45] console: use get_uint() for "head" property Marc-André Lureau
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 43/45] tests/qdict: check more get_try_int() cases Marc-André Lureau
2017-06-06 12:26   ` Markus Armbruster
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 44/45] RFC: qdict: add uint Marc-André Lureau
2017-06-06 12:28   ` Markus Armbruster
2017-05-31 13:57 ` [Qemu-devel] [PATCH v2 45/45] qobject: move dump_qobject() from block/ to qobject/ Marc-André Lureau
2017-05-31 20:06 ` [Qemu-devel] [PATCH v2 00/45] qobject/qapi: add uint type no-reply
2017-06-06 12:36 ` 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=87y3tabikl.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.