Skip to content

Commit 27310d5

Browse files
committed
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: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent d320bac commit 27310d5

6 files changed

Lines changed: 19 additions & 33 deletions

File tree

drivers/firewire/core-card.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ static void bm_work(struct work_struct *work)
374374

375375
bm_id = be32_to_cpu(transaction_data[0]);
376376

377-
spin_lock_irq(&card->lock);
378-
if (rcode == RCODE_COMPLETE && generation == card->generation)
379-
card->bm_node_id =
380-
bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
381-
spin_unlock_irq(&card->lock);
377+
scoped_guard(spinlock_irq, &card->lock) {
378+
if (rcode == RCODE_COMPLETE && generation == card->generation)
379+
card->bm_node_id =
380+
bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
381+
}
382382

383383
if (rcode == RCODE_COMPLETE && bm_id != 0x3f) {
384384
/* Somebody else is BM. Only act as IRM. */
@@ -707,7 +707,6 @@ EXPORT_SYMBOL_GPL(fw_card_release);
707707
void fw_core_remove_card(struct fw_card *card)
708708
{
709709
struct fw_card_driver dummy_driver = dummy_driver_template;
710-
unsigned long flags;
711710

712711
card->driver->update_phy_reg(card, 4,
713712
PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
@@ -721,9 +720,8 @@ void fw_core_remove_card(struct fw_card *card)
721720
dummy_driver.stop_iso = card->driver->stop_iso;
722721
card->driver = &dummy_driver;
723722

724-
spin_lock_irqsave(&card->lock, flags);
725-
fw_destroy_nodes(card);
726-
spin_unlock_irqrestore(&card->lock, flags);
723+
scoped_guard(spinlock_irqsave, &card->lock)
724+
fw_destroy_nodes(card);
727725

728726
/* Wait for all users, especially device workqueue jobs, to finish. */
729727
fw_card_put(card);

drivers/firewire/core-cdev.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
354354
{
355355
struct fw_card *card = client->device->card;
356356

357-
spin_lock_irq(&card->lock);
357+
guard(spinlock_irq)(&card->lock);
358358

359359
event->closure = client->bus_reset_closure;
360360
event->type = FW_CDEV_EVENT_BUS_RESET;
@@ -364,8 +364,6 @@ static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
364364
event->bm_node_id = card->bm_node_id;
365365
event->irm_node_id = card->irm_node->node_id;
366366
event->root_node_id = card->root_node->node_id;
367-
368-
spin_unlock_irq(&card->lock);
369367
}
370368

371369
static void for_each_client(struct fw_device *device,

drivers/firewire/core-device.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -886,16 +886,14 @@ static void fw_device_release(struct device *dev)
886886
{
887887
struct fw_device *device = fw_device(dev);
888888
struct fw_card *card = device->card;
889-
unsigned long flags;
890889

891890
/*
892891
* Take the card lock so we don't set this to NULL while a
893892
* FW_NODE_UPDATED callback is being handled or while the
894893
* bus manager work looks at this node.
895894
*/
896-
spin_lock_irqsave(&card->lock, flags);
897-
device->node->data = NULL;
898-
spin_unlock_irqrestore(&card->lock, flags);
895+
scoped_guard(spinlock_irqsave, &card->lock)
896+
device->node->data = NULL;
899897

900898
fw_node_put(device->node);
901899
kfree(device->config_rom);
@@ -952,7 +950,7 @@ static int lookup_existing_device(struct device *dev, void *data)
952950
return 0;
953951

954952
guard(rwsem_read)(&fw_device_rwsem); // serialize config_rom access
955-
spin_lock_irq(&card->lock); /* serialize node access */
953+
guard(spinlock_irq)(&card->lock); // serialize node access
956954

957955
if (memcmp(old->config_rom, new->config_rom, 6 * 4) == 0 &&
958956
atomic_cmpxchg(&old->state,
@@ -982,8 +980,6 @@ static int lookup_existing_device(struct device *dev, void *data)
982980
match = 1;
983981
}
984982

985-
spin_unlock_irq(&card->lock);
986-
987983
return match;
988984
}
989985

drivers/firewire/core-iso.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,8 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
375375
u32 channels_lo = channels_mask >> 32; /* channels 63...32 */
376376
int irm_id, ret, c = -EINVAL;
377377

378-
spin_lock_irq(&card->lock);
379-
irm_id = card->irm_node->node_id;
380-
spin_unlock_irq(&card->lock);
378+
scoped_guard(spinlock_irq, &card->lock)
379+
irm_id = card->irm_node->node_id;
381380

382381
if (channels_hi)
383382
c = manage_channel(card, irm_id, generation, channels_hi,

drivers/firewire/core-topology.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,10 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
455455
int self_id_count, u32 *self_ids, bool bm_abdicate)
456456
{
457457
struct fw_node *local_node;
458-
unsigned long flags;
459458

460459
trace_bus_reset_handle(card->index, generation, node_id, bm_abdicate, self_ids, self_id_count);
461460

462-
spin_lock_irqsave(&card->lock, flags);
461+
guard(spinlock_irqsave)(&card->lock);
463462

464463
/*
465464
* 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,
500499
} else {
501500
update_tree(card, local_node);
502501
}
503-
504-
spin_unlock_irqrestore(&card->lock, flags);
505502
}
506503
EXPORT_SYMBOL(fw_core_handle_bus_reset);

drivers/firewire/core-transaction.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,6 @@ static void handle_registers(struct fw_card *card, struct fw_request *request,
11601160
int reg = offset & ~CSR_REGISTER_BASE;
11611161
__be32 *data = payload;
11621162
int rcode = RCODE_COMPLETE;
1163-
unsigned long flags;
11641163

11651164
switch (reg) {
11661165
case CSR_PRIORITY_BUDGET:
@@ -1202,10 +1201,10 @@ static void handle_registers(struct fw_card *card, struct fw_request *request,
12021201
if (tcode == TCODE_READ_QUADLET_REQUEST) {
12031202
*data = cpu_to_be32(card->split_timeout_hi);
12041203
} else if (tcode == TCODE_WRITE_QUADLET_REQUEST) {
1205-
spin_lock_irqsave(&card->lock, flags);
1204+
guard(spinlock_irqsave)(&card->lock);
1205+
12061206
card->split_timeout_hi = be32_to_cpu(*data) & 7;
12071207
update_split_timeout(card);
1208-
spin_unlock_irqrestore(&card->lock, flags);
12091208
} else {
12101209
rcode = RCODE_TYPE_ERROR;
12111210
}
@@ -1215,11 +1214,10 @@ static void handle_registers(struct fw_card *card, struct fw_request *request,
12151214
if (tcode == TCODE_READ_QUADLET_REQUEST) {
12161215
*data = cpu_to_be32(card->split_timeout_lo);
12171216
} else if (tcode == TCODE_WRITE_QUADLET_REQUEST) {
1218-
spin_lock_irqsave(&card->lock, flags);
1219-
card->split_timeout_lo =
1220-
be32_to_cpu(*data) & 0xfff80000;
1217+
guard(spinlock_irqsave)(&card->lock);
1218+
1219+
card->split_timeout_lo = be32_to_cpu(*data) & 0xfff80000;
12211220
update_split_timeout(card);
1222-
spin_unlock_irqrestore(&card->lock, flags);
12231221
} else {
12241222
rcode = RCODE_TYPE_ERROR;
12251223
}

0 commit comments

Comments
 (0)