Message ID | 1408614466-17596-2-git-send-email-arei.gonglei@huawei.com |
---|---|
State | New |
Headers | show |
On Thu, Aug 21, 2014 at 05:47:45PM +0800, arei.gonglei@huawei.com wrote: > From: Gonglei <arei.gonglei@huawei.com> > > We need to use qbus's parent and get its name. > > Signed-off-by: Gonglei <arei.gonglei@huawei.com> > --- > hw/core/qdev.c | 7 +++++++ > include/hw/qdev-core.h | 1 + > 2 files changed, 8 insertions(+) > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index da1ba48..5c49e08 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -616,6 +616,13 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam > return bus; > } > > +DeviceState *qbus_get_parent(BusState *bus) > +{ > + DeviceState *parent = bus->parent; > + > + return parent; > +} You can return bus->parent directly, or safer: if (bus) { return bus->parent; } return NULL; And, the function is simple enough to make it inline. > + > static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) > { > BusClass *bc = BUS_GET_CLASS(bus); > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > index 0799ff2..760e726 100644 > --- a/include/hw/qdev-core.h > +++ b/include/hw/qdev-core.h > @@ -301,6 +301,7 @@ typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); > void qbus_create_inplace(void *bus, size_t size, const char *typename, > DeviceState *parent, const char *name); > BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); > +DeviceState *qbus_get_parent(BusState *bus); > /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, > * < 0 if either devfn or busfn terminate walk somewhere in cursion, > * 0 otherwise. */ > -- > 1.7.12.4 > >
> From: Hu Tao [mailto:hutao@cn.fujitsu.com] > On Thu, Aug 21, 2014 at 05:47:45PM +0800, arei.gonglei@huawei.com wrote: > > From: Gonglei <arei.gonglei@huawei.com> > > > > We need to use qbus's parent and get its name. > > > > Signed-off-by: Gonglei <arei.gonglei@huawei.com> > > --- > > hw/core/qdev.c | 7 +++++++ > > include/hw/qdev-core.h | 1 + > > 2 files changed, 8 insertions(+) > > > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > > index da1ba48..5c49e08 100644 > > --- a/hw/core/qdev.c > > +++ b/hw/core/qdev.c > > @@ -616,6 +616,13 @@ BusState *qbus_create(const char *typename, > DeviceState *parent, const char *nam > > return bus; > > } > > > > +DeviceState *qbus_get_parent(BusState *bus) > > +{ > > + DeviceState *parent = bus->parent; > > + > > + return parent; > > +} > > You can return bus->parent directly, or safer: > > if (bus) { > return bus->parent; > } > > return NULL; > It should not happen, at the moment, but it is more safer, indeed. Thanks. > And, the function is simple enough to make it inline. > Yes, it is simple. I just follow the realization of qdev_get_parent_bus() Best regards, -Gonglei
diff --git a/hw/core/qdev.c b/hw/core/qdev.c index da1ba48..5c49e08 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -616,6 +616,13 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam return bus; } +DeviceState *qbus_get_parent(BusState *bus) +{ + DeviceState *parent = bus->parent; + + return parent; +} + static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) { BusClass *bc = BUS_GET_CLASS(bus); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 0799ff2..760e726 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -301,6 +301,7 @@ typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); void qbus_create_inplace(void *bus, size_t size, const char *typename, DeviceState *parent, const char *name); BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); +DeviceState *qbus_get_parent(BusState *bus); /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, * < 0 if either devfn or busfn terminate walk somewhere in cursion, * 0 otherwise. */