firewire: core: add helper functions to access to fw_device data in fw_node structure
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 8 Sep 2025 01:21:01 +0000 (10:21 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 8 Sep 2025 01:26:26 +0000 (10:26 +0900)
The data mbmer in fw_node structure is an opaque pointer, while nowadays
it is just used to refer to fw_device associated with the fw_node.

This commit redefines the opaque pointer to a pointer to fw_device
structure, and adds some helper functions to set/get it.

Link: https://lore.kernel.org/r/20250908012108.514698-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/core-card.c
drivers/firewire/core-device.c
drivers/firewire/core.h

index 41902dc..4a4210c 100644 (file)
@@ -307,12 +307,12 @@ static void bm_work(struct work_struct *work)
        generation = card->generation;
 
        root_node = fw_node_get(card->root_node);
-       root_device = root_node->data;
+       root_device = fw_node_get_device(root_node);
        root_device_is_running = root_device &&
                        atomic_read(&root_device->state) == FW_DEVICE_RUNNING;
        root_device_is_cmc = root_device && root_device->cmc;
 
-       irm_device = card->irm_node->data;
+       irm_device = fw_node_get_device(card->irm_node);
        irm_is_1394_1995_only = irm_device && irm_device->config_rom &&
                        (irm_device->config_rom[2] & 0x000000f0) == 0;
 
index aeacd4c..6a04a00 100644 (file)
@@ -887,7 +887,7 @@ static void fw_device_release(struct device *dev)
         * bus manager work looks at this node.
         */
        scoped_guard(spinlock_irqsave, &card->lock)
-               device->node->data = NULL;
+               fw_node_set_device(device->node, NULL);
 
        fw_node_put(device->node);
        kfree(device->config_rom);
@@ -1007,7 +1007,7 @@ static void fw_device_init(struct work_struct *work)
        int ret;
 
        /*
-        * All failure paths here set node->data to NULL, so that we
+        * All failure paths here call fw_node_set_device(node, NULL), so that we
         * don't try to do device_for_each_child() on a kfree()'d
         * device.
         */
@@ -1051,9 +1051,9 @@ static void fw_device_init(struct work_struct *work)
                                struct fw_node *obsolete_node = reused->node;
 
                                device->node = obsolete_node;
-                               device->node->data = device;
+                               fw_node_set_device(device->node, device);
                                reused->node = current_node;
-                               reused->node->data = reused;
+                               fw_node_set_device(reused->node, reused);
 
                                reused->max_speed = device->max_speed;
                                reused->node_id = current_node->node_id;
@@ -1292,7 +1292,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
                 * FW_NODE_UPDATED callbacks can update the node_id
                 * and generation for the device.
                 */
-               node->data = device;
+               fw_node_set_device(node, device);
 
                /*
                 * Many devices are slow to respond after bus resets,
@@ -1307,7 +1307,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
 
        case FW_NODE_INITIATED_RESET:
        case FW_NODE_LINK_ON:
-               device = node->data;
+               device = fw_node_get_device(node);
                if (device == NULL)
                        goto create;
 
@@ -1324,7 +1324,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
                break;
 
        case FW_NODE_UPDATED:
-               device = node->data;
+               device = fw_node_get_device(node);
                if (device == NULL)
                        break;
 
@@ -1339,7 +1339,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
 
        case FW_NODE_DESTROYED:
        case FW_NODE_LINK_OFF:
-               if (!node->data)
+               if (!fw_node_get_device(node))
                        break;
 
                /*
@@ -1354,7 +1354,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
                 * the device in shutdown state to have that code fail
                 * to create the device.
                 */
-               device = node->data;
+               device = fw_node_get_device(node);
                if (atomic_xchg(&device->state,
                                FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
                        device->workfn = fw_device_shutdown;
index 9b298af..083e390 100644 (file)
@@ -194,8 +194,8 @@ struct fw_node {
        /* For serializing node topology into a list. */
        struct list_head link;
 
-       /* Upper layer specific data. */
-       void *data;
+       // The device when already associated, else NULL.
+       struct fw_device *device;
 
        struct fw_node *ports[] __counted_by(port_count);
 };
@@ -219,6 +219,16 @@ static inline void fw_node_put(struct fw_node *node)
        kref_put(&node->kref, release_node);
 }
 
+static inline struct fw_device *fw_node_get_device(struct fw_node *node)
+{
+       return node->device;
+}
+
+static inline void fw_node_set_device(struct fw_node *node, struct fw_device *device)
+{
+       node->device = device;
+}
+
 void fw_core_handle_bus_reset(struct fw_card *card, int node_id,
        int generation, int self_id_count, u32 *self_ids, bool bm_abdicate);
 void fw_destroy_nodes(struct fw_card *card);