hw/qdev: Housekeeping around qdev_get_parent_bus()
cover hw/qdev: Housekeeping around qdev_get_parent_bus()
DeviceState::parent_bus is an internal field and should be accessed by the qdev_get_parent_bus() helper. Replace most uses.
Philippe Mathieu-Daudé (4):
hw/qdev: Constify DeviceState* argument of qdev_get_parent_bus()
hw: Replace dev->parent_bus by qdev_get_parent_bus(dev)
hw: Use qdev_get_parent_bus() in
qdev_get_own_fw_dev_path_from_handler()
qdev-monitor: Use qdev_get_parent_bus() in bus_print_dev()
hw/audio/intel-hda.c | 2 +- hw/block/fdc.c | 2 +- hw/block/swim.c | 2 +- hw/core/qdev-fw.c | 9 +++++---- hw/core/qdev.c | 2 +- hw/ide/qdev.c | 4 ++-- hw/net/virtio-net.c | 2 +- hw/pci-bridge/pci_expander_bridge.c | 2 +- hw/scsi/scsi-bus.c | 2 +- hw/usb/bus.c | 2 +- hw/usb/desc.c | 2 +- hw/usb/dev-smartcard-reader.c | 16 ++++++++-------- include/hw/qdev-core.h | 4 ++-- softmmu/bootdevice.c | 2 +- softmmu/qdev-monitor.c | 6 +++--- 15 files changed, 30 insertions(+), 29 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/4 hw/qdev: Constify DeviceState* argument of qdev_get_parent_bus()
The structure is accessed read-only by qdev_get_parent_bus().
--- hw/core/qdev.c | 2 +- include/hw/qdev-core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/core/qdev.c +1 -1
@@ -330,7 +330,7 @@ bool qdev_machine_modified(void)return qdev_hot_added || qdev_hot_removed; } -BusState *qdev_get_parent_bus (DeviceState *dev) +BusState *qdev_get_parent_bus (const DeviceState *dev) {return dev->parent_bus; }
include/hw/qdev-core.h +1 -1
@@ -715,7 +715,7 @@ static inline void qdev_init_gpio_in_named(DeviceState *dev,void qdev_pass_gpios (DeviceState *dev,DeviceState *container,const char *name); -BusState *qdev_get_parent_bus (DeviceState *dev); +BusState *qdev_get_parent_bus (const DeviceState *dev);/*** BUS API. ***/
Signature · 1 line
2.38.1
Re: [PATCH 1/4] hw/qdev: Constify DeviceState* argument of qdev_get_parent_bus()
Quoted 7 lines · Philippe Mathieu-Daudé
The structure is accessed read-only by
qdev_get_parent_bus().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/core/qdev.c | 2 +- include/hw/qdev-core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
r~
PATCH 2/4 hw: Replace dev->parent_bus by qdev_get_parent_bus(dev)
In reply to Philippe Mathieu-DaudéDeviceState::parent_bus is an internal field and should be accessed by the qdev_get_parent_bus() helper. Replace all uses in hw/ except the QDev uses in hw/core/.
--- hw/audio/intel-hda.c | 2 +- hw/block/fdc.c | 2 +- hw/block/swim.c | 2 +- hw/ide/qdev.c | 4 ++-- hw/net/virtio-net.c | 2 +- hw/pci-bridge/pci_expander_bridge.c | 2 +- hw/scsi/scsi-bus.c | 2 +- hw/usb/bus.c | 2 +- hw/usb/desc.c | 2 +- hw/usb/dev-smartcard-reader.c | 16 ++++++++-------- 10 files changed, 18 insertions(+), 18 deletions(-)
hw/audio/intel-hda.c +1 -1
@@ -59,7 +59,7 @@ void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size,static void hda_codec_dev_realize (DeviceState *qdev,Error **errp) { -HDACodecBus *bus =HDA_BUS (qdev->parent_bus); +HDACodecBus *bus =HDA_BUS (qdev_get_parent_bus (qdev));HDACodecDevice *dev =HDA_CODEC_DEVICE (qdev);HDACodecDeviceClass *cdc =HDA_CODEC_DEVICE_GET_CLASS (dev);
hw/block/fdc.c +1 -1
@@ -466,7 +466,7 @@ static Property floppy_drive_properties[] = {static void floppy_drive_realize (DeviceState *qdev,Error **errp) {FloppyDrive *dev =FLOPPY_DRIVE (qdev); -FloppyBus *bus =FLOPPY_BUS (qdev->parent_bus); +FloppyBus *bus =FLOPPY_BUS (qdev_get_parent_bus (qdev));FDrive *drive;bool read_only;int ret;
hw/block/swim.c +1 -1
@@ -157,7 +157,7 @@ static Property swim_drive_properties[] = {static void swim_drive_realize (DeviceState *qdev,Error **errp) {SWIMDrive *dev =SWIM_DRIVE (qdev); -SWIMBus *bus =SWIM_BUS (qdev->parent_bus); +SWIMBus *bus =SWIM_BUS (qdev_get_parent_bus (qdev));FDrive *drive;int ret;
hw/ide/qdev.c +2 -2
@@ -81,7 +81,7 @@ static char *idebus_get_fw_dev_path(DeviceState *dev)char path[30 ];snprintf (path,sizeof (path),"%s@%x" ,qdev_fw_name (dev), - ((IDEBus *)dev->parent_bus)->bus_id); + ((IDEBus *)qdev_get_parent_bus (dev))->bus_id);return g_strdup (path); }
@@ -90,7 +90,7 @@ static void ide_qdev_realize(DeviceState *qdev, Error **errp) {IDEDevice *dev =IDE_DEVICE (qdev);IDEDeviceClass *dc =IDE_DEVICE_GET_CLASS (dev); -IDEBus *bus =DO_UPCAST (IDEBus, qbus, qdev->parent_bus); +IDEBus *bus =DO_UPCAST (IDEBus, qbus,qdev_get_parent_bus (qdev));if (dev->unit ==-1 ) { dev->unit = bus->master ?1 :0 ;
hw/net/virtio-net.c +1 -1
@@ -3423,7 +3423,7 @@ static bool failover_replug_primary(VirtIONet *n, DeviceState *dev,if (!pdev->partially_hotplugged) {return true; } - primary_bus = dev->parent_bus; + primary_bus =qdev_get_parent_bus (dev);if (!primary_bus) {error_setg (errp,"virtio_net: couldn't find primary bus" );return false;
hw/pci-bridge/pci_expander_bridge.c +1 -1
@@ -151,7 +151,7 @@ static char *pxb_host_ofw_unit_address(const SysBusDevice *dev)assert (position >=0 ); pxb_dev_base =DEVICE (pxb_dev); - main_host =PCI_HOST_BRIDGE (pxb_dev_base->parent_bus->parent); + main_host =PCI_HOST_BRIDGE (qdev_get_parent_bus (pxb_dev_base)->parent); main_host_sbd =SYS_BUS_DEVICE (main_host);if (main_host_sbd->num_mmio >0 ) {
hw/scsi/scsi-bus.c +1 -1
@@ -1671,7 +1671,7 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense)static char *scsibus_get_dev_path (DeviceState *dev) {SCSIDevice *d =SCSI_DEVICE (dev); -DeviceState *hba = dev->parent_bus->parent; +DeviceState *hba =qdev_get_parent_bus (dev)->parent;char *id;char *path;
hw/usb/bus.c +1 -1
@@ -595,7 +595,7 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)static char *usb_get_dev_path (DeviceState *qdev) {USBDevice *dev =USB_DEVICE (qdev); -DeviceState *hcd = qdev->parent_bus->parent; +DeviceState *hcd =qdev_get_parent_bus (qdev)->parent;char *id =qdev_get_dev_path (hcd);if (id) {
hw/usb/desc.c +1 -1
@@ -553,7 +553,7 @@ void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)*/ void usb_desc_create_serial (USBDevice *dev) { -DeviceState *hcd = dev->qdev.parent_bus->parent; +DeviceState *hcd =qdev_get_parent_bus (DEVICE (dev))->parent;const USBDesc *desc =usb_device_get_usb_desc (dev);int index = desc->id.iSerialNumber;char *path, *serial;
hw/usb/dev-smartcard-reader.c +8 -8
@@ -1187,7 +1187,7 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *card, uint8_t *apdu, uint32_t len) {DeviceState *qdev =DEVICE (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev);Answer *answer;
@@ -1210,7 +1210,7 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *card,void ccid_card_card_removed (CCIDCardState *card) {DeviceState *qdev =DEVICE (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev);ccid_on_slot_change (s, false);
@@ -1221,7 +1221,7 @@ void ccid_card_card_removed(CCIDCardState *card)int ccid_card_ccid_attach (CCIDCardState *card) {DeviceState *qdev =DEVICE (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev);DPRINTF (s,1 ,"CCID Attach\n" );
@@ -1231,7 +1231,7 @@ int ccid_card_ccid_attach(CCIDCardState *card)void ccid_card_ccid_detach (CCIDCardState *card) {DeviceState *qdev =DEVICE (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev);DPRINTF (s,1 ,"CCID Detach\n" );
@@ -1244,7 +1244,7 @@ void ccid_card_ccid_detach(CCIDCardState *card)void ccid_card_card_error (CCIDCardState *card,uint64_t error) {DeviceState *qdev =DEVICE (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev); s->bmCommandStatus =COMMAND_STATUS_FAILED ;
@@ -1263,7 +1263,7 @@ void ccid_card_card_error(CCIDCardState *card, uint64_t error)void ccid_card_card_inserted (CCIDCardState *card) {DeviceState *qdev =DEVICE (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev); s->bmCommandStatus =COMMAND_STATUS_NO_ERROR ;
@@ -1275,7 +1275,7 @@ static void ccid_card_unrealize(DeviceState *qdev) {CCIDCardState *card =CCID_CARD (qdev);CCIDCardClass *cc =CCID_CARD_GET_CLASS (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev);if (ccid_card_inserted (s)) {
@@ -1291,7 +1291,7 @@ static void ccid_card_realize(DeviceState *qdev, Error **errp) {CCIDCardState *card =CCID_CARD (qdev);CCIDCardClass *cc =CCID_CARD_GET_CLASS (card); -USBDevice *dev =USB_DEVICE (qdev->parent_bus->parent); +USBDevice *dev =USB_DEVICE (qdev_get_parent_bus (qdev)->parent);USBCCIDState *s =USB_CCID_DEV (dev);Error *local_err =NULL ;
Signature · 1 line
2.38.1
Re: [PATCH 2/4] hw: Replace dev->parent_bus by qdev_get_parent_bus(dev)
Quoted 5 lines · Philippe Mathieu-Daudé
DeviceState::parent_busis an internal field and should be accessed by theqdev_get_parent_bus()helper. Replace all uses in hw/ except the QDev uses in hw/core/.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 12 lines
--- hw/audio/intel-hda.c | 2 +- hw/block/fdc.c | 2 +- hw/block/swim.c | 2 +- hw/ide/qdev.c | 4 ++-- hw/net/virtio-net.c | 2 +- hw/pci-bridge/pci_expander_bridge.c | 2 +- hw/scsi/scsi-bus.c | 2 +- hw/usb/bus.c | 2 +- hw/usb/desc.c | 2 +- hw/usb/dev-smartcard-reader.c | 16 ++++++++-------- 10 files changed, 18 insertions(+), 18 deletions(-)
I missed:
-- >8 --
hw/audio/intel-hda.c +0 -0
@@ -103,14 +103,14 @@ HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad) void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t
response)
{
- HDACodecBus *bus = HDA_BUS(dev->qdev.parent_bus);
+ HDACodecBus *bus = HDA_BUS(qdev_get_parent_bus(DEVICE(dev)));
bus->response(dev, solicited, response);}
bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
uint8_t *buf, uint32_t len)
{
- HDACodecBus *bus = HDA_BUS(dev->qdev.parent_bus);
+ HDACodecBus *bus = HDA_BUS(qdev_get_parent_bus(DEVICE(dev)));
return bus->xfer(dev, stnr, output, buf, len);}
@@ -344,7 +344,7 @@ static void intel_hda_corb_run(IntelHDAState *d)
static void intel_hda_response(HDACodecDevice *dev, bool solicited,uint32_t response)
{
const MemTxAttrs attrs = { .memory = true };
- HDACodecBus *bus = HDA_BUS(dev->qdev.parent_bus);
+ HDACodecBus *bus = HDA_BUS(qdev_get_parent_bus(DEVICE(dev)));
IntelHDAState *d = container_of(bus, IntelHDAState, codecs);
hwaddr addr;
uint32_t wp, ex;
@@ -399,7 +399,7 @@ static bool intel_hda_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
uint8_t *buf, uint32_t len)
{
const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
- HDACodecBus *bus = HDA_BUS(dev->qdev.parent_bus);
+ HDACodecBus *bus = HDA_BUS(qdev_get_parent_bus(DEVICE(dev)));
IntelHDAState *d = container_of(bus, IntelHDAState, codecs);
hwaddr addr;
uint32_t s, copy, left;hw/ide/qdev.c +0 -0
@@ -164,7 +164,7 @@ typedef struct IDEDrive { static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error
**errp)
{
- IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
+ IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev_get_parent_bus(DEVICE(dev)));
IDEState *s = bus->ifs + dev->unit;
int ret;hw/ppc/spapr_vio.c +2 -2
@@ -382,7 +382,7 @@ static void rtas_quiesce(PowerPCCPU *cpu, SpaprMachineState *spapr,static SpaprVioDevice *reg_conflict (SpaprVioDevice *dev) { -SpaprVioBus *bus =SPAPR_VIO_BUS (dev->qdev.parent_bus); +SpaprVioBus *bus =SPAPR_VIO_BUS (qdev_get_parent_bus (DEVICE (dev)));BusChild *kid;SpaprVioDevice *other;
@@ -492,7 +492,7 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp) } }else {/* Need to assign an address */ -SpaprVioBus *bus =SPAPR_VIO_BUS (dev->qdev.parent_bus); +SpaprVioBus *bus =SPAPR_VIO_BUS (qdev_get_parent_bus (DEVICE (dev))); do { dev->reg = bus->next_reg++;
hw/scsi/scsi-bus.c +6 -6
@@ -104,7 +104,7 @@ static void scsi_device_unrealize(SCSIDevice *s)int scsi_bus_parse_cdb (SCSIDevice *dev,SCSICommand *cmd,uint8_t *buf,size_t buf_len,void *hba_private) { -SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus,qdev_get_parent_bus (DEVICE (dev)));int rc;assert (cmd->len ==0 );
@@ -250,7 +250,7 @@ static bool scsi_bus_check_address(BusState *qbus, DeviceState *qdev, Error **erstatic void scsi_qdev_realize (DeviceState *qdev,Error **errp) {SCSIDevice *dev =SCSI_DEVICE (qdev); -SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus,qdev_get_parent_bus (DEVICE (dev)));bool is_free;Error *local_err =NULL ;
@@ -705,7 +705,7 @@ SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d,SCSIRequest *scsi_req_new (SCSIDevice *d,uint32_t tag,uint32_t lun,uint8_t *buf,size_t buf_len,void *hba_private) { -SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, d->qdev.parent_bus); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus,qdev_get_parent_bus (DEVICE (d)));const SCSIReqOps *ops;SCSIDeviceClass *sc =SCSI_DEVICE_GET_CLASS (d);SCSIRequest *req;
@@ -1353,7 +1353,7 @@ int scsi_req_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf,void scsi_device_report_change (SCSIDevice *dev,SCSISense sense) { -SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus,qdev_get_parent_bus (DEVICE (dev)));scsi_device_set_ua (dev, sense);if (bus->info->change) {
@@ -1372,7 +1372,7 @@ void scsi_req_unref(SCSIRequest *req) {assert (req->refcount >0 );if (--req->refcount ==0 ) { -BusState *qbus = req->dev->qdev.parent_bus; +BusState *qbus =qdev_get_parent_bus (DEVICE (req->dev));SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, qbus);if (bus->info->free_request && req->hba_private) {
@@ -1444,7 +1444,7 @@ void scsi_req_print(SCSIRequest *req)int i;fprintf (fp,"[%s id=%d] %s" , - req->dev->qdev.parent_bus->name, +qdev_get_parent_bus (DEVICE (req->dev))->name, req->dev->id,scsi_command_name (req->cmd.buf[0 ]));for (i =1 ; i < req->cmd.len; i++) {
@@ -1698,7 +1698,7 @@ static int put_scsi_requests(QEMUFile *f, void *pv, size_t size,const VMStateField *field, JSONWriter
*vmdesc)
{
SCSIDevice *s = pv;
- SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus);
+ SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, qdev_get_parent_bus(DEVICE(s)));
SCSIRequest *req;
QTAILQ_FOREACH(req, &s->requests, next) {
@@ -1726,7 +1726,7 @@ static int get_scsi_requests(QEMUFile *f, void *pv, size_t size,
const VMStateField *field)
{
SCSIDevice *s = pv;
- SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus);
+ SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, qdev_get_parent_bus(DEVICE(s)));
int8_t sbyte;
while ((sbyte = qemu_get_sbyte(f)) > 0) {include/hw/scsi/scsi.h +1 -1
@@ -177,7 +177,7 @@ static inline void scsi_bus_init(SCSIBus *bus, size_t bus_size,static inline SCSIBus *scsi_bus_from_device (SCSIDevice *d) { -return DO_UPCAST (SCSIBus, qbus, d->qdev.parent_bus); +return DO_UPCAST (SCSIBus, qbus,qdev_get_parent_bus (DEVICE (d))); } SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk,
include/hw/usb.h +1 -1
@@ -520,7 +520,7 @@ void usb_check_attach(USBDevice *dev, Error **errp);static inline USBBus *usb_bus_from_device (USBDevice *d) { -return DO_UPCAST (USBBus, qbus, d->qdev.parent_bus); +return DO_UPCAST (USBBus, qbus,qdev_get_parent_bus (DEVICE (d))); }extern const VMStateDescription vmstate_usb_device;
---
Richard Henderson
Acked-byRe: [PATCH 2/4] hw: Replace dev->parent_bus by qdev_get_parent_bus(dev)
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé
DeviceState::parent_busis an internal field and should be accessed by theqdev_get_parent_bus()helper. Replace all uses in hw/ except the QDev uses in hw/core/.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/audio/intel-hda.c | 2 +- hw/block/fdc.c | 2 +- hw/block/swim.c | 2 +- hw/ide/qdev.c | 4 ++-- hw/net/virtio-net.c | 2 +-hw/pci-bridge/pci_expander_bridge.c| 2 +- hw/scsi/scsi-bus.c | 2 +- hw/usb/bus.c | 2 +- hw/usb/desc.c | 2 +- hw/usb/dev-smartcard-reader.c | 16 ++++++++--------Quoted 1 line
10 files changed, 18 insertions(+), 18 deletions(-)
Quoted 1 line
I missed:
Did you use a temporary rename of the field to catch all the uses?
Quoted 4 lines
void
hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response){
- HDACodecBus *bus =HDA_BUS(dev->qdev.parent_bus);
+ HDACodecBus *bus = HDA_BUS(qdev_get_parent_bus(DEVICE(dev)));
I'm never sure the cast is clearer than &dev->qdev. But it seems the normal way in qemu...
r~
Re: [PATCH 2/4] hw: Replace dev->parent_bus by qdev_get_parent_bus(dev)
Quoted 20 lines · Richard Henderson
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé
DeviceState::parent_busis an internal field and should be accessed by theqdev_get_parent_bus()helper. Replace all uses in hw/ except the QDev uses in hw/core/.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/audio/intel-hda.c | 2 +- hw/block/fdc.c | 2 +- hw/block/swim.c | 2 +- hw/ide/qdev.c | 4 ++-- hw/net/virtio-net.c | 2 +-hw/pci-bridge/pci_expander_bridge.c| 2 +- hw/scsi/scsi-bus.c | 2 +- hw/usb/bus.c | 2 +- hw/usb/desc.c | 2 +- hw/usb/dev-smartcard-reader.c | 16 ++++++++--------10 files changed, 18 insertions(+), 18 deletions(-)
Quoted 3 lines
Quoted 1 line
I missed:
Did you use a temporary rename of the field to catch all the uses?
No, git-grep. Good idea.
Quoted 6 lines
Quoted 4 lines
void
hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response){
- HDACodecBus *bus =HDA_BUS(dev->qdev.parent_bus);
+ HDACodecBus *bus = HDA_BUS(qdev_get_parent_bus(DEVICE(dev)));I'm never sure the cast is clearer than
&dev->qdev.
Maybe this one isn't obvious, but see for QOM macros use:
https://lore.kernel.org/qemu-devel/[email protected]/:
- vcdev->vdev.dev = &vcdev->cdev.parent_obj.parent_obj;
+ vcdev->vdev.dev = DEVICE(vcdev);
We should agree on how we want to use this API. If the DeviceState::parent_bus field isn't considered internal, the we should remove the qdev_get_parent_bus() helper which is simply:
hw/core/qdev.c:333:BusState *qdev_get_parent_bus(DeviceState *dev) hw/core/qdev.c-334-{
hw/core/qdev.c-335- return dev->parent_bus;
hw/core/qdev.c-336-}
Note the alternate series expanding QDev macros:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 3 lines
But it seems the normal way in qemu...
Thanks!
PATCH 3/4 hw: Use qdev_get_parent_bus() in qdev_get_own_fw_dev_path_from_handler()
In reply to Philippe Mathieu-DaudéNo need to pass 'dev' and 'dev->parent_bus' when we can retrieve 'parent_bus' with qdev_get_parent_bus().
--- hw/core/qdev-fw.c | 9 +++++---- include/hw/qdev-core.h | 2 +- softmmu/bootdevice.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-)
hw/core/qdev-fw.c +5 -4
@@ -41,9 +41,10 @@ static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev)return NULL ; } -static char *qdev_get_fw_dev_path_from_handler (BusState *bus,DeviceState *dev) +static char *qdev_get_fw_dev_path_from_handler (DeviceState *dev) {Object *obj =OBJECT (dev); +BusState *bus =qdev_get_parent_bus (dev);char *d =NULL ;while (!d && obj->parent) {
@@ -53,11 +54,11 @@ static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState *dev)return d; } -char *qdev_get_own_fw_dev_path_from_handler (BusState *bus,DeviceState *dev) +char *qdev_get_own_fw_dev_path_from_handler (DeviceState *dev) {Object *obj =OBJECT (dev); -return fw_path_provider_try_get_dev_path (obj, bus, dev); +return fw_path_provider_try_get_dev_path (obj,qdev_get_parent_bus (dev), dev); }static int qdev_get_fw_dev_path_helper (DeviceState *dev,char *p,int size)
@@ -67,7 +68,7 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)if (dev && dev->parent_bus) {char *d; l =qdev_get_fw_dev_path_helper (dev->parent_bus->parent, p, size); - d =qdev_get_fw_dev_path_from_handler (dev->parent_bus, dev); + d =qdev_get_fw_dev_path_from_handler (dev);if (!d) { d =bus_get_fw_dev_path (dev->parent_bus, dev); }
include/hw/qdev-core.h +1 -1
@@ -774,7 +774,7 @@ bool bus_is_in_reset(BusState *bus);BusState *sysbus_get_default (void );char *qdev_get_fw_dev_path (DeviceState *dev); -char *qdev_get_own_fw_dev_path_from_handler (BusState *bus,DeviceState *dev); +char *qdev_get_own_fw_dev_path_from_handler (DeviceState *dev);void device_class_set_props (DeviceClass *dc,Property *props);
softmmu/bootdevice.c +1 -1
@@ -214,7 +214,7 @@ static char *get_boot_device_path(DeviceState *dev, bool ignore_suffixes,if (!ignore_suffixes) {if (dev) { - d =qdev_get_own_fw_dev_path_from_handler (dev->parent_bus, dev); + d =qdev_get_own_fw_dev_path_from_handler (dev);if (d) {assert (!suffix); s = d;
Signature · 1 line
2.38.1
Re: [PATCH 3/4] hw: Use qdev_get_parent_bus() in qdev_get_own_fw_dev_path_from_handler()
hw/core/qdev-fw.c static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev) · line 50
Quoted 8 lines · Philippe Mathieu-Daudé
hw/core/qdev-fw.c +2
-1-static char *qdev_get_fw_dev_path_from_handler (BusState *bus,DeviceState *dev) +static char *qdev_get_fw_dev_path_from_handler (DeviceState *dev) {Object *obj =OBJECT (dev); +BusState *bus =qdev_get_parent_bus (dev);char *d =NULL ;while (!d && obj->parent) {
This is a separate change from...
hw/core/qdev-fw.c static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState *dev) · line 61
Quoted 7 lines
hw/core/qdev-fw.c +2
-2-char *qdev_get_own_fw_dev_path_from_handler (BusState *bus,DeviceState *dev) +char *qdev_get_own_fw_dev_path_from_handler (DeviceState *dev) {Object *obj =OBJECT (dev); -return fw_path_provider_try_get_dev_path (obj, bus, dev); +return fw_path_provider_try_get_dev_path (obj,qdev_get_parent_bus (dev), dev);
... this, which is what $SUBJECT says.
hw/core/qdev-fw.c static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) · line 71
Quoted 6 lines
hw/core/qdev-fw.c +1
-1@@ -67,7 +68,7 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)if (dev && dev->parent_bus) {char *d; l =qdev_get_fw_dev_path_helper (dev->parent_bus->parent, p, size); - d =qdev_get_fw_dev_path_from_handler (dev->parent_bus, dev); + d =qdev_get_fw_dev_path_from_handler (dev);
We've already accessed parent_bus just above
hw/core/qdev-fw.c static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) · line 73
Quoted 2 lines
hw/core/qdev-fw.c +0
-0if (!d) { d =bus_get_fw_dev_path (dev->parent_bus, dev);
... and just below. So, what's the cleanup?
r~
Re: [PATCH 3/4] hw: Use qdev_get_parent_bus() in qdev_get_own_fw_dev_path_from_handler()
Quoted 33 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé
-static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState *dev)
+static char *qdev_get_fw_dev_path_from_handler(DeviceState *dev) {
Object *obj = OBJECT(dev);
+ BusState *bus =qdev_get_parent_bus(dev);
char *d = NULL;
while (!d &&obj->parent) {This is a separate change from...
Quoted 8 lines
-char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev)
+char *qdev_get_own_fw_dev_path_from_handler(DeviceState *dev) {
Object *obj = OBJECT(dev);
- returnfw_path_provider_try_get_dev_path(obj, bus, dev); + returnfw_path_provider_try_get_dev_path(obj, qdev_get_parent_bus(dev), dev);... this, which is what $SUBJECT says.
hw/core/qdev-fw.c static int qdev_get_fw_dev_path_helper(DeviceState · line 72
Quoted 7 lines
hw/core/qdev-fw.c +1
-1@@ -67,7 +68,7 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) if (dev && dev->parent_bus) { char *d; l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size); - d = qdev_get_fw_dev_path_from_handler(dev->parent_bus, dev); + d = qdev_get_fw_dev_path_from_handler(dev);We've already accessed
parent_busjust above
Quoted 4 lines
hw/core/qdev-fw.c static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size) · line 73
Quoted 2 lines
hw/core/qdev-fw.c +0
-0if (!d) { d = bus_get_fw_dev_path(dev->parent_bus, dev);... and just below. So, what's the cleanup?
qdev_get_own_fw_dev_path_from_handler() being a public API, I wanted to clean it to avoid a funny case when it is called with
bus != qdev_get_parent_bus(dev). Maybe I merged 2 patches in one, I'll revisit. Or I can just add assert(bus == qdev_get_parent_bus(dev)) to prove the API is convoluted. I'll reword on before respin.
PATCH 4/4 qdev-monitor: Use qdev_get_parent_bus() in bus_print_dev()
In reply to Philippe Mathieu-DaudéNo need to pass 'dev' and 'dev->parent_bus' when we can retrieve 'parent_bus' with qdev_get_parent_bus().
--- softmmu/qdev-monitor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
softmmu/qdev-monitor.c +3 -3
@@ -770,9 +770,9 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, } } -static void bus_print_dev (BusState *bus,Monitor *mon,DeviceState *dev,int indent) +static void bus_print_dev (Monitor *mon,DeviceState *dev,int indent) { -BusClass *bc =BUS_GET_CLASS (bus); +BusClass *bc =BUS_GET_CLASS (qdev_get_parent_bus (dev));if (bc->print_dev) { bc->print_dev (mon, dev, indent);
@@ -811,7 +811,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)qdev_print_props (mon, dev,DEVICE_CLASS (class)->props_, indent); class =object_class_get_parent (class); }while (class !=object_class_by_name (TYPE_DEVICE )); -bus_print_dev (dev->parent_bus, mon, dev, indent); +bus_print_dev (mon, dev, indent); QLIST_FOREACH(child, &dev->child_bus, sibling) {qbus_print (mon, child, indent); }
Signature · 1 line
2.38.1
Re: [PATCH 4/4] qdev-monitor: Use qdev_get_parent_bus() in bus_print_dev()
Quoted 7 lines · Philippe Mathieu-Daudé
No need to pass 'dev' and '
dev->parent_bus' when we can retrieve 'parent_bus' withqdev_get_parent_bus().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- softmmu/qdev-monitor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
r~
Quoted 26 lines
softmmu/qdev-monitor.c +3
-3@@ -770,9 +770,9 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, } } -static void bus_print_dev (BusState *bus,Monitor *mon,DeviceState *dev,int indent) +static void bus_print_dev (Monitor *mon,DeviceState *dev,int indent) { -BusClass *bc =BUS_GET_CLASS (bus); +BusClass *bc =BUS_GET_CLASS (qdev_get_parent_bus (dev));if (bc->print_dev) { bc->print_dev (mon, dev, indent);@@ -811,7 +811,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)qdev_print_props (mon, dev,DEVICE_CLASS (class)->props_, indent); class =object_class_get_parent (class); }while (class !=object_class_by_name (TYPE_DEVICE )); -bus_print_dev (dev->parent_bus, mon, dev, indent); +bus_print_dev (mon, dev, indent); QLIST_FOREACH(child, &dev->child_bus, sibling) {qbus_print (mon, child, indent); }