Skip to content

Commit d320bac

Browse files
committed
firewire: core: use guard macro to maintain list of asynchronous transaction
The core function maintains pending asynchronous transactions by list in the instance of fw_card. The concurrent access to the list is protected by spinlock in the instance. This commit uses guard macro to maintain the spinlock. Link: https://lore.kernel.org/r/20240805085408.251763-14-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent b954544 commit d320bac

1 file changed

Lines changed: 34 additions & 51 deletions

File tree

drivers/firewire/core-transaction.c

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,31 @@ static int close_transaction(struct fw_transaction *transaction, struct fw_card
4949
u32 response_tstamp)
5050
{
5151
struct fw_transaction *t = NULL, *iter;
52-
unsigned long flags;
5352

54-
spin_lock_irqsave(&card->lock, flags);
55-
list_for_each_entry(iter, &card->transaction_list, link) {
56-
if (iter == transaction) {
57-
if (!try_cancel_split_timeout(iter)) {
58-
spin_unlock_irqrestore(&card->lock, flags);
59-
goto timed_out;
53+
scoped_guard(spinlock_irqsave, &card->lock) {
54+
list_for_each_entry(iter, &card->transaction_list, link) {
55+
if (iter == transaction) {
56+
if (try_cancel_split_timeout(iter)) {
57+
list_del_init(&iter->link);
58+
card->tlabel_mask &= ~(1ULL << iter->tlabel);
59+
t = iter;
60+
}
61+
break;
6062
}
61-
list_del_init(&iter->link);
62-
card->tlabel_mask &= ~(1ULL << iter->tlabel);
63-
t = iter;
64-
break;
6563
}
6664
}
67-
spin_unlock_irqrestore(&card->lock, flags);
6865

69-
if (t) {
70-
if (!t->with_tstamp) {
71-
t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data);
72-
} else {
73-
t->callback.with_tstamp(card, rcode, t->packet.timestamp, response_tstamp,
74-
NULL, 0, t->callback_data);
75-
}
76-
return 0;
66+
if (!t)
67+
return -ENOENT;
68+
69+
if (!t->with_tstamp) {
70+
t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data);
71+
} else {
72+
t->callback.with_tstamp(card, rcode, t->packet.timestamp, response_tstamp, NULL, 0,
73+
t->callback_data);
7774
}
7875

79-
timed_out:
80-
return -ENOENT;
76+
return 0;
8177
}
8278

8379
/*
@@ -121,16 +117,13 @@ static void split_transaction_timeout_callback(struct timer_list *timer)
121117
{
122118
struct fw_transaction *t = from_timer(t, timer, split_timeout_timer);
123119
struct fw_card *card = t->card;
124-
unsigned long flags;
125120

126-
spin_lock_irqsave(&card->lock, flags);
127-
if (list_empty(&t->link)) {
128-
spin_unlock_irqrestore(&card->lock, flags);
129-
return;
121+
scoped_guard(spinlock_irqsave, &card->lock) {
122+
if (list_empty(&t->link))
123+
return;
124+
list_del(&t->link);
125+
card->tlabel_mask &= ~(1ULL << t->tlabel);
130126
}
131-
list_del(&t->link);
132-
card->tlabel_mask &= ~(1ULL << t->tlabel);
133-
spin_unlock_irqrestore(&card->lock, flags);
134127

135128
if (!t->with_tstamp) {
136129
t->callback.without_tstamp(card, RCODE_CANCELLED, NULL, 0, t->callback_data);
@@ -143,20 +136,14 @@ static void split_transaction_timeout_callback(struct timer_list *timer)
143136
static void start_split_transaction_timeout(struct fw_transaction *t,
144137
struct fw_card *card)
145138
{
146-
unsigned long flags;
139+
guard(spinlock_irqsave)(&card->lock);
147140

148-
spin_lock_irqsave(&card->lock, flags);
149-
150-
if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) {
151-
spin_unlock_irqrestore(&card->lock, flags);
141+
if (list_empty(&t->link) || WARN_ON(t->is_split_transaction))
152142
return;
153-
}
154143

155144
t->is_split_transaction = true;
156145
mod_timer(&t->split_timeout_timer,
157146
jiffies + card->split_timeout_jiffies);
158-
159-
spin_unlock_irqrestore(&card->lock, flags);
160147
}
161148

162149
static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 request_timestamp);
@@ -1015,7 +1002,6 @@ EXPORT_SYMBOL(fw_core_handle_request);
10151002
void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
10161003
{
10171004
struct fw_transaction *t = NULL, *iter;
1018-
unsigned long flags;
10191005
u32 *data;
10201006
size_t data_length;
10211007
int tcode, tlabel, source, rcode;
@@ -1054,26 +1040,23 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
10541040
break;
10551041
}
10561042

1057-
spin_lock_irqsave(&card->lock, flags);
1058-
list_for_each_entry(iter, &card->transaction_list, link) {
1059-
if (iter->node_id == source && iter->tlabel == tlabel) {
1060-
if (!try_cancel_split_timeout(iter)) {
1061-
spin_unlock_irqrestore(&card->lock, flags);
1062-
goto timed_out;
1043+
scoped_guard(spinlock_irqsave, &card->lock) {
1044+
list_for_each_entry(iter, &card->transaction_list, link) {
1045+
if (iter->node_id == source && iter->tlabel == tlabel) {
1046+
if (try_cancel_split_timeout(iter)) {
1047+
list_del_init(&iter->link);
1048+
card->tlabel_mask &= ~(1ULL << iter->tlabel);
1049+
t = iter;
1050+
}
1051+
break;
10631052
}
1064-
list_del_init(&iter->link);
1065-
card->tlabel_mask &= ~(1ULL << iter->tlabel);
1066-
t = iter;
1067-
break;
10681053
}
10691054
}
1070-
spin_unlock_irqrestore(&card->lock, flags);
10711055

10721056
trace_async_response_inbound((uintptr_t)t, card->index, p->generation, p->speed, p->ack,
10731057
p->timestamp, p->header, data, data_length / 4);
10741058

10751059
if (!t) {
1076-
timed_out:
10771060
fw_notice(card, "unsolicited response (source %x, tlabel %x)\n",
10781061
source, tlabel);
10791062
return;

0 commit comments

Comments
 (0)