mirror of
https://github.com/torvalds/linux.git
synced 2026-10-25 08:16:03 +01:00
firewire: core: code refactoring to find and pop transaction entry
The list operation to find and pop transaction entry appears several times in transaction implementation, and can be replaced with a helper functional macro. Link: https://lore.kernel.org/r/20251101102131.925071-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
This commit is contained in:
parent
ddc021b58b
commit
fa2dc27100
|
|
@ -51,28 +51,34 @@ static void remove_transaction_entry(struct fw_card *card, struct fw_transaction
|
||||||
card->transactions.tlabel_mask &= ~(1ULL << entry->tlabel);
|
card->transactions.tlabel_mask &= ~(1ULL << entry->tlabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// card->transactions.lock must be acquired in advance.
|
||||||
|
#define find_and_pop_transaction_entry(card, condition) \
|
||||||
|
({ \
|
||||||
|
struct fw_transaction *iter, *t = NULL; \
|
||||||
|
list_for_each_entry(iter, &card->transactions.list, link) { \
|
||||||
|
if (condition) { \
|
||||||
|
t = iter; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
if (t && try_cancel_split_timeout(t)) \
|
||||||
|
remove_transaction_entry(card, t); \
|
||||||
|
t; \
|
||||||
|
})
|
||||||
|
|
||||||
static int close_transaction(struct fw_transaction *transaction, struct fw_card *card, int rcode,
|
static int close_transaction(struct fw_transaction *transaction, struct fw_card *card, int rcode,
|
||||||
u32 response_tstamp)
|
u32 response_tstamp)
|
||||||
{
|
{
|
||||||
struct fw_transaction *t = NULL, *iter;
|
struct fw_transaction *t;
|
||||||
|
|
||||||
// NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for
|
// NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for
|
||||||
// local destination never runs in any type of IRQ context.
|
// local destination never runs in any type of IRQ context.
|
||||||
scoped_guard(spinlock_irqsave, &card->transactions.lock) {
|
scoped_guard(spinlock_irqsave, &card->transactions.lock) {
|
||||||
list_for_each_entry(iter, &card->transactions.list, link) {
|
t = find_and_pop_transaction_entry(card, iter == transaction);
|
||||||
if (iter == transaction) {
|
if (!t)
|
||||||
if (try_cancel_split_timeout(iter)) {
|
return -ENOENT;
|
||||||
remove_transaction_entry(card, iter);
|
|
||||||
t = iter;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!t)
|
|
||||||
return -ENOENT;
|
|
||||||
|
|
||||||
if (!t->with_tstamp) {
|
if (!t->with_tstamp) {
|
||||||
t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data);
|
t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1102,7 +1108,7 @@ EXPORT_SYMBOL(fw_core_handle_request);
|
||||||
|
|
||||||
void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
|
void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
|
||||||
{
|
{
|
||||||
struct fw_transaction *t = NULL, *iter;
|
struct fw_transaction *t = NULL;
|
||||||
u32 *data;
|
u32 *data;
|
||||||
size_t data_length;
|
size_t data_length;
|
||||||
int tcode, tlabel, source, rcode;
|
int tcode, tlabel, source, rcode;
|
||||||
|
|
@ -1144,15 +1150,8 @@ void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
|
||||||
// NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for
|
// NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for
|
||||||
// local destination never runs in any type of IRQ context.
|
// local destination never runs in any type of IRQ context.
|
||||||
scoped_guard(spinlock_irqsave, &card->transactions.lock) {
|
scoped_guard(spinlock_irqsave, &card->transactions.lock) {
|
||||||
list_for_each_entry(iter, &card->transactions.list, link) {
|
t = find_and_pop_transaction_entry(card,
|
||||||
if (iter->node_id == source && iter->tlabel == tlabel) {
|
iter->node_id == source && iter->tlabel == tlabel);
|
||||||
if (try_cancel_split_timeout(iter)) {
|
|
||||||
remove_transaction_entry(card, iter);
|
|
||||||
t = iter;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_async_response_inbound((uintptr_t)t, card->index, p->generation, p->speed, p->ack,
|
trace_async_response_inbound((uintptr_t)t, card->index, p->generation, p->speed, p->ack,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user