boot: Use mempcpy

This commit is contained in:
Jan Janssen
2022-09-07 12:51:16 +02:00
parent aa23f91ed6
commit 515581d66a
4 changed files with 17 additions and 40 deletions
+2 -8
View File
@@ -2416,14 +2416,8 @@ static void config_write_entries_to_variable(Config *config) {
p = buffer = xmalloc(sz);
for (UINTN i = 0; i < config->entry_count; i++) {
UINTN l;
l = strsize16(config->entries[i]->id);
memcpy(p, config->entries[i]->id, l);
p += l;
}
for (UINTN i = 0; i < config->entry_count; i++)
p = mempcpy(p, config->entries[i]->id, strsize16(config->entries[i]->id));
assert(p == buffer + sz);
+5 -10
View File
@@ -116,8 +116,7 @@ static EFI_STATUS pack_cpio_one(
*cpio_buffer = a;
a = (char *) *cpio_buffer + *cpio_buffer_size;
memcpy(a, "070701", 6); /* magic ID */
a += 6;
a = mempcpy(a, "070701", 6); /* magic ID */
a = write_cpio_word(a, (*inode_counter)++); /* inode */
a = write_cpio_word(a, access_mode | 0100000 /* = S_IFREG */); /* mode */
@@ -139,16 +138,14 @@ static EFI_STATUS pack_cpio_one(
a = write_cpio_word(a, target_dir_prefix_size + fname_size + 2); /* fname size */
a = write_cpio_word(a, 0); /* "crc" */
memcpy(a, target_dir_prefix, target_dir_prefix_size);
a += target_dir_prefix_size;
a = mempcpy(a, target_dir_prefix, target_dir_prefix_size);
*(a++) = '/';
a = mangle_filename(a, fname);
/* Pad to next multiple of 4 */
a = pad4(a, *cpio_buffer);
memcpy(a, contents, contents_size);
a += contents_size;
a = mempcpy(a, contents, contents_size);
/* Pad to next multiple of 4 */
a = pad4(a, *cpio_buffer);
@@ -198,8 +195,7 @@ static EFI_STATUS pack_cpio_dir(
*cpio_buffer = a = xrealloc(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
a = (char *) *cpio_buffer + *cpio_buffer_size;
memcpy(a, "070701", 6); /* magic ID */
a += 6;
a = mempcpy(a, "070701", 6); /* magic ID */
a = write_cpio_word(a, (*inode_counter)++); /* inode */
a = write_cpio_word(a, access_mode | 0040000 /* = S_IFDIR */); /* mode */
@@ -215,8 +211,7 @@ static EFI_STATUS pack_cpio_dir(
a = write_cpio_word(a, path_size + 1); /* fname size */
a = write_cpio_word(a, 0); /* "crc" */
memcpy(a, path, path_size + 1);
a += path_size + 1;
a = mempcpy(a, path, path_size + 1);
/* Pad to next multiple of 4 */
a = pad4(a, *cpio_buffer);
+7 -16
View File
@@ -69,8 +69,7 @@ static EFI_STATUS combine_initrd(
/* Order matters, the real initrd must come first, since it might include microcode updates
* which the kernel only looks for in the first cpio archive */
memcpy(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
p += initrd_size;
p = mempcpy(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
pad = ALIGN4(initrd_size) - initrd_size;
if (pad > 0) {
@@ -79,20 +78,12 @@ static EFI_STATUS combine_initrd(
}
}
if (credential_initrd) {
memcpy(p, credential_initrd, credential_initrd_size);
p += credential_initrd_size;
}
if (global_credential_initrd) {
memcpy(p, global_credential_initrd, global_credential_initrd_size);
p += global_credential_initrd_size;
}
if (sysext_initrd) {
memcpy(p, sysext_initrd, sysext_initrd_size);
p += sysext_initrd_size;
}
if (credential_initrd)
p = mempcpy(p, credential_initrd, credential_initrd_size);
if (global_credential_initrd)
p = mempcpy(p, global_credential_initrd, global_credential_initrd_size);
if (sysext_initrd)
p = mempcpy(p, sysext_initrd, sysext_initrd_size);
assert((uint8_t*) PHYSICAL_ADDRESS_TO_POINTER(base) + n == p);
+3 -6
View File
@@ -751,14 +751,11 @@ EFI_STATUS make_file_device_path(EFI_HANDLE device, const char16_t *file, EFI_DE
end_node = NextDevicePathNode(end_node);
size_t file_size = strsize16(file);
size_t dp_size = ((uint8_t *) end_node - (uint8_t *) dp) + END_DEVICE_PATH_LENGTH;
size_t dp_size = (uint8_t *) end_node - (uint8_t *) dp;
/* Make a copy that can also hold a file media device path. */
*ret_dp = xmalloc(dp_size + file_size + SIZE_OF_FILEPATH_DEVICE_PATH);
memcpy(*ret_dp, dp, dp_size);
/* Point dp to the end node of the copied device path. */
dp = (EFI_DEVICE_PATH *) ((uint8_t *) *ret_dp + dp_size - END_DEVICE_PATH_LENGTH);
*ret_dp = xmalloc(dp_size + file_size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
dp = mempcpy(*ret_dp, dp, dp_size);
/* Replace end node with file media device path. */
FILEPATH_DEVICE_PATH *file_dp = (FILEPATH_DEVICE_PATH *) dp;