[PATCH 3/4] firewire: cdev: use xchg() to exchange pointer value

From: Takashi Sakamoto

Date: Sat Sep 26 2026 - 23:44:37 EST


xchg() is useful for exchanging a pointer and returning the old value,
even when atomicity is not required.

Signed-off-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
---
drivers/firewire/core-cdev.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index 9a539de9b0a1..73a940d40b39 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1357,8 +1357,7 @@ static void iso_resource_auto_work(struct work_struct *work)
u64 reset_jiffies = client->device->card->reset_jiffies;
int current_generation = client->device->generation;

- int resource_generation = r->generation;
- r->generation = current_generation;
+ int resource_generation = xchg(&r->generation, current_generation); // But no need to be atomic.

scoped_guard(spinlock_irq, &client->lock)
todo = r->todo;
@@ -1388,8 +1387,7 @@ static void iso_resource_auto_work(struct work_struct *work)

if (todo == ISO_RES_AUTO_DEALLOC) {
free = true;
- e = r->e_dealloc;
- r->e_dealloc = NULL;
+ e = xchg(&r->e_dealloc, NULL); // But no need to be atomic.
} else {
free = false;

@@ -1417,8 +1415,7 @@ static void iso_resource_auto_work(struct work_struct *work)
return;

// Notify the userspace client of the failure through a deallocation event.
- e = r->e_dealloc;
- r->e_dealloc = NULL;
+ e = xchg(&r->e_dealloc, NULL); // But no need to be atomic.
} else {
// Transit from allocation to reallocation, except if the client requested
// deallocation in the meantime.
@@ -1428,8 +1425,7 @@ static void iso_resource_auto_work(struct work_struct *work)
if (channel >= 0)
r->params.channels_mask = BIT_ULL(channel);

- e = r->e_alloc;
- r->e_alloc = NULL;
+ e = xchg(&r->e_alloc, NULL); // But no need to be atomic.
}
}

--
2.53.0