diff options
author | Rasmus Villemoes <rasmus.villemoes@prevas.dk> | 2020-11-20 11:45:35 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-01-16 12:11:43 -0500 |
commit | 5776e88e8abc14b33fc08c1098527c951c4f4605 (patch) | |
tree | a34aeb9656fbd8c1c3c754ba59d6039899c1c97a | |
parent | 95b1e1d2816542c7b68a109ed18cea77f173765c (diff) | |
download | u-boot-5776e88e8abc14b33fc08c1098527c951c4f4605.zip u-boot-5776e88e8abc14b33fc08c1098527c951c4f4605.tar.gz u-boot-5776e88e8abc14b33fc08c1098527c951c4f4605.tar.bz2 |
lib/uuid.c: change prototype of uuid_guid_get_str()
There's no reason to require an appropriately sized output parameter
for the string, that's error-prone should the table ever grow an
element with a longer string. We can just return the const char*
pointer directly.
Update the only caller accordingly, and get rid of pointless ifdeffery
in the header so that the compiler always sees a declaration and can
thus do type-checking, whether or not PARTITION_TYPE_GUID is enabled
or not.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
-rw-r--r-- | disk/part_efi.c | 9 | ||||
-rw-r--r-- | include/uuid.h | 4 | ||||
-rw-r--r-- | lib/uuid.c | 11 |
3 files changed, 11 insertions, 13 deletions
diff --git a/disk/part_efi.c b/disk/part_efi.c index 60b1c1d7..2f92266 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -247,10 +247,11 @@ void part_print_efi(struct blk_desc *dev_desc) uuid_bin = (unsigned char *)gpt_pte[i].partition_type_guid.b; uuid_bin_to_str(uuid_bin, uuid, UUID_STR_FORMAT_GUID); printf("\ttype:\t%s\n", uuid); -#ifdef CONFIG_PARTITION_TYPE_GUID - if (!uuid_guid_get_str(uuid_bin, uuid)) - printf("\ttype:\t%s\n", uuid); -#endif + if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID)) { + const char *type = uuid_guid_get_str(uuid_bin); + if (type) + printf("\ttype:\t%s\n", type); + } uuid_bin = (unsigned char *)gpt_pte[i].unique_partition_guid.b; uuid_bin_to_str(uuid_bin, uuid, UUID_STR_FORMAT_GUID); printf("\tguid:\t%s\n", uuid); diff --git a/include/uuid.h b/include/uuid.h index 73c5a89..0c653cb 100644 --- a/include/uuid.h +++ b/include/uuid.h @@ -39,10 +39,8 @@ int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin, int str_format); void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str, int str_format); -#ifdef CONFIG_PARTITION_TYPE_GUID int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin); -int uuid_guid_get_str(const unsigned char *guid_bin, char *guid_str); -#endif +const char *uuid_guid_get_str(const unsigned char *guid_bin); void gen_rand_uuid(unsigned char *uuid_bin); void gen_rand_uuid_str(char *uuid_str, int str_format); #endif @@ -122,20 +122,19 @@ int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin) * uuid_guid_get_str() - this function get string for GUID. * * @param guid_bin - pointer to string with partition type guid [16B] - * @param guid_str - pointer to allocated partition type string [7B] + * + * Returns NULL if the type GUID is not known. */ -int uuid_guid_get_str(const unsigned char *guid_bin, char *guid_str) +const char *uuid_guid_get_str(const unsigned char *guid_bin) { int i; - *guid_str = 0; for (i = 0; i < ARRAY_SIZE(list_guid); i++) { if (!memcmp(list_guid[i].guid.b, guid_bin, 16)) { - strcpy(guid_str, list_guid[i].string); - return 0; + return list_guid[i].string; } } - return -ENODEV; + return NULL; } #endif |