diff mbox series

[18/36] qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen()

Message ID 20201029220246.472693-19-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show
Series Make qdev static property API usable by any QOM type | expand

Commit Message

Eduardo Habkost Oct. 29, 2020, 10:02 p.m. UTC
We're just doing pointer math with the device pointer, we can
simply use obj instead.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 hw/core/qdev-properties.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Marc-André Lureau Oct. 30, 2020, 9:59 a.m. UTC | #1
On Fri, Oct 30, 2020 at 2:18 AM Eduardo Habkost <ehabkost@redhat.com> wrote:

> We're just doing pointer math with the device pointer, we can
> simply use obj instead.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>

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

---
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Daniel P. Berrangé" <berrange@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  hw/core/qdev-properties.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 68b1666e14..27c09255d7 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -610,10 +610,9 @@ static void set_prop_arraylen(Object *obj, Visitor
> *v, const char *name,
>       * array-length field in the device struct, we have to create the
>       * array itself and dynamically add the corresponding properties.
>       */
> -    DeviceState *dev = DEVICE(obj);
>      Property *prop = opaque;
>      uint32_t *alenptr = qdev_get_prop_ptr(obj, prop);
> -    void **arrayptr = (void *)dev + prop->arrayoffset;
> +    void **arrayptr = (void *)obj + prop->arrayoffset;
>      void *eltptr;
>      const char *arrayname;
>      int i;
> @@ -653,7 +652,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v,
> const char *name,
>           * they get the right answer despite the array element not
> actually
>           * being inside the device struct.
>           */
> -        arrayprop->prop.offset = eltptr - (void *)dev;
> +        arrayprop->prop.offset = eltptr - (void *)obj;
>          assert(qdev_get_prop_ptr(obj, &arrayprop->prop) == eltptr);
>          object_property_add(obj, propname,
>                              arrayprop->prop.info->name,
> --
> 2.28.0
>
>
>
diff mbox series

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 68b1666e14..27c09255d7 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -610,10 +610,9 @@  static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
      * array-length field in the device struct, we have to create the
      * array itself and dynamically add the corresponding properties.
      */
-    DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     uint32_t *alenptr = qdev_get_prop_ptr(obj, prop);
-    void **arrayptr = (void *)dev + prop->arrayoffset;
+    void **arrayptr = (void *)obj + prop->arrayoffset;
     void *eltptr;
     const char *arrayname;
     int i;
@@ -653,7 +652,7 @@  static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
          * they get the right answer despite the array element not actually
          * being inside the device struct.
          */
-        arrayprop->prop.offset = eltptr - (void *)dev;
+        arrayprop->prop.offset = eltptr - (void *)obj;
         assert(qdev_get_prop_ptr(obj, &arrayprop->prop) == eltptr);
         object_property_add(obj, propname,
                             arrayprop->prop.info->name,