On Tue, Oct 10, 2017 at 02:28:19PM -0400, Stefan Berger wrote: > On 10/09/2017 06:56 PM, Marc-André Lureau wrote: > > + > > +static void tpm_crb_realizefn(DeviceState *dev, Error **errp) > > +{ > > + CRBState *s = CRB(dev); > > + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); > > + > > + if (!tpm_find()) { > > + error_setg(errp, "at most one TPM device is permitted"); > > > Shouldn't that be the case if tpm_find() != NULL ?
It's tricky: due to the way it's implemented (using object_resolve_path_type()) tpm_find() will be able to find @dev itself, because it is already attached to the device tree, but it will return NULL if there are multiple TPM devices. You can see the same pattern being used at find_vmgenid_dev()/vmgenid_realize() and fw_cfg_find()/fw_cfg_common_realize(). The difference is that find_vmgenid_dev() and fw_cfg_find() are explicitly documented with a "returns NULL unless there is exactly one device" comment, while tpm_find() is not. -- Eduardo