]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firewire: core: use guard macro to maintain properties of fw_card
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 5 Aug 2024 08:54:05 +0000 (17:54 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 5 Aug 2024 08:54:05 +0000 (17:54 +0900)
The core functions uses spinlock in instance of fw_card structure to
protect concurrent access to properties in the instance.

This commit uses guard macro to maintain the spinlock.

Link: https://lore.kernel.org/r/20240805085408.251763-15-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/core-card.c
drivers/firewire/core-cdev.c
drivers/firewire/core-device.c
drivers/firewire/core-iso.c
drivers/firewire/core-topology.c
drivers/firewire/core-transaction.c

index 79a5b19e9d18a4c85fd724c3f9052911c1ec931f..e80b762888fa13d176b74e362e0b3816d557ac51 100644 (file)
@@ -374,11 +374,11 @@ static void bm_work(struct work_struct *work)
 
                bm_id = be32_to_cpu(transaction_data[0]);
 
-               spin_lock_irq(&card->lock);
-               if (rcode == RCODE_COMPLETE && generation == card->generation)
-                       card->bm_node_id =
-                           bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
-               spin_unlock_irq(&card->lock);
+               scoped_guard(spinlock_irq, &card->lock) {
+                       if (rcode == RCODE_COMPLETE && generation == card->generation)
+                               card->bm_node_id =
+                                   bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
+               }
 
                if (rcode == RCODE_COMPLETE && bm_id != 0x3f) {
                        /* Somebody else is BM.  Only act as IRM. */
@@ -707,7 +707,6 @@ EXPORT_SYMBOL_GPL(fw_card_release);
 void fw_core_remove_card(struct fw_card *card)
 {
        struct fw_card_driver dummy_driver = dummy_driver_template;
-       unsigned long flags;
 
        card->driver->update_phy_reg(card, 4,
                                     PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
@@ -721,9 +720,8 @@ void fw_core_remove_card(struct fw_card *card)
        dummy_driver.stop_iso           = card->driver->stop_iso;
        card->driver = &dummy_driver;
 
-       spin_lock_irqsave(&card->lock, flags);
-       fw_destroy_nodes(card);
-       spin_unlock_irqrestore(&card->lock, flags);
+       scoped_guard(spinlock_irqsave, &card->lock)
+               fw_destroy_nodes(card);
 
        /* Wait for all users, especially device workqueue jobs, to finish. */
        fw_card_put(card);
index f32f8667ef2c446f58e6665454e7047eec0a142b..672a37fa83435114720aa3d192bfab66901e3b4f 100644 (file)
@@ -354,7 +354,7 @@ static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
 {
        struct fw_card *card = client->device->card;
 
-       spin_lock_irq(&card->lock);
+       guard(spinlock_irq)(&card->lock);
 
        event->closure       = client->bus_reset_closure;
        event->type          = FW_CDEV_EVENT_BUS_RESET;
@@ -364,8 +364,6 @@ static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
        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;
-
-       spin_unlock_irq(&card->lock);
 }
 
 static void for_each_client(struct fw_device *device,
index d695ec2f1efe57f6a5df3db1f8b08b62bd4b7dc5..bec7e05f6ab8ce2415c427e6df390eb5df3a7bc1 100644 (file)
@@ -886,16 +886,14 @@ static void fw_device_release(struct device *dev)
 {
        struct fw_device *device = fw_device(dev);
        struct fw_card *card = device->card;
-       unsigned long flags;
 
        /*
         * Take the card lock so we don't set this to NULL while a
         * FW_NODE_UPDATED callback is being handled or while the
         * bus manager work looks at this node.
         */
-       spin_lock_irqsave(&card->lock, flags);
-       device->node->data = NULL;
-       spin_unlock_irqrestore(&card->lock, flags);
+       scoped_guard(spinlock_irqsave, &card->lock)
+               device->node->data = NULL;
 
        fw_node_put(device->node);
        kfree(device->config_rom);
@@ -952,7 +950,7 @@ static int lookup_existing_device(struct device *dev, void *data)
                return 0;
 
        guard(rwsem_read)(&fw_device_rwsem); // serialize config_rom access
-       spin_lock_irq(&card->lock);  /* serialize node access */
+       guard(spinlock_irq)(&card->lock); // serialize node access
 
        if (memcmp(old->config_rom, new->config_rom, 6 * 4) == 0 &&
            atomic_cmpxchg(&old->state,
@@ -982,8 +980,6 @@ static int lookup_existing_device(struct device *dev, void *data)
                match = 1;
        }
 
-       spin_unlock_irq(&card->lock);
-
        return match;
 }
 
index b3eda38a36f3105092e94a9969466f1d2b6f7de0..101433b8bb51338563b278f02f0cae16f8286f2f 100644 (file)
@@ -375,9 +375,8 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
        u32 channels_lo = channels_mask >> 32;  /* channels 63...32 */
        int irm_id, ret, c = -EINVAL;
 
-       spin_lock_irq(&card->lock);
-       irm_id = card->irm_node->node_id;
-       spin_unlock_irq(&card->lock);
+       scoped_guard(spinlock_irq, &card->lock)
+               irm_id = card->irm_node->node_id;
 
        if (channels_hi)
                c = manage_channel(card, irm_id, generation, channels_hi,
index 46e6eb287d249136b9d18b01cc5b3374ac3cee51..6adadb11962e3d1935695905ebbbb93f422dd175 100644 (file)
@@ -455,11 +455,10 @@ 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)
 {
        struct fw_node *local_node;
-       unsigned long flags;
 
        trace_bus_reset_handle(card->index, generation, node_id, bm_abdicate, self_ids, self_id_count);
 
-       spin_lock_irqsave(&card->lock, flags);
+       guard(spinlock_irqsave)(&card->lock);
 
        /*
         * If the selfID buffer is not the immediate successor of the
@@ -500,7 +499,5 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
        } else {
                update_tree(card, local_node);
        }
-
-       spin_unlock_irqrestore(&card->lock, flags);
 }
 EXPORT_SYMBOL(fw_core_handle_bus_reset);
index 0f58a5d13d28458752b268009251b6e365f87afc..14af84541e83f61e3809611b3a14f07c5eea1e2d 100644 (file)
@@ -1160,7 +1160,6 @@ static void handle_registers(struct fw_card *card, struct fw_request *request,
        int reg = offset & ~CSR_REGISTER_BASE;
        __be32 *data = payload;
        int rcode = RCODE_COMPLETE;
-       unsigned long flags;
 
        switch (reg) {
        case CSR_PRIORITY_BUDGET:
@@ -1202,10 +1201,10 @@ static void handle_registers(struct fw_card *card, struct fw_request *request,
                if (tcode == TCODE_READ_QUADLET_REQUEST) {
                        *data = cpu_to_be32(card->split_timeout_hi);
                } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) {
-                       spin_lock_irqsave(&card->lock, flags);
+                       guard(spinlock_irqsave)(&card->lock);
+
                        card->split_timeout_hi = be32_to_cpu(*data) & 7;
                        update_split_timeout(card);
-                       spin_unlock_irqrestore(&card->lock, flags);
                } else {
                        rcode = RCODE_TYPE_ERROR;
                }
@@ -1215,11 +1214,10 @@ static void handle_registers(struct fw_card *card, struct fw_request *request,
                if (tcode == TCODE_READ_QUADLET_REQUEST) {
                        *data = cpu_to_be32(card->split_timeout_lo);
                } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) {
-                       spin_lock_irqsave(&card->lock, flags);
-                       card->split_timeout_lo =
-                                       be32_to_cpu(*data) & 0xfff80000;
+                       guard(spinlock_irqsave)(&card->lock);
+
+                       card->split_timeout_lo = be32_to_cpu(*data) & 0xfff80000;
                        update_split_timeout(card);
-                       spin_unlock_irqrestore(&card->lock, flags);
                } else {
                        rcode = RCODE_TYPE_ERROR;
                }