* [PATCH 1/6] thunderbolt: test: Make root_directory independent of host byte order
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
@ 2026-05-24 13:06 ` Thomas Weißschuh
2026-05-24 13:06 ` [PATCH 2/6] thunderbolt: property: Unify format_dwdata()/parse_dwdata() Thomas Weißschuh
` (5 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:06 UTC (permalink / raw)
To: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet
Cc: Mika Westerberg, linux-usb, linux-kernel, Yehezkel Bernat,
Thomas Weißschuh
The wire-format is always the same.
Make sure the test data doesn't suddenly change on big-endian systems.
Fixes: 15a4c7e8f916 ("thunderbolt: Add KUnit tests for XDomain properties")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
This is actual an assumption. I didn't find the specs.
---
drivers/thunderbolt/test.c | 106 ++++++++++++++++++++++-----------------------
1 file changed, 53 insertions(+), 53 deletions(-)
diff --git a/drivers/thunderbolt/test.c b/drivers/thunderbolt/test.c
index 1f4318249c22..114ef11cd6f4 100644
--- a/drivers/thunderbolt/test.c
+++ b/drivers/thunderbolt/test.c
@@ -2604,59 +2604,59 @@ static void tb_test_credit_alloc_all(struct kunit *test)
}
static const u32 root_directory[] = {
- 0x55584401, /* "UXD" v1 */
- 0x00000018, /* Root directory length */
- 0x76656e64, /* "vend" */
- 0x6f726964, /* "orid" */
- 0x76000001, /* "v" R 1 */
- 0x00000a27, /* Immediate value, ! Vendor ID */
- 0x76656e64, /* "vend" */
- 0x6f726964, /* "orid" */
- 0x74000003, /* "t" R 3 */
- 0x0000001a, /* Text leaf offset, (“Apple Inc.”) */
- 0x64657669, /* "devi" */
- 0x63656964, /* "ceid" */
- 0x76000001, /* "v" R 1 */
- 0x0000000a, /* Immediate value, ! Device ID */
- 0x64657669, /* "devi" */
- 0x63656964, /* "ceid" */
- 0x74000003, /* "t" R 3 */
- 0x0000001d, /* Text leaf offset, (“Macintosh”) */
- 0x64657669, /* "devi" */
- 0x63657276, /* "cerv" */
- 0x76000001, /* "v" R 1 */
- 0x80000100, /* Immediate value, Device Revision */
- 0x6e657477, /* "netw" */
- 0x6f726b00, /* "ork" */
- 0x44000014, /* "D" R 20 */
- 0x00000021, /* Directory data offset, (Network Directory) */
- 0x4170706c, /* "Appl" */
- 0x6520496e, /* "e In" */
- 0x632e0000, /* "c." ! */
- 0x4d616369, /* "Maci" */
- 0x6e746f73, /* "ntos" */
- 0x68000000, /* "h" */
- 0x00000000, /* padding */
- 0xca8961c6, /* Directory UUID, Network Directory */
- 0x9541ce1c, /* Directory UUID, Network Directory */
- 0x5949b8bd, /* Directory UUID, Network Directory */
- 0x4f5a5f2e, /* Directory UUID, Network Directory */
- 0x70727463, /* "prtc" */
- 0x69640000, /* "id" */
- 0x76000001, /* "v" R 1 */
- 0x00000001, /* Immediate value, Network Protocol ID */
- 0x70727463, /* "prtc" */
- 0x76657273, /* "vers" */
- 0x76000001, /* "v" R 1 */
- 0x00000001, /* Immediate value, Network Protocol Version */
- 0x70727463, /* "prtc" */
- 0x72657673, /* "revs" */
- 0x76000001, /* "v" R 1 */
- 0x00000001, /* Immediate value, Network Protocol Revision */
- 0x70727463, /* "prtc" */
- 0x73746e73, /* "stns" */
- 0x76000001, /* "v" R 1 */
- 0x00000000, /* Immediate value, Network Protocol Settings */
+ le32_to_cpu(0x55584401), /* "UXD" v1 */
+ le32_to_cpu(0x00000018), /* Root directory length */
+ le32_to_cpu(0x76656e64), /* "vend" */
+ le32_to_cpu(0x6f726964), /* "orid" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x00000a27), /* Immediate value, ! Vendor ID */
+ le32_to_cpu(0x76656e64), /* "vend" */
+ le32_to_cpu(0x6f726964), /* "orid" */
+ le32_to_cpu(0x74000003), /* "t" R 3 */
+ le32_to_cpu(0x0000001a), /* Text leaf offset, (“Apple Inc.”) */
+ le32_to_cpu(0x64657669), /* "devi" */
+ le32_to_cpu(0x63656964), /* "ceid" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x0000000a), /* Immediate value, ! Device ID */
+ le32_to_cpu(0x64657669), /* "devi" */
+ le32_to_cpu(0x63656964), /* "ceid" */
+ le32_to_cpu(0x74000003), /* "t" R 3 */
+ le32_to_cpu(0x0000001d), /* Text leaf offset, (“Macintosh”) */
+ le32_to_cpu(0x64657669), /* "devi" */
+ le32_to_cpu(0x63657276), /* "cerv" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x80000100), /* Immediate value, Device Revision */
+ le32_to_cpu(0x6e657477), /* "netw" */
+ le32_to_cpu(0x6f726b00), /* "ork" */
+ le32_to_cpu(0x44000014), /* "D" R 20 */
+ le32_to_cpu(0x00000021), /* Directory data offset, (Network Directory) */
+ le32_to_cpu(0x4170706c), /* "Appl" */
+ le32_to_cpu(0x6520496e), /* "e In" */
+ le32_to_cpu(0x632e0000), /* "c." ! */
+ le32_to_cpu(0x4d616369), /* "Maci" */
+ le32_to_cpu(0x6e746f73), /* "ntos" */
+ le32_to_cpu(0x68000000), /* "h" */
+ le32_to_cpu(0x00000000), /* padding */
+ le32_to_cpu(0xca8961c6), /* Directory UUID, Network Directory */
+ le32_to_cpu(0x9541ce1c), /* Directory UUID, Network Directory */
+ le32_to_cpu(0x5949b8bd), /* Directory UUID, Network Directory */
+ le32_to_cpu(0x4f5a5f2e), /* Directory UUID, Network Directory */
+ le32_to_cpu(0x70727463), /* "prtc" */
+ le32_to_cpu(0x69640000), /* "id" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x00000001), /* Immediate value, Network Protocol ID */
+ le32_to_cpu(0x70727463), /* "prtc" */
+ le32_to_cpu(0x76657273), /* "vers" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x00000001), /* Immediate value, Network Protocol Version */
+ le32_to_cpu(0x70727463), /* "prtc" */
+ le32_to_cpu(0x72657673), /* "revs" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x00000001), /* Immediate value, Network Protocol Revision */
+ le32_to_cpu(0x70727463), /* "prtc" */
+ le32_to_cpu(0x73746e73), /* "stns" */
+ le32_to_cpu(0x76000001), /* "v" R 1 */
+ le32_to_cpu(0x00000000), /* Immediate value, Network Protocol Settings */
};
static const uuid_t network_dir_uuid =
--
2.54.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 2/6] thunderbolt: property: Unify format_dwdata()/parse_dwdata()
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
2026-05-24 13:06 ` [PATCH 1/6] thunderbolt: test: Make root_directory independent of host byte order Thomas Weißschuh
@ 2026-05-24 13:06 ` Thomas Weißschuh
2026-06-03 0:19 ` Andy Shevchenko
2026-05-24 13:06 ` [PATCH 3/6] thunderbolt: property: Make format_dwdata() work on big-endian systems Thomas Weißschuh
` (4 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:06 UTC (permalink / raw)
To: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet
Cc: Mika Westerberg, linux-usb, linux-kernel, Yehezkel Bernat,
Thomas Weißschuh
Both function do the same. They are about to change. To make that
easier, implement one in terms of the other.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/thunderbolt/property.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c
index da2c59a17db5..fb96608ca471 100644
--- a/drivers/thunderbolt/property.c
+++ b/drivers/thunderbolt/property.c
@@ -48,7 +48,7 @@ static inline void parse_dwdata(void *dst, const void *src, size_t dwords)
static inline void format_dwdata(void *dst, const void *src, size_t dwords)
{
- cpu_to_be32_array(dst, src, dwords);
+ return parse_dwdata(dst, src, dwords);
}
static bool tb_property_entry_valid(const struct tb_property_entry *entry,
--
2.54.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 2/6] thunderbolt: property: Unify format_dwdata()/parse_dwdata()
2026-05-24 13:06 ` [PATCH 2/6] thunderbolt: property: Unify format_dwdata()/parse_dwdata() Thomas Weißschuh
@ 2026-06-03 0:19 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2026-06-03 0:19 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Michael Jamet, Mika Westerberg, linux-usb, linux-kernel,
Yehezkel Bernat
On Sun, May 24, 2026 at 03:06:44PM +0200, Thomas Weißschuh wrote:
> Both function do the same. They are about to change. To make that
> easier, implement one in terms of the other.
...
> static inline void format_dwdata(void *dst, const void *src, size_t dwords)
> {
> - cpu_to_be32_array(dst, src, dwords);
> + return parse_dwdata(dst, src, dwords);
Why return?
> }
Can't you simply kill this and use parse_dwdata everywhere?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 3/6] thunderbolt: property: Make format_dwdata() work on big-endian systems
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
2026-05-24 13:06 ` [PATCH 1/6] thunderbolt: test: Make root_directory independent of host byte order Thomas Weißschuh
2026-05-24 13:06 ` [PATCH 2/6] thunderbolt: property: Unify format_dwdata()/parse_dwdata() Thomas Weißschuh
@ 2026-05-24 13:06 ` Thomas Weißschuh
2026-06-03 0:21 ` Andy Shevchenko
2026-05-24 13:06 ` [PATCH 4/6] thunderbolt: property: Convert byte order of numeric fields Thomas Weißschuh
` (3 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:06 UTC (permalink / raw)
To: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet
Cc: Mika Westerberg, linux-usb, linux-kernel, Yehezkel Bernat,
Thomas Weißschuh
The data also needs to be swapped on big-endian systems.
Use swab32() which works independently from the host byte order.
Fixes: cdae7c07e3e3 ("thunderbolt: Add support for XDomain properties")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/thunderbolt/property.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c
index fb96608ca471..94314fa07d23 100644
--- a/drivers/thunderbolt/property.c
+++ b/drivers/thunderbolt/property.c
@@ -43,7 +43,8 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block,
static inline void parse_dwdata(void *dst, const void *src, size_t dwords)
{
- be32_to_cpu_array(dst, src, 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)
--
2.54.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 3/6] thunderbolt: property: Make format_dwdata() work on big-endian systems
2026-05-24 13:06 ` [PATCH 3/6] thunderbolt: property: Make format_dwdata() work on big-endian systems Thomas Weißschuh
@ 2026-06-03 0:21 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2026-06-03 0:21 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Michael Jamet, Mika Westerberg, linux-usb, linux-kernel,
Yehezkel Bernat
On Sun, May 24, 2026 at 03:06:45PM +0200, Thomas Weißschuh wrote:
> The data also needs to be swapped on big-endian systems.
Why?! The good commit message has to explain this kind of changes deeper.
> Use swab32() which works independently from the host byte order.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 4/6] thunderbolt: property: Convert byte order of numeric fields
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
` (2 preceding siblings ...)
2026-05-24 13:06 ` [PATCH 3/6] thunderbolt: property: Make format_dwdata() work on big-endian systems Thomas Weißschuh
@ 2026-05-24 13:06 ` Thomas Weißschuh
2026-05-24 13:06 ` [PATCH 5/6] thunderbolt: property: Unify parse_dwdata()/format_dwdata() Thomas Weißschuh
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:06 UTC (permalink / raw)
To: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet
Cc: Mika Westerberg, linux-usb, linux-kernel, Yehezkel Bernat,
Thomas Weißschuh
On big-endian system the numeric fields need to be converted after
reading them from the wireformat before they can be used.
Add the necessary conversion.
Fixes: cdae7c07e3e3 ("thunderbolt: Add support for XDomain properties")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/thunderbolt/property.c | 72 +++++++++++++++++++++++-------------------
1 file changed, 39 insertions(+), 33 deletions(-)
diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c
index 94314fa07d23..0cdf1c03efc6 100644
--- a/drivers/thunderbolt/property.c
+++ b/drivers/thunderbolt/property.c
@@ -15,17 +15,17 @@
#include <linux/thunderbolt.h>
struct tb_property_entry {
- u32 key_hi;
- u32 key_lo;
- u16 length;
+ __le32 key_hi;
+ __le32 key_lo;
+ __le16 length;
u8 reserved;
u8 type;
- u32 value;
+ __le32 value;
};
struct tb_property_rootdir_entry {
- u32 magic;
- u32 length;
+ __le32 magic;
+ __le32 length;
struct tb_property_entry entries[];
};
@@ -61,15 +61,16 @@ static bool tb_property_entry_valid(const struct tb_property_entry *entry,
case TB_PROPERTY_TYPE_DIRECTORY:
case TB_PROPERTY_TYPE_DATA:
case TB_PROPERTY_TYPE_TEXT:
- if (entry->length > block_len)
+ if (le16_to_cpu(entry->length) > block_len)
return false;
- if (check_add_overflow(entry->value, entry->length, &end) ||
+ if (check_add_overflow(le32_to_cpu(entry->value),
+ le16_to_cpu(entry->length), &end) ||
end > block_len)
return false;
break;
case TB_PROPERTY_TYPE_VALUE:
- if (entry->length != 1)
+ if (le16_to_cpu(entry->length) != 1)
return false;
break;
}
@@ -116,12 +117,14 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len,
if (!property)
return NULL;
- property->length = entry->length;
+ property->length = le16_to_cpu(entry->length);
switch (property->type) {
case TB_PROPERTY_TYPE_DIRECTORY:
- dir = __tb_property_parse_dir(block, block_len, entry->value,
- entry->length, false, depth + 1);
+ dir = __tb_property_parse_dir(block, block_len,
+ le32_to_cpu(entry->value),
+ le16_to_cpu(entry->length),
+ false, depth + 1);
if (!dir) {
kfree(property);
return NULL;
@@ -136,8 +139,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 + entry->value,
- entry->length);
+ parse_dwdata(property->value.data,
+ block + le32_to_cpu(entry->value),
+ le16_to_cpu(entry->length));
break;
case TB_PROPERTY_TYPE_TEXT:
@@ -147,14 +151,15 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len,
kfree(property);
return NULL;
}
- parse_dwdata(property->value.text, block + entry->value,
- entry->length);
+ parse_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;
case TB_PROPERTY_TYPE_VALUE:
- property->value.immediate = entry->value;
+ property->value.immediate = le32_to_cpu(entry->value);
break;
default:
@@ -240,12 +245,13 @@ struct tb_property_dir *tb_property_parse_dir(const u32 *block,
const struct tb_property_rootdir_entry *rootdir =
(const struct tb_property_rootdir_entry *)block;
- if (rootdir->magic != TB_PROPERTY_ROOTDIR_MAGIC)
+ if (le32_to_cpu(rootdir->magic) != TB_PROPERTY_ROOTDIR_MAGIC)
return NULL;
- if (rootdir->length > block_len)
+ if (le32_to_cpu(rootdir->length) > block_len)
return NULL;
- return __tb_property_parse_dir(block, block_len, 0, rootdir->length,
+ return __tb_property_parse_dir(block, block_len, 0,
+ le32_to_cpu(rootdir->length),
true, 0);
}
@@ -438,8 +444,8 @@ static ssize_t __tb_property_format_dir(const struct tb_property_dir *dir,
struct tb_property_rootdir_entry *re;
re = (struct tb_property_rootdir_entry *)&block[start_offset];
- re->magic = TB_PROPERTY_ROOTDIR_MAGIC;
- re->length = dir_len - sizeof(*re) / 4;
+ re->magic = cpu_to_le32(TB_PROPERTY_ROOTDIR_MAGIC);
+ re->length = cpu_to_le32(dir_len - sizeof(*re) / 4);
entry = re->entries;
}
@@ -456,31 +462,31 @@ static ssize_t __tb_property_format_dir(const struct tb_property_dir *dir,
block_len);
if (ret < 0)
return ret;
- entry->length = tb_property_dir_length(child, false,
- NULL);
- entry->value = dir_end;
+ entry->length = cpu_to_le16(
+ tb_property_dir_length(child, false, NULL));
+ entry->value = cpu_to_le32(dir_end);
dir_end = ret;
break;
case TB_PROPERTY_TYPE_DATA:
format_dwdata(&block[data_offset], property->value.data,
property->length);
- entry->length = property->length;
- entry->value = data_offset;
- data_offset += entry->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);
- entry->length = property->length;
- entry->value = data_offset;
- data_offset += entry->length;
+ entry->length = cpu_to_le16(property->length);
+ entry->value = cpu_to_le32(data_offset);
+ data_offset += property->length;
break;
case TB_PROPERTY_TYPE_VALUE:
- entry->length = property->length;
- entry->value = property->value.immediate;
+ entry->length = cpu_to_le16(property->length);
+ entry->value = cpu_to_le32(property->value.immediate);
break;
default:
--
2.54.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 5/6] thunderbolt: property: Unify parse_dwdata()/format_dwdata()
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
` (3 preceding siblings ...)
2026-05-24 13:06 ` [PATCH 4/6] thunderbolt: property: Convert byte order of numeric fields Thomas Weißschuh
@ 2026-05-24 13:06 ` Thomas Weißschuh
2026-06-03 0:23 ` Andy Shevchenko
2026-05-24 13:06 ` [PATCH 6/6] thunderbolt: property: Make entry key modifications more visible Thomas Weißschuh
2026-05-25 9:35 ` [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Mika Westerberg
6 siblings, 1 reply; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:06 UTC (permalink / raw)
To: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet
Cc: Mika Westerberg, linux-usb, linux-kernel, Yehezkel Bernat,
Thomas Weißschuh
Both functions do the same. Unify them.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
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
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 5/6] thunderbolt: property: Unify parse_dwdata()/format_dwdata()
2026-05-24 13:06 ` [PATCH 5/6] thunderbolt: property: Unify parse_dwdata()/format_dwdata() Thomas Weißschuh
@ 2026-06-03 0:23 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2026-06-03 0:23 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Michael Jamet, Mika Westerberg, linux-usb, linux-kernel,
Yehezkel Bernat
On Sun, May 24, 2026 at 03:06:47PM +0200, Thomas Weißschuh wrote:
> Both functions do the same. Unify them.
This what the first patch should do, without any additional dances.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 6/6] thunderbolt: property: Make entry key modifications more visible
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
` (4 preceding siblings ...)
2026-05-24 13:06 ` [PATCH 5/6] thunderbolt: property: Unify parse_dwdata()/format_dwdata() Thomas Weißschuh
@ 2026-05-24 13:06 ` Thomas Weißschuh
2026-06-03 0:25 ` Andy Shevchenko
2026-05-25 9:35 ` [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Mika Westerberg
6 siblings, 1 reply; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-24 13:06 UTC (permalink / raw)
To: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet
Cc: Mika Westerberg, linux-usb, linux-kernel, Yehezkel Bernat,
Thomas Weißschuh
The modification of the key directly through the entry pointer is
confusing. Explicitly use the key member.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/thunderbolt/property.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c
index 961efcec1795..885a8da7e72f 100644
--- a/drivers/thunderbolt/property.c
+++ b/drivers/thunderbolt/property.c
@@ -15,8 +15,7 @@
#include <linux/thunderbolt.h>
struct tb_property_entry {
- __le32 key_hi;
- __le32 key_lo;
+ u8 key[TB_PROPERTY_KEY_SIZE];
__le16 length;
u8 reserved;
u8 type;
@@ -105,7 +104,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;
- convert_dwdata(key, entry, 2);
+ convert_dwdata(key, &entry->key, 2);
key[TB_PROPERTY_KEY_SIZE] = '\0';
property = tb_property_alloc(key, entry->type);
@@ -447,7 +446,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;
- convert_dwdata(entry, property->key, 2);
+ convert_dwdata(&entry->key, property->key, 2);
entry->type = property->type;
switch (property->type) {
--
2.54.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 6/6] thunderbolt: property: Make entry key modifications more visible
2026-05-24 13:06 ` [PATCH 6/6] thunderbolt: property: Make entry key modifications more visible Thomas Weißschuh
@ 2026-06-03 0:25 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2026-06-03 0:25 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Michael Jamet, Mika Westerberg, linux-usb, linux-kernel,
Yehezkel Bernat
On Sun, May 24, 2026 at 03:06:48PM +0200, Thomas Weißschuh wrote:
> The modification of the key directly through the entry pointer is
> confusing. Explicitly use the key member.
...
> struct tb_property_entry {
> - __le32 key_hi;
> - __le32 key_lo;
> + u8 key[TB_PROPERTY_KEY_SIZE];
> __le16 length;
> u8 reserved;
> u8 type;
> if (!tb_property_entry_valid(entry, block_len))
> return NULL;
>
> - convert_dwdata(key, entry, 2);
> + convert_dwdata(key, &entry->key, 2);
> key[TB_PROPERTY_KEY_SIZE] = '\0';
>
> property = tb_property_alloc(key, entry->type);
> list_for_each_entry(property, &dir->properties, list) {
> const struct tb_property_dir *child;
>
> - convert_dwdata(entry, property->key, 2);
> + convert_dwdata(&entry->key, property->key, 2);
In such case this should use the get_unaligned_le64() or le64_to_cpu() rather
than this strange thing...
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian
2026-05-24 13:06 [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Thomas Weißschuh
` (5 preceding siblings ...)
2026-05-24 13:06 ` [PATCH 6/6] thunderbolt: property: Make entry key modifications more visible Thomas Weißschuh
@ 2026-05-25 9:35 ` Mika Westerberg
2026-05-25 10:32 ` Thomas Weißschuh
6 siblings, 1 reply; 13+ messages in thread
From: Mika Westerberg @ 2026-05-25 9:35 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet, linux-usb, linux-kernel,
Yehezkel Bernat
Hi,
On Sun, May 24, 2026 at 03:06:42PM +0200, Thomas Weißschuh wrote:
> The parsing logic currently only works on little-endian.
> Also make it work on big-endian.
I'm all in making it more portable. Do you have big-endian hardware with
USB4 support or you are just doing so to cover some future hardware? Also
how did you test this?
> The first four patches are necessary to make the parsing work on
> big-endian machines. The remaining ones are some trivial cleanups.
>
> Based on thunderbolt/fixes.
I suggest basing on my next branch because these are really not
regressions, rather you are "improving" the code (and I prefer to keep
these longer in linux-next so that we could catch any unintended
side-effects).
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Thomas Weißschuh (6):
> thunderbolt: test: Make root_directory independent of host byte order
> thunderbolt: property: Unify format_dwdata()/parse_dwdata()
> thunderbolt: property: Make format_dwdata() work on big-endian systems
> thunderbolt: property: Convert byte order of numeric fields
> thunderbolt: property: Unify parse_dwdata()/format_dwdata()
> thunderbolt: property: Make entry key modifications more visible
>
> drivers/thunderbolt/property.c | 93 ++++++++++++++++++------------------
> drivers/thunderbolt/test.c | 106 ++++++++++++++++++++---------------------
> 2 files changed, 100 insertions(+), 99 deletions(-)
> ---
> base-commit: 6ff00aaa856d16015e5bafbcf89e3998fd4a7c2b
> change-id: 20260524-thunderbolt-big-endian-9f012cfc062b
>
> Best regards,
> --
> Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian
2026-05-25 9:35 ` [PATCH 0/6] thunderbolt: property: Fix property parsing on big-endian Mika Westerberg
@ 2026-05-25 10:32 ` Thomas Weißschuh
0 siblings, 0 replies; 13+ messages in thread
From: Thomas Weißschuh @ 2026-05-25 10:32 UTC (permalink / raw)
To: Mika Westerberg
Cc: Andreas Noever, Mika Westerberg, Yehezkel Bernat, David S. Miller,
Andy Shevchenko, Michael Jamet, linux-usb, linux-kernel,
Yehezkel Bernat
Hi Mika,
On 2026-05-25 11:35:29+0200, Mika Westerberg wrote:
> On Sun, May 24, 2026 at 03:06:42PM +0200, Thomas Weißschuh wrote:
> > The parsing logic currently only works on little-endian.
> > Also make it work on big-endian.
>
> I'm all in making it more portable. Do you have big-endian hardware with
> USB4 support or you are just doing so to cover some future hardware? Also
> how did you test this?
This came up while doing some KUnit runs. I don't have any hardware for
it. I also only tested it with KUnit.
> > The first four patches are necessary to make the parsing work on
> > big-endian machines. The remaining ones are some trivial cleanups.
> >
> > Based on thunderbolt/fixes.
>
> I suggest basing on my next branch because these are really not
> regressions, rather you are "improving" the code (and I prefer to keep
> these longer in linux-next so that we could catch any unintended
> side-effects).
Ack. There will be some conflicts between my series, thunderbolt/fixes
and thunderbolt/next. I'll resubmit the patches after -rc1, where these
should have resolved themselves.
Thomas
^ permalink raw reply [flat|nested] 13+ messages in thread