* [PATCH] firewire: core: widen fw_node max_depth and max_hops to u8
@ 2026-11-19 17:07 Ian Rogers
2026-11-22 10:51 ` Takashi Sakamoto
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2026-11-19 17:07 UTC (permalink / raw)
To: Takashi Sakamoto
Cc: linux1394-devel, linux-kernel, llvm, Elkin Cruz, 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 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.
Fixes: 83db801ce8c6 ("firewire: Implement gap count optimization.")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/firewire/core.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
index 8b49d7480c37..ca2150f75174 100644
--- a/drivers/firewire/core.h
+++ b/drivers/firewire/core.h
@@ -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;
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] firewire: core: widen fw_node max_depth and max_hops to u8
2026-11-19 17:07 [PATCH] firewire: core: widen fw_node max_depth and max_hops to u8 Ian Rogers
@ 2026-11-22 10:51 ` Takashi Sakamoto
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Sakamoto @ 2026-11-22 10:51 UTC (permalink / raw)
To: Ian Rogers; +Cc: linux1394-devel, linux-kernel, llvm, Elkin Cruz
Hi,
On Thu, Nov 19, 2026 at 09:07:47AM -0800, Ian Rogers wrote:
> 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.
>
> Fixes: 83db801ce8c6 ("firewire: Implement gap count optimization.")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> 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.
> diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
> index 8b49d7480c37..ca2150f75174 100644
> --- a/drivers/firewire/core.h
> +++ b/drivers/firewire/core.h
> @@ -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;
>
> --
> 2.56.1.708.g77570a6a1d-goog
Thanks
Takashi Sakamoto
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 10:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:07 [PATCH] firewire: core: widen fw_node max_depth and max_hops to u8 Ian Rogers
2026-11-22 10:51 ` Takashi Sakamoto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®