[PATCH 3/6] firewire: core: use sparse annotations and lockdep checks for transaction lock

From: Takashi Sakamoto

Date: Thu Oct 08 2026 - 19:45:12 EST


The spinlock protects the list of pending transactions and the transaction
label.

Add sparse annotations and lockdep checks for this lock.

Signed-off-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
---
drivers/firewire/core-transaction.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
index ac7a9bde6fef..0c492e4af971 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -38,16 +38,21 @@

/* returns 0 if the split timeout handler is already running */
static int try_cancel_split_timeout(struct fw_transaction *t)
+__must_hold(&t->card->transactions.lock)
{
+ lockdep_assert_held(&t->card->transactions.lock);
+
if (t->is_split_transaction)
return timer_delete(&t->split_timeout_timer) || disable_work(&t->error_work);
else
return 1;
}

-// card->transactions.lock must be acquired in advance.
static void remove_transaction_entry(struct fw_card *card, struct fw_transaction *entry)
+__must_hold(&card->transactions.lock)
{
+ lockdep_assert_held(&card->transactions.lock);
+
list_del_init(&entry->link);
card->transactions.tlabel_mask &= ~(1ULL << entry->tlabel);
}
@@ -65,10 +70,13 @@ static void invoke_callback(struct fw_transaction *t, int rcode, u32 response_ts

// Must be called without holding card->transactions.lock.
void fw_cancel_pending_transactions(struct fw_card *card)
+__must_not_hold(&card->transactions.lock)
{
struct fw_transaction *t, *tmp;
LIST_HEAD(pending_list);

+ lockdep_assert_not_held(&card->transactions.lock);
+
scoped_guard(spinlock_irq, &card->transactions.lock) {
list_for_each_entry_safe(t, tmp, &card->transactions.list, link) {
if (try_cancel_split_timeout(t))
@@ -111,7 +119,10 @@ void fw_cancel_pending_transactions(struct fw_card *card)
* pending transaction.
*/
int fw_cancel_transaction(struct fw_card *card, struct fw_transaction *transaction)
+__must_not_hold(&card->transactions.lock)
{
+ lockdep_assert_not_held(&card->transactions.lock);
+
// Allow the call of struct fw_card_driver.cancel_packet() to wait any event.
might_sleep();

@@ -156,10 +167,13 @@ static void schedule_error_callback(struct fw_transaction *t, int rcode, u32 res
}

static void split_transaction_timeout_callback(struct timer_list *timer)
+__must_not_hold(&card->transactions.lock)
{
struct fw_transaction *t = timer_container_of(t, timer, split_timeout_timer);
struct fw_card *card = t->card;

+ lockdep_assert_not_held(&card->transactions.lock);
+
scoped_guard(spinlock_irqsave, &card->transactions.lock) {
if (list_empty(&t->link))
return;
@@ -169,9 +183,11 @@ static void split_transaction_timeout_callback(struct timer_list *timer)
schedule_error_callback(t, RCODE_CANCELLED, t->split_timeout_cycle);
}

-// card->transactions.lock should be acquired in advance for the linked list.
static void start_split_transaction_timeout(struct fw_transaction *t, unsigned int delta)
+__must_hold(&t->card->transactions.lock)
{
+ lockdep_assert_held(&t->card->transactions.lock);
+
if (list_empty(&t->link) || WARN_ON(t->is_split_transaction))
return;

@@ -184,10 +200,13 @@ static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 request_tim

static void transmit_complete_callback(struct fw_packet *packet,
struct fw_card *card, int status)
+__must_not_hold(&card->transactions.lock)
{
struct fw_transaction *t =
container_of(packet, struct fw_transaction, packet);

+ lockdep_assert_not_held(&card->transactions.lock);
+
trace_async_request_outbound_complete((uintptr_t)t, card->index, packet->generation,
packet->speed, status, packet->timestamp);

@@ -379,9 +398,12 @@ void __fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode
int destination_id, int generation, int speed, unsigned long long offset,
void *payload, size_t length, union fw_transaction_callback callback,
bool with_tstamp, void *callback_data)
+__must_not_hold(&card->transactions.lock)
{
int tlabel;

+ lockdep_assert_not_held(&card->transactions.lock);
+
t->card = card;
t->callback = callback;
t->with_tstamp = with_tstamp;
@@ -1137,12 +1159,15 @@ void fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
EXPORT_SYMBOL(fw_core_handle_request);

void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
+__must_not_hold(&card->transactions.lock)
{
struct fw_transaction *t = NULL;
u32 *data;
size_t data_length;
int tcode, tlabel, source, rcode;

+ lockdep_assert_not_held(&card->transactions.lock);
+
// Allow the call of struct fw_card_driver.cancel_packet() to wait any event.
might_sleep();

--
2.53.0