From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Date: Sat, 13 May 2023 08:18:24 +0000 (+0200)
Subject: efi_loader: clean up efi_dp_from_file
X-Git-Tag: v2025.01-rc5-pxa1908~991^2~3
X-Git-Url: http://git.dujemihanovic.xyz/img/static/html/%7B%7B%20%24style.RelPermalink%20%7D%7D?a=commitdiff_plain;h=57806128916e0fcb19d512d12f1f5e65442a1919;p=u-boot.git

efi_loader: clean up efi_dp_from_file

* Improve variable name usage: Use pos instead of buf to indicate the
  current position in a buffer.
* Avoid double assignment in a single code line.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---

diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index c4f0cc23a0..0f58082141 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -1022,7 +1022,7 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
 		const char *path)
 {
 	struct efi_device_path_file_path *fp;
-	void *buf, *start;
+	void *buf, *pos;
 	size_t dpsize = 0, fpsize;
 
 	if (desc)
@@ -1035,26 +1035,28 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
 
 	dpsize += fpsize;
 
-	start = buf = efi_alloc(dpsize + sizeof(END));
+	buf = efi_alloc(dpsize + sizeof(END));
 	if (!buf)
 		return NULL;
 
 	if (desc)
-		buf = dp_part_fill(buf, desc, part);
+		pos = dp_part_fill(buf, desc, part);
+	else
+		pos = buf;
 
 	/* add file-path: */
 	if (*path) {
-		fp = buf;
+		fp = pos;
 		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;
+		pos += fpsize;
 	}
 
-	*((struct efi_device_path *)buf) = END;
+	memcpy(pos, &END, sizeof(END));
 
-	return start;
+	return buf;
 }
 
 struct efi_device_path *efi_dp_from_uart(void)