Eduardo Habkost <ehabk...@redhat.com> writes: ... >> >> DeviceState *dev, Error **errp) >> >> { >> >> + int idx; >> >> HotplugHandlerClass *hhc; >> >> Error *local_err = NULL; >> >> PCMachineState *pcms = PC_MACHINE(hotplug_dev); >> >> >> >> + pc_find_cpu_slot(pcms, CPU(dev), &idx); >> > >> > Looks fragile: if one day we create any TYPE_CPU object that is >> > not in possible_cpus array, idx is undefined. I suggest >> > initializing idx to -1 above. >> >> Or just let pc_find_cpu_slot universally set it to -1 since >> this series assumes that -1 means index isn't valid. > > I think it would be more intuitive if pc_find_cpu_slot() didn't > touch *idx if no slot is found. But both ways sound good to me.
The caller then has to always take care of making sure there is no bogus value in idx. Maybe, always calling if (pc_find_cpu_slot()) is better.