[PATCH 1/5] firewire: cdev: use memory barrier to access fw_device members

From: Takashi Sakamoto

Date: Sun Sep 20 2026 - 03:15:22 EST


The core code uses a read memory barrier when accessing the generation
and node_id members of the fw_device structure. It assumes that the
latest value of the former is visible to a processor core when the latest
value of the latter is visible, since these members are updated in reverse
order with a write memory barrier.

However, the function that fills the fw_cdev_event_bus_reset structure
does not follow this approach. Use a read memory barrier when accessing
these members.
---
drivers/firewire/core-cdev.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index e49d8a58be09..9a3be1ceee2a 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -399,18 +399,21 @@ static ssize_t fw_device_op_read(struct file *file, char __user *buffer,
static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
struct client *client)
{
- struct fw_card *card = client->device->card;
-
- guard(spinlock_irq)(&card->lock);
-
event->closure = client->bus_reset_closure;
event->type = FW_CDEV_EVENT_BUS_RESET;
+
event->generation = client->device->generation;
+ smp_rmb();
event->node_id = client->device->node_id;
- event->local_node_id = card->local_node->node_id;
- event->bm_node_id = card->bm_node_id;
- event->irm_node_id = card->irm_node->node_id;
- event->root_node_id = card->root_node->node_id;
+
+ struct fw_card *card = client->device->card;
+
+ scoped_guard(spinlock_irq, &card->lock) {
+ event->local_node_id = card->local_node->node_id;
+ event->bm_node_id = card->bm_node_id;
+ event->irm_node_id = card->irm_node->node_id;
+ event->root_node_id = card->root_node->node_id;
+ }
}

static void for_each_client(struct fw_device *device,
--
2.53.0