The purpose of this code is to walk the tree of the devices depth-first. Devices that don't have a parent will never be part of that tree.