main: Match getSubTrees* to GetAncestors pattern
main: Match getSubTrees* to GetAncestors pattern

getSubTrees, getSubTreePaths and GetAncestors have a code snippet that's
very similar. Unify them so that they are easier to read.

For the ret vector being declared further down, it's better practice to
declare variables closer to where it's going to be used since
we wouldn't have needed ret if we error out early.

Tested: The code is only syntatically different. Tested with the
following commit in more depth.

Signed-off-by: Brandon Kim <dbcb4743d083bf663ac612bcd5bbeafe818a4d70@google.com>
Change-Id: Ib449ab4ffab502c801040cf6bce28b30507d8e0b

openbmc/phosphor-objmgr,openbmc/phosphor-objmgr