summaryrefslogtreecommitdiff
path: root/src/boot
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2023-01-07 11:46:41 +0100
committerJan Janssen <medhefgo@web.de>2023-02-22 21:54:11 +0100
commitd755ac62149110ee716f6a9f5da3161144c293af (patch)
tree62169865506f04c15f107ad98a443f4ed8b6fd44 /src/boot
parente6d7dc9ada482e1a7a26197a5bf93714292c7958 (diff)
downloadsystemd-d755ac62149110ee716f6a9f5da3161144c293af.tar.gz
boot: Remove some device path helper macros
In gnu-efi/EDK2 device paths are not marked as packed and instead the Length field is split into 2 bytes. Accessing those requires these helper macros as device paths may be unaligned. Since our own efi headers define device path structs as packed, we can access these directly, making code much more readable.
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/efi/cpio.c2
-rw-r--r--src/boot/efi/device-path-util.c20
-rw-r--r--src/boot/efi/part-discovery.c11
-rw-r--r--src/boot/efi/proto/device-path.h4
4 files changed, 11 insertions, 26 deletions
diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c
index acfefbb001..c53f19b25c 100644
--- a/src/boot/efi/cpio.c
+++ b/src/boot/efi/cpio.c
@@ -312,7 +312,7 @@ static char16_t *get_dropin_dir(const EFI_DEVICE_PATH *file_path) {
/* Make sure we really only got file paths. */
for (const EFI_DEVICE_PATH *node = file_path; !IsDevicePathEnd(node); node = NextDevicePathNode(node))
- if (DevicePathType(node) != MEDIA_DEVICE_PATH || DevicePathSubType(node) != MEDIA_FILEPATH_DP)
+ if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_FILEPATH_DP)
return NULL;
_cleanup_free_ char16_t *file_path_str = NULL;
diff --git a/src/boot/efi/device-path-util.c b/src/boot/efi/device-path-util.c
index 4e0b3db611..a693c3f296 100644
--- a/src/boot/efi/device-path-util.c
+++ b/src/boot/efi/device-path-util.c
@@ -55,11 +55,10 @@ EFI_STATUS device_path_to_str(const EFI_DEVICE_PATH *dp, char16_t **ret) {
for (const EFI_DEVICE_PATH *node = dp; !IsDevicePathEnd(node);
node = NextDevicePathNode(node)) {
- if (DevicePathType(node) != MEDIA_DEVICE_PATH ||
- DevicePathSubType(node) != MEDIA_FILEPATH_DP)
+ if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_FILEPATH_DP)
return err;
- size_t path_size = DevicePathNodeLength(node);
+ size_t path_size = node->Length;
if (path_size <= offsetof(FILEPATH_DEVICE_PATH, PathName) || path_size % sizeof(char16_t))
return EFI_INVALID_PARAMETER;
path_size -= offsetof(FILEPATH_DEVICE_PATH, PathName);
@@ -99,11 +98,9 @@ bool device_path_startswith(const EFI_DEVICE_PATH *dp, const EFI_DEVICE_PATH *st
return true;
if (IsDevicePathEnd(dp))
return false;
- size_t l1 = DevicePathNodeLength(start);
- size_t l2 = DevicePathNodeLength(dp);
- if (l1 != l2)
+ if (start->Length != dp->Length)
return false;
- if (memcmp(dp, start, l1) != 0)
+ if (memcmp(dp, start, start->Length) != 0)
return false;
start = NextDevicePathNode(start);
dp = NextDevicePathNode(dp);
@@ -119,15 +116,12 @@ EFI_DEVICE_PATH *device_path_replace_node(
assert(path);
assert(node);
- size_t len = (uint8_t *) node - (uint8_t *) path, new_node_len = 0;
- if (new_node)
- new_node_len = DevicePathNodeLength(new_node);
-
- EFI_DEVICE_PATH *ret = xmalloc(len + new_node_len + sizeof(EFI_DEVICE_PATH));
+ size_t len = (uint8_t *) node - (uint8_t *) path;
+ EFI_DEVICE_PATH *ret = xmalloc(len + (new_node ? new_node->Length : 0) + sizeof(EFI_DEVICE_PATH));
EFI_DEVICE_PATH *end = mempcpy(ret, path, len);
if (new_node)
- end = mempcpy(end, new_node, new_node_len);
+ end = mempcpy(end, new_node, new_node->Length);
SetDevicePathEndNode(end);
return ret;
diff --git a/src/boot/efi/part-discovery.c b/src/boot/efi/part-discovery.c
index e71daf0382..2524eb6fd0 100644
--- a/src/boot/efi/part-discovery.c
+++ b/src/boot/efi/part-discovery.c
@@ -166,10 +166,7 @@ static EFI_STATUS find_device(const EFI_GUID *type, EFI_HANDLE *device, EFI_DEVI
/* Find the (last) partition node itself. */
EFI_DEVICE_PATH *part_node = NULL;
for (EFI_DEVICE_PATH *node = partition_path; !IsDevicePathEnd(node); node = NextDevicePathNode(node)) {
- if (DevicePathType(node) != MEDIA_DEVICE_PATH)
- continue;
-
- if (DevicePathSubType(node) != MEDIA_HARDDRIVE_DP)
+ if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_HARDDRIVE_DP)
continue;
part_node = node;
@@ -286,14 +283,12 @@ char16_t *disk_get_part_uuid(EFI_HANDLE *handle) {
return NULL;
for (; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
- if (DevicePathType(dp) != MEDIA_DEVICE_PATH)
- continue;
- if (DevicePathSubType(dp) != MEDIA_HARDDRIVE_DP)
+ if (dp->Type != MEDIA_DEVICE_PATH || dp->SubType != MEDIA_HARDDRIVE_DP)
continue;
/* The HD device path may be misaligned. */
HARDDRIVE_DEVICE_PATH hd;
- memcpy(&hd, dp, MIN(sizeof(hd), (size_t) DevicePathNodeLength(dp)));
+ memcpy(&hd, dp, MIN(sizeof(hd), dp->Length));
if (hd.SignatureType != SIGNATURE_TYPE_GUID)
continue;
diff --git a/src/boot/efi/proto/device-path.h b/src/boot/efi/proto/device-path.h
index 8d8bd0c3f7..f6583b3697 100644
--- a/src/boot/efi/proto/device-path.h
+++ b/src/boot/efi/proto/device-path.h
@@ -82,10 +82,6 @@ typedef struct {
const char16_t *ConvertTextToDevicPath);
} EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL;
-#define DevicePathType(dp) ((dp)->Type)
-#define DevicePathSubType(dp) ((dp)->SubType)
-#define DevicePathNodeLength(dp) ((dp)->Length)
-
static inline EFI_DEVICE_PATH *NextDevicePathNode(const EFI_DEVICE_PATH *dp) {
assert(dp);
return (EFI_DEVICE_PATH *) ((uint8_t *) dp + dp->Length);