1385 Commits
Author SHA1 Message Date
Takashi Sakamoto 06d410ba93 firewire: core: replace drain_workqueue() with flush_workqueue()
drain_workqueue() allows only chained work to be queued while draining.
This is inconvenient because work can be queued from contexts other than
work items already executing on the workqueue.

Use flush_workqueue() instead to allow work to be queued from any
context.

Link: https://lore.kernel.org/r/20261019122555.328060-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-19 21:25:55 +09:00
Takashi Sakamoto 3e3858e479 firewire: core: adjust context_unsafe() usage for lockdep checks
schedule_error_callback() requires a lock to be held by the caller.
However, __fw_send_request() calls the function without holding any lock
when retrieving the transaction label fails, as no lock is needed in
this case. context_safe() is used to suppress the precondition check in
compiler-based context analysis, but it does not affect lockdep checks.
As a result, lockdep reports a violation of the precondition.

Acquire the lock before calling the function instead of using
context_unsafe().

Link: https://lore.kernel.org/r/20261019122555.328060-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-19 21:25:54 +09:00
Takashi Sakamoto 7d1e256fa1 firewire: core: invoke packet callback from workqueue when removing card instance
Current implementation switches the underlying driver of a card instance
to the dummy driver in the kernel stack when removing the card. The dummy
driver simply invokes callbacks when sending request and response
packets.

Recent changes for the 1394 OHCI driver and core transaction layer ensure
that callbacks are invoked in process context from a workqueue. This
guarantees a consistent execution context for callbacks. However, card
removel is currently an exception.

Invoke packet callbacks from a workqueue during card removal.

Link: https://lore.kernel.org/r/20261018132955.391090-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 22:29:55 +09:00
Takashi Sakamoto 2b6748c5c6 firewire: core: use designated initializer for dummy driver on card removal
The dummy driver used during card removal contains mutable variables.
Use a designated initializer instead of a static constant assignment.

Link: https://lore.kernel.org/r/20261018132955.391090-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 22:29:54 +09:00
Takashi Sakamoto d7a7c63437 firewire: core: use context analysis to check lock state when scheduling error callbacks
The precondition for schedule_error_callback() involves accessing the
pending transaction list. This access should be protected by the
transaction lock.

Use compiler-based context analysis to verify that the lock is held when
accessing the list.

Link: https://lore.kernel.org/r/20261018063056.329226-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 15:30:56 +09:00
Takashi Sakamoto 31ab33a6e3 firewire: core: check precondition when scheduling error callbacks
Current implementation requires that the transaction not be on the
pending list before its error callback is scheduled. A WARN_ON() in the
callback function detects violations of this precondition, but the check
belongs in the scheduling helper.

Move the WARN_ON() to schedule_error_callback().

Link: https://lore.kernel.org/r/20261018063056.329226-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 15:30:55 +09:00
Takashi Sakamoto 767e87bb6f firewire: core: use workqueue to cancel all pending transactions on card removal
When a card is being removed, all pending transactions are canceled by
calling fw_cancel_pending_transactions(). This function moves the entries
for unfinished transactions to a local list so that their callbacks can
be invoked without holding the transaction lock. However, this complicates
the management of pending transactions.

Use workqueue to invoke error callbacks for all pending transactions.

Link: https://lore.kernel.org/r/20261018063056.329226-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 15:30:54 +09:00
Takashi Sakamoto 3e7ed554a8 firewire: core: reuse helper function for scheduling error callbacks
The transaction layer has some code that can be replaced with the
existing helper function for scheduling error callbacks.

Link: https://lore.kernel.org/r/20261017153339.267337-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 00:33:39 +09:00
Takashi Sakamoto e7f6c18a8c firewire: core: don't disable error work for transaction
The error callback work is scheduled only when the transaction instance
is no longer on the pending list. Therefore, iterating over the list to
cancel the work is pointless.

Remove the code that cancels the work while iterating over the pending
list. Once scheduled, the work can run and invoke the error callback
without being cancelled.

Link: https://lore.kernel.org/r/20261017153339.267337-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-18 00:33:38 +09:00
Takashi Sakamoto 23b790766a firewire: core: use release/acquire pair when replacing underlying driver on card removal
When removing a card instance, the underlying driver is replaced to handle
closing operations. Without proper memory reordering, other CPUs may
observe the driver before it is fully initialized.

Use a release/acquire pair to ensure that the driver's initialization is
visible before the driver is accessed for close operations.

Link: https://lore.kernel.org/r/20261017081720.186688-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-17 17:17:20 +09:00
Takashi Sakamoto aa7f13e25c firewire: core: add kerneldoc for inbound transaction-related symbols
The core provides helper functions and structures for handling
transaction requests to local address regions.

Add kerneldoc comments for these symbols.

Link: https://lore.kernel.org/r/20261013111509.612518-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-13 20:15:09 +09:00
Takashi Sakamoto 7a8db81dbd firewire: core: add kerneldoc for outbound transaction-related symbols
The core provides helper functions and structures for initiating
asynchronous transactions.

Add kerneldoc comments for these symbols.

Link: https://lore.kernel.org/r/20261013111509.612518-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-13 20:15:08 +09:00
Takashi Sakamoto a78c645379 firewire: core: use appropriate spinlock variants for transaction-related locks
The spinlocks in the fw_card structure protect transaction-related state
from concurrent access. They are acquired mostly from process context.
The exceptions are split_transaction_timeout_callback(), which runs in
softirq context for the timer wheel, and __fw_send_request(), which may
also be called from interrupt context.

Use spin_lock() in split_transaction_timeout_callback() and
spin_lock_irqsave() in the other functions. The latter preserves and
restores the caller's interrupt state, as the callers are not guaranteed
to have interrupts enabled.

Link: https://lore.kernel.org/r/20261012015739.530731-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-12 10:57:39 +09:00
Takashi Sakamoto aea8c084cb firewire: core: narrow the card lock scope when accessing node_id
When preparing the request subaction for an asynchronous transaction,
the node_id field in the fw_card structure is accessed under the
card-level spinlock. However, the lock is held across a call to a helper
function, unnecessarily extending the critical section.

Narrow the critical section to cover only the access to node_id.

Link: https://lore.kernel.org/r/20261011063146.497455-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-11 15:31:46 +09:00
Takashi Sakamoto c2b3fb6326 firewire: core: use context analysis annotations and lockdep checks for topology map lock
The spinlock protects the topology map from concurrent access.

Add context analysis annotations and lockdep checks for this lock.

Link: https://lore.kernel.org/r/20261011063146.497455-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-11 15:31:45 +09:00
Takashi Sakamoto 8540ec31c8 firewire: core: use context analysis annotations and lockdep checks for split timeout lock
The spinlock protects parameters related to split transaction timeouts.

Add context analysis annotations and lockdep checks for this lock.

Link: https://lore.kernel.org/r/20261009121048.282982-5-o-takashi@sakamocchi.jp
Link: https://lore.kernel.org/r/20261011063146.497455-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-11 15:31:44 +09:00
Takashi Sakamoto 15efe5cec6 firewire: core: use context analysis annotations and lockdep checks for transactions lock
The transaction lock protects the list of pending transactions and the
transaction label.

Add context analysis annotations for the transaction lock. Compiler-based
context analysis has difficulty tracking the locking scope when the lock
is accessed through an indirect reference (e.g. t->card->lock), making
some functions difficult to annotate. Use lockdep assertions to cover
these cases.

Link: https://lore.kernel.org/r/20261011063146.497455-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-11 15:31:43 +09:00
Takashi Sakamoto 382e671eac firewire: core: enable context analysis for transaction layer
The kernel is transitioning from Sparse-based context analysis to
compier-based context analysis, which requires LLVM/Clang 23 or later.
Individual compilation units can opt in to the analysis through their
Makefiles.

Enable context analysis for the transaction layer.

Link: https://lore.kernel.org/r/20261011063146.497455-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-11 15:31:42 +09:00
Takashi Sakamoto 9136caffae firewire: core: add might_sleep() checks to transaction layer
Some functions are now guaranteed to run in process context.

Add might_sleep() calls to these functions to document and check this
requirement.

Link: https://lore.kernel.org/r/20261011063146.497455-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-11 15:31:41 +09:00
Takashi Sakamoto b381407e03 firewire: core: fulfill kerneldoc for fw_cancel_transaction()
fw_cancel_transaction() has no kerneldoc even though it is exposed.

Add kerneldoc for it.

Link: https://lore.kernel.org/r/20261007093235.175742-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-07 18:32:35 +09:00
Takashi Sakamoto dd1c6b1518 firewire: core: schedule callback when cancelling pending transactions
The current implementation invokes the transaction callback in the
context where transaction cancellation is requested. This is
inconvenient because the context can affect the transaction callback.

Invoke the transaction callback from a workqueue instead. Use the
workqueue for error handling.

Link: https://lore.kernel.org/r/20261007093235.175742-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-07 18:32:34 +09:00
Takashi Sakamoto 34dca2ecd4 firewire: ohci: allow AT local packet cancellation
The current implementation uses a different path for local packets than
for remote packets, and local packets cannot be cancelled once they have
been queued.

Allow local packets to be cancelled.

Link: https://lore.kernel.org/r/20261007093235.175742-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-07 18:32:33 +09:00
Takashi Sakamoto 1d2f5118ba firewire: ohci: schedule callback on workqueue when cancelling AT request packet
The current implementation invokes the packet callback in the context
where the packet cancellation is requested. This is inconvenient because
the context can affect the packet callback.

Invoke the packet callback from a workqueue instead. Use the workqueue
for local AT packets.

Link: https://lore.kernel.org/r/20261007093235.175742-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-07 18:32:32 +09:00
Takashi Sakamoto a87cf01800 firewire: core: expand close_transaction() into its callers and remove it
The return value from close_transaction() is useful only in
fw_cancel_transaction(). The other caller,
transmit_complete_callback(), simply discards it.

Additionally, the pending transaction queue should be enumerated as soon
as possible to prevent the issued transaction from completing.

Expand close_transaction() into its callers, and remove it.

In the find_and_pop_transaction_entry() macro, a local variable provides
the evaluation result, however transmit_complete_callback() uses the same
local variable for another purpose. Add an underscore prefix to the one
in the macro to avoid the unexpected result.

Link: https://lore.kernel.org/r/20261007093235.175742-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-10-07 18:32:31 +09:00
Takashi Sakamoto 8487a3a876 firewire: cdev: use kzalloc_flex() to allocate structure with byte array
Some event structures have a trailing flexible array member of bytes to
store event-specific data. Use kzalloc_flex() to allocate the structure
together with storage for the flexible array member.

Link: https://lore.kernel.org/r/20260928125718.50974-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-28 21:57:17 +09:00
Takashi Sakamoto b1790574d3 firewire: cdev: use kzalloc_flex() to allocate structure with quadlet array
Some event structures have a trailing flexible array member of quadlets
to store event-specific data. Use kzalloc_flex() to allocate the
structure together with storage for the flexible array member.

Link: https://lore.kernel.org/r/20260928125718.50974-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-28 21:57:16 +09:00
Takashi Sakamoto 8fa3077dff firewire: core: use kzalloc_flex() to allocate structure with quadlet array
fw_core_handle_request() is now called in process context, so GFP_KERNEL
is available. The fw_request structure has a trailing flexible array
member of quadlets to store packet data. Use kzalloc_flex() to allocate
the structure together with storage for the flexible array member.

Link: https://lore.kernel.org/r/20260928125718.50974-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-28 21:57:15 +09:00
Takashi Sakamoto 930960ee37 firewire: cdev: use mutex for client locking
All execution paths in the cdev layer now run in process context.

Use a mutex instead of a spinlock for client-level locking.

Link: https://lore.kernel.org/r/20260927230724.119305-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-28 08:07:24 +09:00
Takashi Sakamoto 2b69c5fe9e firewire: cdev: use atomic_t for iso_resource_auto todo member
The transition state of an iso_resource_auto client resource has no
effect on the client, so the client-level lock is not suitable for
protecting it.

At present, this state is the only member that requires mutual
exclusion. Adding a separate lock for it would be excessive.

Change the type of the transition state to atomic_t and use an atomic
compare-and-swap operation to preserve consistency.

Link: https://lore.kernel.org/r/20260927230724.119305-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-28 08:07:23 +09:00
Takashi Sakamoto c94caec799 firewire: ohci: run work immediately when re-enabled in packet cancellation
During packet cancellation, the work item for the AT request context is
disabled. As a result, packets for request subactions are not processed
by the work item even if they finished, since the work item can not be
scheduled from hardIRQ handling.

Run the work item immediately after re-enabling it.

Link: https://lore.kernel.org/r/20260927044407.65497-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-27 13:44:07 +09:00
Takashi Sakamoto 87a48a22b3 firewire: core: remove unnecessary branch for timestamping when cancelling transaction request packets
When fw_card_driver.cancel_packet() returns a non-zero value, the request
subaction of the transaction has already finished. It means that the
packet for the request subaction has already received an ack code and a
timestamp, so there is no need to check them.

Remove the unnecessary branch for the ack code and timestamp.

Link: https://lore.kernel.org/r/20260927044407.65497-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-27 13:44:06 +09:00
Takashi Sakamoto 981a9c4feb firewire: cdev: refactor event copying to remove goto statement
Arrange the local variables to avoid a goto statement when copying events
to the userspace buffer.

Link: https://lore.kernel.org/r/20260927034343.28076-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-27 12:43:43 +09:00
Takashi Sakamoto 9cc8efc586 firewire: cdev: use xchg() to exchange pointer value
xchg() is useful for exchanging a pointer and returning the old value,
even when atomicity is not required.

Link: https://lore.kernel.org/r/20260927034343.28076-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-27 12:43:42 +09:00
Takashi Sakamoto 0f636cfe8d firewire: cdev: wake up client from queue_event() only when any event is available
The in_shutdown member of client structure is set only when releasing
file descriptor, thus no need to wake up the client itself.

Link: https://lore.kernel.org/r/20260927034343.28076-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-27 12:43:41 +09:00
Takashi Sakamoto b362e6dd5c firewire: cdev: remove unnecessary client locking for fw_device members
Some accesses to fw_device members unnecessarily use the client-level
lock. Remove the locking from these accesses.

Link: https://lore.kernel.org/r/20260927034343.28076-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-27 12:43:40 +09:00
Bill Wendling 39e505c38f firewire: core: add __counted_by_ptr attribute to struct fw_device
The GCC and Clang attribute '__counted_by_ptr' associates a pointer
field with an integer field holding its element count. This enables
runtime bounds checking by KASAN and UBSAN to prevent out-of-bounds
accesses to the pointer.

In 'struct fw_device' (defined in 'include/linux/firewire.h'), the
field 'config_rom' is a pointer to the device's Configuration ROM data,
and its associated element count is stored in 'config_rom_length'.

Additionally, update the existing KUnit test in
'drivers/firewire/device-attribute-test.c' where 'config_rom_length'
was incorrectly initialized with the byte size
('sizeof(simple_avc_config_rom)') instead of the element count
('ARRAY_SIZE(simple_avc_config_rom)'). This ensures the
'__counted_by_ptr' bounds-checking annotation does not trigger any
false-positive panics or compile/runtime checks.

Cc: codemender-patching+linux@google.com
Assisted-by: LLM
Signed-off-by: Bill Wendling <morbo@google.com>
Link: https://lore.kernel.org/r/20260925212552.125652-1-morbo@google.com
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-25 21:25:52 +00:00
Takashi Sakamoto 76ef77d7e6 firewire: cdev: fix client refcount leak in iso_resource_auto_work()
The client reference leaks when the pending work is cancelled because an
additional reference was taken when scheduling the work.

The reference held by the fw_iso_resource_auto object already ensures
that the client structure remains valid for the lifetime of the object.
Therefore, the additional reference taken when scheduling the work is
unnecessary.

Remove the additional reference.

Reported-by: Dingisoul <dingiso.kernel@gmail.com>
Link: https://sourceforge.net/p/linux1394/mailman/message/59317811/
Link: https://lore.kernel.org/r/20260923172328.277232-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-24 02:23:28 +09:00
Takashi Sakamoto a689a10b51 firewire: cdev: hold client reference for fw_iso_resource_auto lifetime
The fw_iso_resource_auto object can outlive the operation that created
it since hte main operation for it is done in a work item. This work and
release paths access members of the client structure, therefore the
client structure must remain valid for the lifetime of an
fw_iso_resource_auto object.

Hold a reference to the client structure for the lifetime of the
fw_iso_resource_auto object.

Link: https://lore.kernel.org/r/20260923172328.277232-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-24 02:23:27 +09:00
Takashi Sakamoto f95344968c firewire: core: update kerneldoc for fw_send_request() and its variants
Some error paths invoke the transaction callback in process context using
a workqueue. All transaction callbacks are now invoked in process context.

Update kerneldoc to reflect this behavior.

Link: https://lore.kernel.org/r/20260921031931.287429-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-21 12:19:31 +09:00
Takashi Sakamoto 382ec29406 firewire: core: use workqueue to invoke transaction callback in some error cases
Some error paths of __fw_send_request() invoke the transaction callback
in the caller's context. Additionally, when a split transaction times
out, the callback is invoked in softIRQ context by the timer wheel.

These are the only cases where the callback is not guaranteed to be
invoked in process context.

Use a workqueue to invoke the callback in these cases. This may introduce
additional delay when a split transaction times out, but the default
timeout is 2 seconds, so the additional delay should be negligible.

Link: https://lore.kernel.org/r/20260921031931.287429-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-21 12:19:30 +09:00
Takashi Sakamoto 4e7cbc6c14 firewire: core: refactor invoking transaction callback
Two types of transaction callbacks are defined. There are many places
where the transaction callback is invoked with conditional branches.

Add a helper function to simplify invoking the callback.

Link: https://lore.kernel.org/r/20260921031931.287429-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-21 12:19:29 +09:00
Takashi Sakamoto e079effb35 firewire: cdev: refactor add_client_resource() to have release callback function
The implementation of the client_resource structure now requires a release
callback.

Add an argument to add_client_resource() for the release callback.

Link: https://lore.kernel.org/r/20260920083659.191855-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 17:36:59 +09:00
Takashi Sakamoto 4e3f598122 firewire: cdev: refactor add_client_resource() to drop GFP flags argument
The add_client_resource() function has an argument for GFP flags. The
argument was originally used to distinguish atomic calls. However, all
callers now use GFP_KERNEL.

Drop the unused argument and always allocate with GFP_KERNEL.

Link: https://lore.kernel.org/r/20260920083659.191855-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 17:36:58 +09:00
Takashi Sakamoto 0958dcb1e5 firewire: cdev: use GFP_KERNEL in address handler
The callback for the address handler is now guaranteed to be invoked in
process context. In the cdev layer, GFP_ATOMIC is still used for memory
allocation in the address handler.

Use GFP_KERNEL instead.

Link: https://lore.kernel.org/r/20260920083659.191855-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 17:36:57 +09:00
Takashi Sakamoto a520ce89fc firewire: cdev: use mutex for phy receiver list
In the cdev layer, the list of phy packet receivers is currently
protected by a spinlock. This requires GFP_ATOMIC for memory allocation
when enumerating the list in fw_cdev_handle_phy_packet(). However, the
function is guaranteed to be invoked in process context, so GFP_KERNEL
can be used by switching from the spinlock to a mutex.

Link: https://lore.kernel.org/r/20260920083659.191855-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 17:36:56 +09:00
Takashi Sakamoto 567a656d92 firewire: core: fulfill kerneldoc for address handler
The callback for the address handler is now invoked in process context.

Update the kerneldoc for the address handler accordingly.

Link: https://lore.kernel.org/r/20260920083659.191855-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 17:36:55 +09:00
Takashi Sakamoto e64f2d4de1 firewire: core: consolidate lock scopes for event waiting in dequeue function
Current implementation uses the spinlock in the card structure to
serialize accesses to the event list. The dequeue_event() function yields
the CPU while waiting for the condition to become true, but checks the
list without acquiring the spinlock. It acquires the spinlock when
operating the list, however it assumes that the list has at least one
entry.

This can cause problems when multiple threads execute read(2) system calls
concurrently, since the list can become empty after rescheduling but before
the list operation, depending on the scheduling order of the two threads.

Use a wait_event variant that reacquires the lock after being
rescheduled, before checking the condition.

Link: https://lore.kernel.org/r/20260920104745.212753-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 19:47:45 +09:00
Takashi Sakamoto ab2a823af3 firewire: cdev: add KUnit test for bus reset event UAPI structure
The bus reset event structure exposed through the UAPI has a different
size depending on the target architecture. Extra care is required when
copying it to/from userspace.

Add a KUnit test for the structure to ensure that it has the expected
size and offsets.

Link: https://lore.kernel.org/r/20260920071501.77785-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 16:15:01 +09:00
Takashi Sakamoto 259ee8e255 firewire: cdev: add annotations and comments about race condition of bus_reset_closure
There is a race condition involving the bus_reset_closure member of the
fw_cdev_event_bus_reset structure, which was addressed by commit
93b37905f7 ("firewire: cdev: prevent race between first get_info ioctl
and bus reset event queuing").

Add code comments and annotations to document it.

Link: https://lore.kernel.org/r/20260920071501.77785-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 16:15:00 +09:00
Takashi Sakamoto 1f6877ccef firewire: cdev: refactor copy_to_user() in get_info ioctl call
A non-zero return value from copy_to_user() is handled by returning
-EFAULT. Using scoped_guard() simplifies this handling, since it
eliminates the need for a local variable to store the return value and
check it after the locking primitive is released.

Refactor the code to remove the local variable.

Link: https://lore.kernel.org/r/20260920071501.77785-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2026-09-20 16:14:59 +09:00