[PATCH v2 2/5] firewire: core: use sparse annotations and lockdep checks for transaction lock
From: Takashi Sakamoto
Date: Fri Oct 09 2026 - 09:05:57 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 be8b2b7b887f..2692e875b00a 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);
+
// 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.
scoped_guard(spinlock_irqsave, &card->transactions.lock) {
@@ -113,7 +121,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 for any event.
might_sleep();
@@ -161,10 +172,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;
@@ -174,9 +188,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;
@@ -189,10 +205,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);
@@ -388,9 +407,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;
@@ -1152,12 +1174,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 for any event.
might_sleep();
--
2.53.0