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

Eduardo Habkost posted 36 patches 5 years, 3 months ago
Maintainers: Antony Pavlov <antonynpavlov@gmail.com>, Halil Pasic <pasic@linux.ibm.com>, Juan Quintela <quintela@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Cédric Le Goater" <clg@kaod.org>, Paolo Bonzini <pbonzini@redhat.com>, Jason Wang <jasowang@redhat.com>, Richard Henderson <rth@twiddle.net>, John Snow <jsnow@redhat.com>, Magnus Damm <magnus.damm@gmail.com>, Max Reitz <mreitz@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Alberto Garcia <berto@igalia.com>, Fabien Chouteau <chouteau@adacore.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Laurent Vivier <lvivier@redhat.com>, Sarah Harris <S.E.Harris@kent.ac.uk>, Eric Auger <eric.auger@redhat.com>, Thomas Huth <huth@tuxfamily.org>, Anthony Perard <anthony.perard@citrix.com>, Raphael Norwitz <raphael.norwitz@nutanix.com>, Jiri Pirko <jiri@resnulli.us>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Gerd Hoffmann <kraxel@redhat.com>, Christian Borntraeger <borntraeger@de.ibm.com>, Eduardo Habkost <ehabkost@redhat.com>, Artyom Tarasenko <atar4qemu@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Amit Shah <amit@kernel.org>, Andrew Baumann <Andrew.Baumann@microsoft.com>, Corey Minyard <minyard@acm.org>, Joel Stanley <joel@jms.id.au>, Igor Mitsyanko <i.mitsyanko@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Alex Williamson <alex.williamson@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Peter Chubb <peter.chubb@nicta.com.au>, Andrzej Zaborowski <balrogg@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Michael Rolnik <mrolnik@gmail.com>, Paul Durrant <paul@xen.org>, KONRAD Frederic <frederic.konrad@adacore.com>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Michael Walle <michael@walle.cc>, Yoshinori Sato <ysato@users.sourceforge.jp>, Stefan Hajnoczi <stefanha@redhat.com>, Yuval Shaia <yuval.shaia.ml@gmail.com>
There is a newer version of this series
[PATCH 18/36] qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen()
Posted by Eduardo Habkost 5 years, 3 months ago
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(-)

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


Re: [PATCH 18/36] qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen()
Posted by Marc-André Lureau 5 years, 3 months ago
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
>
>
>

-- 
Marc-André Lureau