* [PATCH 0/4] efi_loader: simplify string handling
@ 2022-04-02 9:46 Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 1/4] lib: convert u16_strlen() into a macro Heinrich Schuchardt
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-04-02 9:46 UTC (permalink / raw)
To: u-boot; +Cc: Heinrich Schuchardt
* convert u16_strlen() into a macro
* use u16_size() instead of u16_strlen() to simplify code
Heinrich Schuchardt (4):
lib: convert u16_strlen() into a macro
lib: simplify u16_strdup()
efi_loader: EFI_HII_STRING_PROTOCOL.GetString()
efi_loader: simplify efi_serialize_load_option()
include/charset.h | 26 ++++++++++++++------------
lib/charset.c | 14 +-------------
lib/efi_loader/efi_hii.c | 2 +-
lib/efi_loader/efi_load_options.c | 2 +-
4 files changed, 17 insertions(+), 27 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] lib: convert u16_strlen() into a macro
2022-04-02 9:46 [PATCH 0/4] efi_loader: simplify string handling Heinrich Schuchardt
@ 2022-04-02 9:46 ` Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 2/4] lib: simplify u16_strdup() Heinrich Schuchardt
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-04-02 9:46 UTC (permalink / raw)
To: u-boot; +Cc: Heinrich Schuchardt
The function u16_strlen() can be implemented as call to u16_strnlen().
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
include/charset.h | 26 ++++++++++++++------------
lib/charset.c | 12 ------------
2 files changed, 14 insertions(+), 24 deletions(-)
diff --git a/include/charset.h b/include/charset.h
index b93d023092..38908e08f0 100644
--- a/include/charset.h
+++ b/include/charset.h
@@ -200,18 +200,6 @@ int u16_strncmp(const u16 *s1, const u16 *s2, size_t n);
*/
#define u16_strcmp(s1, s2) u16_strncmp((s1), (s2), SIZE_MAX)
-/**
- * u16_strlen - count non-zero words
- *
- * This function matches wsclen() if the -fshort-wchar compiler flag is set.
- * In the EFI context we explicitly need a function handling u16 strings.
- *
- * @in: null terminated u16 string
- * Return: number of non-zero words.
- * This is not the number of utf-16 letters!
- */
-size_t u16_strlen(const void *in);
-
/**
* u16_strsize() - count size of u16 string in bytes including the null
* character
@@ -236,6 +224,20 @@ size_t u16_strsize(const void *in);
*/
size_t u16_strnlen(const u16 *in, size_t count);
+/**
+ * u16_strlen - count non-zero words
+ *
+ * This function matches wsclen() if the -fshort-wchar compiler flag is set.
+ * In the EFI context we explicitly need a function handling u16 strings.
+ *
+ * @in: null terminated u16 string
+ * Return: number of non-zero words.
+ * This is not the number of utf-16 letters!
+ */
+size_t u16_strlen(const void *in);
+
+#define u16_strlen(in) u16_strnlen(in, SIZE_MAX)
+
/**
* u16_strcpy() - copy u16 string
*
diff --git a/lib/charset.c b/lib/charset.c
index f44c58d9d8..91cbe87509 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -375,18 +375,6 @@ int u16_strncmp(const u16 *s1, const u16 *s2, size_t n)
return ret;
}
-size_t u16_strlen(const void *in)
-{
- const char *pos = in;
- size_t ret;
-
- for (; pos[0] || pos[1]; pos += 2)
- ;
- ret = pos - (char *)in;
- ret >>= 1;
- return ret;
-}
-
size_t __efi_runtime u16_strnlen(const u16 *in, size_t count)
{
size_t i;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] lib: simplify u16_strdup()
2022-04-02 9:46 [PATCH 0/4] efi_loader: simplify string handling Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 1/4] lib: convert u16_strlen() into a macro Heinrich Schuchardt
@ 2022-04-02 9:46 ` Heinrich Schuchardt
2022-04-02 9:47 ` [PATCH 3/4] efi_loader: EFI_HII_STRING_PROTOCOL.GetString() Heinrich Schuchardt
2022-04-02 9:47 ` [PATCH 4/4] efi_loader: simplify efi_serialize_load_option() Heinrich Schuchardt
3 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-04-02 9:46 UTC (permalink / raw)
To: u-boot; +Cc: Heinrich Schuchardt
Use u16_strsize() instead of duplicating it.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
lib/charset.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/charset.c b/lib/charset.c
index 91cbe87509..de201cf3b9 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -407,7 +407,7 @@ u16 *u16_strdup(const void *src)
if (!src)
return NULL;
- len = (u16_strlen(src) + 1) * sizeof(u16);
+ len = u16_strsize(src);
new = malloc(len);
if (!new)
return NULL;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] efi_loader: EFI_HII_STRING_PROTOCOL.GetString()
2022-04-02 9:46 [PATCH 0/4] efi_loader: simplify string handling Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 1/4] lib: convert u16_strlen() into a macro Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 2/4] lib: simplify u16_strdup() Heinrich Schuchardt
@ 2022-04-02 9:47 ` Heinrich Schuchardt
2022-04-02 9:47 ` [PATCH 4/4] efi_loader: simplify efi_serialize_load_option() Heinrich Schuchardt
3 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-04-02 9:47 UTC (permalink / raw)
To: u-boot; +Cc: Heinrich Schuchardt
Use u16_strsize().
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
lib/efi_loader/efi_hii.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c
index 9f87e95e32..75ff58aafa 100644
--- a/lib/efi_loader/efi_hii.c
+++ b/lib/efi_loader/efi_hii.c
@@ -900,7 +900,7 @@ get_string(const struct efi_hii_string_protocol *this,
str = stbl->strings[string_id - 1].string;
if (str) {
- len = (u16_strlen(str) + 1) * sizeof(u16);
+ len = u16_strsize(str);
if (*string_size < len) {
*string_size = len;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] efi_loader: simplify efi_serialize_load_option()
2022-04-02 9:46 [PATCH 0/4] efi_loader: simplify string handling Heinrich Schuchardt
` (2 preceding siblings ...)
2022-04-02 9:47 ` [PATCH 3/4] efi_loader: EFI_HII_STRING_PROTOCOL.GetString() Heinrich Schuchardt
@ 2022-04-02 9:47 ` Heinrich Schuchardt
3 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-04-02 9:47 UTC (permalink / raw)
To: u-boot; +Cc: Heinrich Schuchardt
Use u16_strsize().
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
lib/efi_loader/efi_load_options.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/efi_loader/efi_load_options.c b/lib/efi_loader/efi_load_options.c
index 68cd85ba2e..71454f0fc6 100644
--- a/lib/efi_loader/efi_load_options.c
+++ b/lib/efi_loader/efi_load_options.c
@@ -113,7 +113,7 @@ unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data)
unsigned long size;
u8 *p;
- label_len = (u16_strlen(lo->label) + 1) * sizeof(u16);
+ label_len = u16_strsize(lo->label);
/* total size */
size = sizeof(lo->attributes);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-02 9:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-02 9:46 [PATCH 0/4] efi_loader: simplify string handling Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 1/4] lib: convert u16_strlen() into a macro Heinrich Schuchardt
2022-04-02 9:46 ` [PATCH 2/4] lib: simplify u16_strdup() Heinrich Schuchardt
2022-04-02 9:47 ` [PATCH 3/4] efi_loader: EFI_HII_STRING_PROTOCOL.GetString() Heinrich Schuchardt
2022-04-02 9:47 ` [PATCH 4/4] efi_loader: simplify efi_serialize_load_option() Heinrich Schuchardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).