def METHOD_NAME(data):
    """Convert a tree of resources or drivers to a named list.
    When using named resources or drivers, the config file uses a list of
    dicts instead of simply nested dicts. This allows creating multiple
    instances of the same class with different names.
    resources: # or drivers
      FooPort: {}
      BarPort:
        name: "bar"
    or
    resources: # or drivers
    - FooPort: {}
    - BarPort:
        name: "bar"
    should be transformed to
    resources: # or drivers
    - cls: "FooPort"
    - cls: "BarPort"
      name: "bar"
    """
    # resolve syntactic sugar (list of dicts each containing a dict of key -> args)
    result = []
    if isinstance(data, list):
        for item in data:
            if not isinstance(item, dict):
                raise InvalidConfigError(
                    f"invalid list item type {type(item)} (should be dict)")
            if not item:
                raise InvalidConfigError("invalid empty dict as list item")
            if len(item) > 1:
                if 'cls' in item:
                    item = item.copy()
                else:
                    raise InvalidConfigError(f"missing 'cls' key in {item}")
            else:
                # only one pair left
                (key, value), = item.items()
                if key == 'cls':
                    item = item.copy()
                else:
                    item = {'cls':  key}
                    if value is None:
                        raise InvalidConfigError("invalid list item, add empty dict for no arguments")  # pylint: disable=line-too-long
                    item.update(value)
            result.append(item)
    elif isinstance(data, dict):
        for cls, args in data.items():
            args = args.copy()
            args.setdefault('cls', cls)
            result.append(args)
    else:
        raise InvalidConfigError(f"invalid type {type(data)} (should be dict or list)")
    for item in result:
        item.setdefault('name', None)
        assert 'cls' in item
    return result