Message ID | 20201211220529.2290218-17-ehabkost@redhat.com |
---|---|
State | New |
Headers | show |
Series | qdev property code cleanup | expand |
On Fri, 11 Dec 2020 17:05:13 -0500 Eduardo Habkost <ehabkost@redhat.com> wrote: > Instead of duplicating the code that sets name, info, offset, > and does type checking, make DEFINE_PROP accept a variable number > of arguments and reuse it in all DEFINE_PROP_* macros. > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> > --- > Changes v1 -> v2: > * Redone after UUID property was moved > --- > Cc: Paolo Bonzini <pbonzini@redhat.com> > Cc: "Daniel P. Berrangé" <berrange@redhat.com> > Cc: Eduardo Habkost <ehabkost@redhat.com> > Cc: qemu-devel@nongnu.org > --- > include/hw/qdev-properties-system.h | 19 ++--- > include/hw/qdev-properties.h | 114 ++++++++++------------------ > 2 files changed, 46 insertions(+), 87 deletions(-) > > diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properties-system.h > index 29529dc999..0ac327ae60 100644 > --- a/include/hw/qdev-properties-system.h > +++ b/include/hw/qdev-properties-system.h > @@ -63,22 +63,15 @@ extern const PropertyInfo qdev_prop_pcie_link_width; > DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \ > PCIExpLinkWidth) > > -#define DEFINE_PROP_UUID(_name, _state, _field) { \ > - .name = (_name), \ > - .info = &qdev_prop_uuid, \ > - .offset = offsetof(_state, _field) \ > - + type_check(QemuUUID, typeof_field(_state, _field)), \ > - .set_default = true, \ > - } > +#define DEFINE_PROP_UUID(_name, _state, _field) \ > + DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \ > + .set_default = true) > + > #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \ > DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard) > > -#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \ > - .name = (_name), \ > - .info = &qdev_prop_uuid, \ > - .offset = offsetof(_state, _field) \ > - + type_check(QemuUUID, typeof_field(_state, _field)), \ > - } > +#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \ > + DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID) > > > #endif > diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h > index d35d4aae84..1b58e4f922 100644 > --- a/include/hw/qdev-properties.h > +++ b/include/hw/qdev-properties.h > @@ -61,73 +61,46 @@ extern const PropertyInfo qdev_prop_size32; > extern const PropertyInfo qdev_prop_arraylen; > extern const PropertyInfo qdev_prop_link; > > -#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ > +#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \ > .name = (_name), \ > .info = &(_prop), \ > .offset = offsetof(_state, _field) \ > + type_check(_type, typeof_field(_state, _field)), \ > + __VA_ARGS__ \ > } > > -#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \ > - .name = (_name), \ > - .info = &(_prop), \ > - .offset = offsetof(_state, _field) \ > - + type_check(_type,typeof_field(_state, _field)), \ > - .set_default = true, \ > - .defval.i = (_type)_defval, \ > - } > +#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \ > + DEFINE_PROP(_name, _state, _field, _prop, _type, \ > + .set_default = true, \ > + .defval.i = (_type)_defval) > > -#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ > - .name = (_name), \ > - .info = &(_prop), \ > - .offset = offsetof(_state, _field) \ > - + type_check(_type, typeof_field(_state, _field)), \ > - } > +#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \ > + DEFINE_PROP(_name, _state, _field, _prop, _type) > > -#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)), \ > - .set_default = true, \ > - .defval.u = (bool)_defval, \ > - } > +#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \ > + DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \ > + .bitnr = (_bit), \ > + .set_default = true, \ > + .defval.u = (bool)_defval) > > -#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \ > - .name = (_name), \ > - .info = &(_prop), \ > - .offset = offsetof(_state, _field) \ > - + type_check(_type, typeof_field(_state, _field)), \ > - .set_default = true, \ > - .defval.u = (_type)_defval, \ > - } > +#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \ > + DEFINE_PROP(_name, _state, _field, _prop, _type, \ > + .set_default = true, \ > + .defval.u = (_type)_defval) > > -#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ > - .name = (_name), \ > - .info = &(_prop), \ > - .offset = offsetof(_state, _field) \ > - + type_check(_type, typeof_field(_state, _field)), \ > - } > +#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \ > + DEFINE_PROP(_name, _state, _field, _prop, _type) > > -#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)), \ > - .set_default = true, \ > - .defval.u = (bool)_defval, \ > - } > +#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \ > + DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \ > + .bitnr = (_bit), \ > + .set_default = true, \ > + .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)), \ > - .set_default = true, \ > - .defval.u = (bool)_defval, \ > - } > +#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ > + DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \ > + .set_default = true, \ > + .defval.u = (bool)_defval) > > #define PROP_ARRAY_LEN_PREFIX "len-" > > @@ -155,26 +128,19 @@ extern const PropertyInfo qdev_prop_link; > * It is the responsibility of the device deinit code to free the > * @_arrayfield memory. > */ > -#define DEFINE_PROP_ARRAY(_name, _state, _field, \ > - _arrayfield, _arrayprop, _arraytype) { \ > - .name = (PROP_ARRAY_LEN_PREFIX _name), \ > - .info = &(qdev_prop_arraylen), \ > - .set_default = true, \ > - .defval.u = 0, \ > - .offset = offsetof(_state, _field) \ > - + type_check(uint32_t, typeof_field(_state, _field)), \ > - .arrayinfo = &(_arrayprop), \ > - .arrayfieldsize = sizeof(_arraytype), \ > - .arrayoffset = offsetof(_state, _arrayfield), \ > - } > +#define DEFINE_PROP_ARRAY(_name, _state, _field, \ > + _arrayfield, _arrayprop, _arraytype) \ > + DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \ > + _state, _field, qdev_prop_arraylen, uint32_t, \ > + .set_default = true, \ > + .defval.u = 0, \ > + .arrayinfo = &(_arrayprop), \ > + .arrayfieldsize = sizeof(_arraytype), \ > + .arrayoffset = offsetof(_state, _arrayfield)) > > -#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \ > - .name = (_name), \ > - .info = &(qdev_prop_link), \ > - .offset = offsetof(_state, _field) \ > - + type_check(_ptr_type, typeof_field(_state, _field)), \ > - .link_type = _type, \ > - } > +#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \ > + DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \ > + .link_type = _type) > > #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ > DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properties-system.h index 29529dc999..0ac327ae60 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -63,22 +63,15 @@ extern const PropertyInfo qdev_prop_pcie_link_width; DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \ PCIExpLinkWidth) -#define DEFINE_PROP_UUID(_name, _state, _field) { \ - .name = (_name), \ - .info = &qdev_prop_uuid, \ - .offset = offsetof(_state, _field) \ - + type_check(QemuUUID, typeof_field(_state, _field)), \ - .set_default = true, \ - } +#define DEFINE_PROP_UUID(_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID, \ + .set_default = true) + #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard) -#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \ - .name = (_name), \ - .info = &qdev_prop_uuid, \ - .offset = offsetof(_state, _field) \ - + type_check(QemuUUID, typeof_field(_state, _field)), \ - } +#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID) #endif diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index d35d4aae84..1b58e4f922 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -61,73 +61,46 @@ extern const PropertyInfo qdev_prop_size32; extern const PropertyInfo qdev_prop_arraylen; extern const PropertyInfo qdev_prop_link; -#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ +#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \ .name = (_name), \ .info = &(_prop), \ .offset = offsetof(_state, _field) \ + type_check(_type, typeof_field(_state, _field)), \ + __VA_ARGS__ \ } -#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \ - .name = (_name), \ - .info = &(_prop), \ - .offset = offsetof(_state, _field) \ - + type_check(_type,typeof_field(_state, _field)), \ - .set_default = true, \ - .defval.i = (_type)_defval, \ - } +#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \ + DEFINE_PROP(_name, _state, _field, _prop, _type, \ + .set_default = true, \ + .defval.i = (_type)_defval) -#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ - .name = (_name), \ - .info = &(_prop), \ - .offset = offsetof(_state, _field) \ - + type_check(_type, typeof_field(_state, _field)), \ - } +#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \ + DEFINE_PROP(_name, _state, _field, _prop, _type) -#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)), \ - .set_default = true, \ - .defval.u = (bool)_defval, \ - } +#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \ + .bitnr = (_bit), \ + .set_default = true, \ + .defval.u = (bool)_defval) -#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \ - .name = (_name), \ - .info = &(_prop), \ - .offset = offsetof(_state, _field) \ - + type_check(_type, typeof_field(_state, _field)), \ - .set_default = true, \ - .defval.u = (_type)_defval, \ - } +#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \ + DEFINE_PROP(_name, _state, _field, _prop, _type, \ + .set_default = true, \ + .defval.u = (_type)_defval) -#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ - .name = (_name), \ - .info = &(_prop), \ - .offset = offsetof(_state, _field) \ - + type_check(_type, typeof_field(_state, _field)), \ - } +#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \ + DEFINE_PROP(_name, _state, _field, _prop, _type) -#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)), \ - .set_default = true, \ - .defval.u = (bool)_defval, \ - } +#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \ + .bitnr = (_bit), \ + .set_default = true, \ + .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)), \ - .set_default = true, \ - .defval.u = (bool)_defval, \ - } +#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \ + .set_default = true, \ + .defval.u = (bool)_defval) #define PROP_ARRAY_LEN_PREFIX "len-" @@ -155,26 +128,19 @@ extern const PropertyInfo qdev_prop_link; * It is the responsibility of the device deinit code to free the * @_arrayfield memory. */ -#define DEFINE_PROP_ARRAY(_name, _state, _field, \ - _arrayfield, _arrayprop, _arraytype) { \ - .name = (PROP_ARRAY_LEN_PREFIX _name), \ - .info = &(qdev_prop_arraylen), \ - .set_default = true, \ - .defval.u = 0, \ - .offset = offsetof(_state, _field) \ - + type_check(uint32_t, typeof_field(_state, _field)), \ - .arrayinfo = &(_arrayprop), \ - .arrayfieldsize = sizeof(_arraytype), \ - .arrayoffset = offsetof(_state, _arrayfield), \ - } +#define DEFINE_PROP_ARRAY(_name, _state, _field, \ + _arrayfield, _arrayprop, _arraytype) \ + DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \ + _state, _field, qdev_prop_arraylen, uint32_t, \ + .set_default = true, \ + .defval.u = 0, \ + .arrayinfo = &(_arrayprop), \ + .arrayfieldsize = sizeof(_arraytype), \ + .arrayoffset = offsetof(_state, _arrayfield)) -#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \ - .name = (_name), \ - .info = &(qdev_prop_link), \ - .offset = offsetof(_state, _field) \ - + type_check(_ptr_type, typeof_field(_state, _field)), \ - .link_type = _type, \ - } +#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \ + .link_type = _type) #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
Instead of duplicating the code that sets name, info, offset, and does type checking, make DEFINE_PROP accept a variable number of arguments and reuse it in all DEFINE_PROP_* macros. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Changes v1 -> v2: * Redone after UUID property was moved --- Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: "Daniel P. Berrangé" <berrange@redhat.com> Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: qemu-devel@nongnu.org --- include/hw/qdev-properties-system.h | 19 ++--- include/hw/qdev-properties.h | 114 ++++++++++------------------ 2 files changed, 46 insertions(+), 87 deletions(-)