/* returns: the targetted node offset in the base device tree Negative error code on error  */
static int overlay_get_target(const void *fdt, const void *fdto, int fragment, char const **pathp)
/* returns: the targetted node offset in the base device tree Negative error code on error  */
static int overlay_get_target(const void *fdt, const void *fdto, int fragment, char const **pathp)
{
  uint32_t    phandle;
  const char  *path = NULL;
  int         path_len = 0, ret;
  phandle = overlay_get_target_phandle (fdto, fragment);
  if (phandle == (uint32_t)-1) {
    return -FDT_ERR_BADPHANDLE;
  }
  if (!phandle) {
    path = fdt_getprop (fdto, fragment, "target-path", &path_len);
    if (path) {
      ret = fdt_path_offset (fdt, path);
    } else {
      ret = path_len;
    }
  } else {
    ret = fdt_node_offset_by_phandle (fdt, phandle);
  }
  if ((ret < 0) && (path_len == -FDT_ERR_NOTFOUND)) {
    ret = -FDT_ERR_BADOVERLAY;
  }
  if (ret < 0) {
    return ret;
  }
  if (pathp) {
    *pathp = path ? path : NULL;
  }
  return ret;
}