/* This function returns the size, in bytes, of the device path data structure specified by DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned. If the length of the device path is bigger than MaxSize, also return 0 to indicate this is an invalidate device path. */
UINTN BmGetDevicePathSizeEx(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN MaxSize)
/* This function returns the size, in bytes, of the device path data structure specified by DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned. If the length of the device path is bigger than MaxSize, also return 0 to indicate this is an invalidate device path. */
UINTN BmGetDevicePathSizeEx(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN MaxSize)
{
  UINTN  Size;
  UINTN  NodeSize;
  if (DevicePath == NULL) {
    return 0;
  }
  Size = 0;
  while (!IsDevicePathEnd (DevicePath)) {
    NodeSize = DevicePathNodeLength (DevicePath);
    if (NodeSize == 0) {
      return 0;
    }
    Size += NodeSize;
    if (Size > MaxSize) {
      return 0;
    }
    DevicePath = NextDevicePathNode (DevicePath);
  }
  Size += DevicePathNodeLength (DevicePath);
  if (Size > MaxSize) {
    return 0;
  }
  return Size;
}