All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-5.0 0/8] ppc: Consolidate QOM links and pointers to the same object
@ 2019-11-15 11:53 Greg Kurz
  2019-11-15 11:53 ` [PATCH for-5.0 1/8] xive: Link "cpu" property to XiveTCTX::cs pointer Greg Kurz
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Greg Kurz @ 2019-11-15 11:53 UTC (permalink / raw)
  To: David Gibson, Cédric Le Goater; +Cc: qemu-ppc, qemu-devel

There's a recurring pattern in the code where a const link is added to a
newly instanciated object and the link is then used in the object's realize
function to keep a pointer to the QOM entity which the link points to.

void create_obj_B(Object *obj_a)
{
    Object *obj_b;

    obj_b = object_new(TYPE_B);
    object_property_add_const_link(obj_b, "link-to-a", obj_a, &error_abort);
}

void object_B_realize(DeviceState *dev, Error **errp)
{
    Object *obj_a;

    obj_a = object_property_get_link(OBJECT(dev), "link-to-a", errp);
    if (!obj_a) {
        return;
    }

    obj_b->obj_a = A(obj_a); // If obj_b->obj_a is changed, the link property
                             // still points to the original obj_a that was
                             // passed to object_property_add_const_link()
}

Confusing bugs could arise if the pointer and the link go out of sync for
some reason. This can be avoided if the property is defined to directly use
the pointer with object_property_add_link() and object_property_set_link().

This series just does that for all occurences of the fragile pattern in
the XIVE and PNV code.

--
Greg

---

Greg Kurz (8):
      xive: Link "cpu" property to XiveTCTX::cs pointer
      xive: Link "xive" property to XiveSource::xive pointer
      xive: Link "xive" property to XiveEndSource::xrtr pointer
      ppc/pnv: Link "psi" property to PnvLpc::psi pointer
      ppc/pnv: Link "psi" property to PnvOCC::psi pointer
      ppc/pnv: Link "chip" property to PnvHomer::chip pointer
      ppc/pnv: Link "chip" property to PnvCore::chip pointer
      ppc/pnv: Link "chip" property to PnvXive::chip pointer


 hw/intc/pnv_xive.c        |   29 +++++++++-----------
 hw/intc/spapr_xive.c      |    8 +++---
 hw/intc/xive.c            |   65 ++++++++++++++++++++++-----------------------
 hw/ppc/pnv.c              |   32 +++++++++++-----------
 hw/ppc/pnv_core.c         |   18 +++++++-----
 hw/ppc/pnv_homer.c        |   24 +++++++++--------
 hw/ppc/pnv_lpc.c          |   23 ++++++++--------
 hw/ppc/pnv_occ.c          |   23 ++++++++--------
 hw/ppc/pnv_psi.c          |    3 +-
 include/hw/ppc/pnv.h      |    2 +
 include/hw/ppc/pnv_core.h |    2 +
 11 files changed, 115 insertions(+), 114 deletions(-)



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-11-15 13:29 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-15 11:53 [PATCH for-5.0 0/8] ppc: Consolidate QOM links and pointers to the same object Greg Kurz
2019-11-15 11:53 ` [PATCH for-5.0 1/8] xive: Link "cpu" property to XiveTCTX::cs pointer Greg Kurz
2019-11-15 11:53 ` [PATCH for-5.0 2/8] xive: Link "xive" property to XiveSource::xive pointer Greg Kurz
2019-11-15 11:53 ` [PATCH for-5.0 3/8] xive: Link "xive" property to XiveEndSource::xrtr pointer Greg Kurz
2019-11-15 11:53 ` [PATCH for-5.0 4/8] ppc/pnv: Link "psi" property to PnvLpc::psi pointer Greg Kurz
2019-11-15 11:53 ` [PATCH for-5.0 5/8] ppc/pnv: Link "psi" property to PnvOCC::psi pointer Greg Kurz
2019-11-15 11:53 ` [PATCH for-5.0 6/8] ppc/pnv: Link "chip" property to PnvHomer::chip pointer Greg Kurz
2019-11-15 11:54 ` [PATCH for-5.0 7/8] ppc/pnv: Link "chip" property to PnvCore::chip pointer Greg Kurz
2019-11-15 12:24   ` Cédric Le Goater
2019-11-15 12:45     ` Greg Kurz
2019-11-15 11:54 ` [PATCH for-5.0 8/8] ppc/pnv: Link "chip" property to PnvXive::chip pointer Greg Kurz
2019-11-15 12:25   ` Cédric Le Goater
2019-11-15 12:46     ` Greg Kurz
2019-11-15 12:16 ` [PATCH for-5.0 0/8] ppc: Consolidate QOM links and pointers to the same object Cédric Le Goater
2019-11-15 13:28   ` Greg Kurz

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.