From: Richard Henderson <richard.henderson@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>, qemu-devel@nongnu.org
Cc: Huacai Chen <chenhuacai@kernel.org>,
Bernhard Beschow <shentey@gmail.com>,
Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: Re: [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link()
Date: Fri, 6 Jan 2023 10:49:57 -0800 [thread overview]
Message-ID: <d55772bf-c87e-20e5-180f-a903d9f9f8b0@linaro.org> (raw)
In-Reply-To: <20230105130710.49264-5-philmd@linaro.org>
On 1/5/23 05:07, Philippe Mathieu-Daudé wrote:
> A QOM object shouldn't poke at another object internals.
>
> Here the PCI host bridge instantiates its PCI function #0
> and sets a reference to itself (so the function can access
> the bridge fields).
>
> Pass this reference with object_property_add_const_link(),
> since the reference won't change during the object lifetime.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/pci-host/bonito.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
> index 80ec424f86..d881c85509 100644
> --- a/hw/pci-host/bonito.c
> +++ b/hw/pci-host/bonito.c
> @@ -656,10 +656,17 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
> static void bonito_pci_realize(PCIDevice *dev, Error **errp)
> {
> PCIBonitoState *s = PCI_BONITO(dev);
> - SysBusDevice *sysbus = SYS_BUS_DEVICE(s->pcihost);
> - PCIHostState *phb = PCI_HOST_BRIDGE(s->pcihost);
> - BonitoState *bs = BONITO_PCI_HOST_BRIDGE(s->pcihost);
> MemoryRegion *pcimem_alias = g_new(MemoryRegion, 1);
> + SysBusDevice *sysbus;
> + PCIHostState *phb;
> + BonitoState *bs;
> + Object *obj;
> +
> + obj = object_property_get_link(OBJECT(dev), "host-bridge", &error_abort);
> + s->pcihost = BONITO_PCI_HOST_BRIDGE(obj);
> + sysbus = SYS_BUS_DEVICE(obj);
> + phb = PCI_HOST_BRIDGE(obj);
> + bs = BONITO_PCI_HOST_BRIDGE(obj);
It would be nice to re-order these so that you only perform the dynamic cast once:
s->pcihost = bs;
Regardless,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
next prev parent reply other threads:[~2023-01-06 18:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 13:07 [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
2023-01-05 13:07 ` [PATCH 1/8] hw/pci-host/bonito: Convert to 3-phase reset Philippe Mathieu-Daudé
2023-01-06 18:43 ` Richard Henderson
2023-01-05 13:07 ` [PATCH 2/8] hw/pci-host/bonito: Use 'bonito_host' for PCI host bridge code Philippe Mathieu-Daudé
2023-01-06 18:43 ` Richard Henderson
2023-01-05 13:07 ` [PATCH 3/8] hw/pci-host/bonito: Use 'bonito_pci' for PCI function #0 code Philippe Mathieu-Daudé
2023-01-06 18:48 ` Richard Henderson
2023-01-05 13:07 ` [PATCH 4/8] hw/pci-host/bonito: Set reference using object_property_add_const_link() Philippe Mathieu-Daudé
2023-01-06 18:49 ` Richard Henderson [this message]
2023-01-05 13:07 ` [PATCH 5/8] hw/pci-host/bonito: Create PCI function #0 in bridge realize() handler Philippe Mathieu-Daudé
2023-01-06 18:57 ` Richard Henderson
2023-01-05 13:07 ` [PATCH 6/8] hw/pci-host/bonito: Sysbus'ify outgoing IRQ Philippe Mathieu-Daudé
2023-01-06 19:14 ` Richard Henderson
2023-01-05 13:07 ` [PATCH 7/8] hw/pci-host/bonito: Declare TYPE_BONITO_PCI_HOST_BRIDGE in header Philippe Mathieu-Daudé
2023-01-06 19:15 ` Richard Henderson
2023-01-05 13:07 ` [PATCH 8/8] hw/mips/fuloong2e: Open code bonito_init() Philippe Mathieu-Daudé
2023-01-06 19:16 ` Richard Henderson
2023-01-13 8:11 ` [PATCH 0/8] hw/pci-host/bonito: Housekeeping Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d55772bf-c87e-20e5-180f-a903d9f9f8b0@linaro.org \
--to=richard.henderson@linaro.org \
--cc=chenhuacai@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=shentey@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).