aboutsummaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_device_path.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/efi_loader/efi_device_path.c')
-rw-r--r--lib/efi_loader/efi_device_path.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index 50a988c..171661b 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -973,9 +973,22 @@ static void path_to_uefi(void *uefi, const char *src)
*pos = 0;
}
-/*
- * If desc is NULL, this creates a path with only the file component,
- * otherwise it creates a full path with both device and file components
+/**
+ * efi_dp_from_file() - create device path for file
+ *
+ * The function creates a device path from the block descriptor @desc and the
+ * partition number @part and appends a device path node created describing the
+ * file path @path.
+ *
+ * If @desc is NULL, the device path will not contain nodes describing the
+ * partition.
+ * If @path is an empty string "", the device path will not contain a node
+ * for the file path.
+ *
+ * @desc: block device descriptor or NULL
+ * @part: partition number
+ * @path: file path on partition or ""
+ * Return: device path or NULL in case of an error
*/
struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
const char *path)
@@ -1002,12 +1015,14 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
buf = dp_part_fill(buf, desc, part);
/* add file-path: */
- fp = buf;
- fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
- fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
- fp->dp.length = (u16)fpsize;
- path_to_uefi(fp->str, path);
- buf += fpsize;
+ if (*path) {
+ fp = buf;
+ fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
+ fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
+ fp->dp.length = (u16)fpsize;
+ path_to_uefi(fp->str, path);
+ buf += fpsize;
+ }
*((struct efi_device_path *)buf) = END;