firewire: core: widen fw_node max_depth and max_hops to u8
PATCH 1/1 firewire: core: widen fw_node max_depth and max_hops to u8
In bm_work(), FireWire bus management checks 'root_node->max_hops < ARRAY_SIZE(gap_count_table)' (16) so that IEEE 1394 topologies with 16 or more hops (up to 63 nodes / 62 hops per IEEE 1394a) fall back to expected_gap_count = 63. However, struct fw_node declares max_depth and max_hops as 4-bit unsigned bitfields (0..15). On topologies with >= 16 hops, update_hop_count() truncates max_depth and max_hops modulo 16 (for example 19 hops wraps to 3), causing bm_work() to program a too-small gap count (8 instead of 63) and trigger arbitration failures.
Change max_depth and max_hops from 4-bit bitfields to u8. Because both fields occupy existing alignment padding ahead of struct kref in struct fw_node, sizeof(struct fw_node) is unchanged.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wtautological-value-range-compare enabled; fix and changelog drafted with an AI coding assistant. Verified with an ASan/UBSan C struct-size and 19-hop topology test, and build-tested under LLVM=1 W=1 (-Werror) and -Wtautological-value-range-compare; not tested on physical IEEE 1394 hardware.
--- drivers/firewire/core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firewire/core.h +2 -2
@@ -207,8 +207,8 @@ struct fw_node { u8 phy_speed:2; /* As in the self ID packet. */ u8 max_speed:2; /* Minimum of all phy-speeds on the path from the* local node to this node. */ - u8 max_depth:4; /* Maximum depth to any leaf node */ - u8 max_hops:4; /* Max hops in this sub tree */ +u8 max_depth;/* Maximum depth to any leaf node */ +u8 max_hops;/* Max hops in this sub tree */ struct kref kref;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
Takashi Sakamoto
maintainerHi,
Quoted 20 lines · Ian Rogers
In
bm_work(), FireWire bus management checks 'root_node->max_hops<ARRAY_SIZE(gap_count_table)' (16) so that IEEE 1394 topologies with 16 or more hops (up to 63 nodes / 62 hops per IEEE 1394a) fall back toexpected_gap_count= 63. However, structfw_nodedeclaresmax_depthandmax_hopsas 4-bit unsigned bitfields (0..15). On topologies with >= 16 hops,update_hop_count()truncatesmax_depthandmax_hopsmodulo 16 (for example 19 hops wraps to 3), causingbm_work()to program a too-small gap count (8 instead of 63) and trigger arbitration failures.Change
max_depthandmax_hopsfrom 4-bit bitfields to u8. Because both fields occupy existing alignment padding ahead of struct kref in structfw_node,sizeof(struct fw_node)is unchanged.Found via an
x86_64LLVM=1 (Clang 21.1.8) allyesconfig audit with -Wtautological-value-range-compare enabled; fix and changelog drafted with an AI coding assistant. Verified with an ASan/UBSan C struct-size and 19-hop topology test, and build-tested under LLVM=1 W=1 (-Werror) and -Wtautological-value-range-compare; not tested on physical IEEE 1394 hardware.
Quoted 5 lines
Fixes 83db801ce8c6 ("firewire: Implement gap count optimization.")Signed-off-by Ian Rogers <[email protected]>--- drivers/firewire/core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
The wrap-around in the 16-hop case is intentional and works correctly: the resulting index is zero, which points to the first entry (63) in gap_count_table in bm_work(). Therefore, we only need to check for hop counts of 17 or greater.
According to the IEEE 1394 specification, the 16-hop limit is derived from the worst-case timing constraints for copper cable media. It is not a general requirement for IEEE 1394 topologies, which can also use other transmission media, such as optical fiber and unshielded twisted pairs.
In practice, most Linux users connect just one device, or two or three at most. IEEE 1394 is now primarily used for peripherals such as legacy audio equipment, rather than as a mass-storage or networking backend.
Moreover, the limited bus bandwidth (400 or 800 Mbps) is itself a
constraint: even a few streaming devices can consume most of the available bandwidth. This makes it difficult to see a practical need for connecting a large number of devices in the first place.
Considering these practical usage patterns, I don't think this patch is justified by realistic use cases. Nevertheless, the change does not increase the size of structure, and removing the bit fields is preferable in itself. I've applied it to for-next.
Quoted 17 lines
drivers/firewire/core.h +2
-2@@ -207,8 +207,8 @@ struct fw_node { u8 phy_speed:2; /* As in the self ID packet. */ u8 max_speed:2; /* Minimum of all phy-speeds on the path from the* local node to this node. */ - u8 max_depth:4; /* Maximum depth to any leaf node */ - u8 max_hops:4; /* Max hops in this sub tree */ +u8 max_depth;/* Maximum depth to any leaf node */ +u8 max_hops;/* Max hops in this sub tree */ struct kref kref;Signature · 1 line
2.56.1.708.g77570a6a1d-goog
Thanks
Takashi Sakamoto