From 18c22d7112a76fabeee5022a3bdd9e8c3a37c8d2 Mon Sep 17 00:00:00 2001 From: Yang Weijiang Date: Tue, 15 Feb 2022 14:52:51 -0500 Subject: qdev-properties: Add a new macro with bitmask check for uint64_t property The DEFINE_PROP_UINT64_CHECKMASK maro applies certain mask check agaist user-supplied property value, reject the value if it violates the bitmask. Co-developed-by: Like Xu Signed-off-by: Like Xu Signed-off-by: Yang Weijiang Message-Id: <20220215195258.29149-2-weijiang.yang@intel.com> Signed-off-by: Paolo Bonzini --- hw/core/qdev-properties.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'hw/core') diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index c34aac6..357b876 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -428,6 +428,25 @@ const PropertyInfo qdev_prop_int64 = { .set_default_value = qdev_propinfo_set_default_value_int, }; +static void set_uint64_checkmask(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Property *prop = opaque; + uint64_t *ptr = object_field_prop_ptr(obj, prop); + + visit_type_uint64(v, name, ptr, errp); + if (*ptr & ~prop->bitmask) { + error_setg(errp, "Property value for '%s' has bits outside mask '0x%" PRIx64 "'", + name, prop->bitmask); + } +} + +const PropertyInfo qdev_prop_uint64_checkmask = { + .name = "uint64", + .get = get_uint64, + .set = set_uint64_checkmask, +}; + /* --- string --- */ static void release_string(Object *obj, const char *name, void *opaque) -- cgit v1.1