[PATCH 5/6] thunderbolt: property: Unify parse_dwdata()/format_dwdata()

From: Thomas Weißschuh

Date: Sun May 24 2026 - 09:09:35 EST


Both functions do the same. Unify them.

Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
drivers/thunderbolt/property.c | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c
index 0cdf1c03efc6..961efcec1795 100644
--- a/drivers/thunderbolt/property.c
+++ b/drivers/thunderbolt/property.c
@@ -41,17 +41,12 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block,
size_t block_len, unsigned int dir_offset, size_t dir_len,
bool is_root, unsigned int depth);

-static inline void parse_dwdata(void *dst, const void *src, size_t dwords)
+static inline void convert_dwdata(void *dst, const void *src, size_t dwords)
{
for (size_t i = 0; i < dwords; i++)
((u32 *)dst)[i] = swab32(((u32 *)src)[i]);
}

-static inline void format_dwdata(void *dst, const void *src, size_t dwords)
-{
- return parse_dwdata(dst, src, dwords);
-}
-
static bool tb_property_entry_valid(const struct tb_property_entry *entry,
size_t block_len)
{
@@ -110,7 +105,7 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len,
if (!tb_property_entry_valid(entry, block_len))
return NULL;

- parse_dwdata(key, entry, 2);
+ convert_dwdata(key, entry, 2);
key[TB_PROPERTY_KEY_SIZE] = '\0';

property = tb_property_alloc(key, entry->type);
@@ -139,9 +134,9 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len,
kfree(property);
return NULL;
}
- parse_dwdata(property->value.data,
- block + le32_to_cpu(entry->value),
- le16_to_cpu(entry->length));
+ convert_dwdata(property->value.data,
+ block + le32_to_cpu(entry->value),
+ le16_to_cpu(entry->length));
break;

case TB_PROPERTY_TYPE_TEXT:
@@ -151,9 +146,9 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len,
kfree(property);
return NULL;
}
- parse_dwdata(property->value.text,
- block + le32_to_cpu(entry->value),
- le16_to_cpu(entry->length));
+ convert_dwdata(property->value.text,
+ block + le32_to_cpu(entry->value),
+ le16_to_cpu(entry->length));
/* Force null termination */
property->value.text[property->length * 4 - 1] = '\0';
break;
@@ -452,7 +447,7 @@ static ssize_t __tb_property_format_dir(const struct tb_property_dir *dir,
list_for_each_entry(property, &dir->properties, list) {
const struct tb_property_dir *child;

- format_dwdata(entry, property->key, 2);
+ convert_dwdata(entry, property->key, 2);
entry->type = property->type;

switch (property->type) {
@@ -469,16 +464,16 @@ static ssize_t __tb_property_format_dir(const struct tb_property_dir *dir,
break;

case TB_PROPERTY_TYPE_DATA:
- format_dwdata(&block[data_offset], property->value.data,
- property->length);
+ convert_dwdata(&block[data_offset], property->value.data,
+ property->length);
entry->length = cpu_to_le16(property->length);
entry->value = cpu_to_le32(data_offset);
data_offset += property->length;
break;

case TB_PROPERTY_TYPE_TEXT:
- format_dwdata(&block[data_offset], property->value.text,
- property->length);
+ convert_dwdata(&block[data_offset], property->value.text,
+ property->length);
entry->length = cpu_to_le16(property->length);
entry->value = cpu_to_le32(data_offset);
data_offset += property->length;

--
2.54.0