Commit 27310d56 authored by Takashi Sakamoto's avatar Takashi Sakamoto
Browse files

firewire: core: use guard macro to maintain properties of fw_card

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: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
parent d320bac9
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -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);
		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;
		spin_unlock_irq(&card->lock);
		}

		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);
	scoped_guard(spinlock_irqsave, &card->lock)
		fw_destroy_nodes(card);
	spin_unlock_irqrestore(&card->lock, flags);

	/* Wait for all users, especially device workqueue jobs, to finish. */
	fw_card_put(card);
+1 −3
Original line number Diff line number Diff line
@@ -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,
+3 −7
Original line number Diff line number Diff line
@@ -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);
	scoped_guard(spinlock_irqsave, &card->lock)
		device->node->data = NULL;
	spin_unlock_irqrestore(&card->lock, flags);

	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;
}

+2 −3
Original line number Diff line number Diff line
@@ -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);
	scoped_guard(spinlock_irq, &card->lock)
		irm_id = card->irm_node->node_id;
	spin_unlock_irq(&card->lock);

	if (channels_hi)
		c = manage_channel(card, irm_id, generation, channels_hi,
+1 −4
Original line number Diff line number Diff line
@@ -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);
Loading