[PATCH 10/24] part: Add an accessor for struct disk_partition sys_ind

Simon Glass sjg at chromium.org
Sun Aug 13 16:26:38 CEST 2023


This field is only present when a CONFIG is set. To avoid annoying #ifdefs
in the source code, add an accessor. Update the only usage.

Note that the accessor is optional. It can be omitted if it is known that
the option is enabled.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 boot/bootdev-uclass.c |  7 +++----
 include/part.h        | 12 ++++++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 3f2c8d7153a4..00dc28e623a2 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -184,12 +184,11 @@ int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,
 		if (ret)
 			return log_msg_ret("fs", ret);
 
-		/* Use an #ifdef due to info.sys_ind */
-#ifdef CONFIG_DOS_PARTITION
 		log_debug("%s: Found partition %x type %x fstype %d\n",
-			  blk->name, bflow->part, info.sys_ind,
+			  blk->name, bflow->part,
+			  IS_ENABLED(CONFIG_DOS_PARTITION) ?
+			  disk_partition_sys_ind(&info) : 0,
 			  ret ? -1 : fs_get_type());
-#endif
 		bflow->blk = blk;
 		bflow->state = BOOTFLOWST_FS;
 	}
diff --git a/include/part.h b/include/part.h
index aa96516ba353..c3de317fcce8 100644
--- a/include/part.h
+++ b/include/part.h
@@ -135,6 +135,18 @@ static inline void disk_partition_clr_type_guid(struct disk_partition *info)
 #endif
 }
 
+/* Accessors for struct disk_partition field ->sys_ind */
+extern int __invalid_use_of_disk_partition_sys_ind;
+
+static inline uint disk_partition_sys_ind(const struct disk_partition *info)
+{
+#ifdef CONFIG_DOS_PARTITION
+	return info->sys_ind;
+#else
+	return __invalid_use_of_disk_partition_sys_ind;
+#endif
+}
+
 struct disk_part {
 	int partnum;
 	struct disk_partition gpt_part_info;
-- 
2.41.0.640.ga95def55d0-goog



More information about the U-Boot mailing list