[PATCH net-next 1/4] psp: refactor psp_dev_tx_key_del()
From: Daniel Zahka
Date: Thu Sep 03 2026 - 21:39:19 EST
No functional changes.
Lift the list deletion and tx spi validation code into
callers. Deferred key deletion code paths will need similar checks
that a tx key needs removal from the underlying device, but will
diverge when it comes to list handling and when to call
psp_dev_ops::tx_key_del().
Also, move the predicate for tx key deletion into a helper for
readability and reuse in later patches.
Signed-off-by: Daniel Zahka <daniel.zahka@xxxxxxxxx>
---
net/psp/psp.h | 6 ++++++
net/psp/psp_main.c | 7 +++++--
net/psp/psp_sock.c | 11 ++++++-----
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/net/psp/psp.h b/net/psp/psp.h
index 86eeba823ced..8acf9ca84b55 100644
--- a/net/psp/psp.h
+++ b/net/psp/psp.h
@@ -53,4 +53,10 @@ static inline bool psp_dev_is_registered(struct psp_dev *psd)
return !!psd->ops;
}
+static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas)
+{
+ lockdep_assert_held(&pas->psd->lock);
+ return pas->tx.spi;
+}
+
#endif /* __PSP_PSP_H */
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index c9c1a8826b7f..2556f0d46ef4 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -147,8 +147,11 @@ void psp_dev_unregister(struct psp_dev *psd)
list_splice_init(&psd->active_assocs, &psd->prev_assocs);
list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
- list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list)
- psp_dev_tx_key_del(psd, pas);
+ list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list) {
+ if (psp_assoc_needs_tx_key_del(pas))
+ psp_dev_tx_key_del(psd, pas);
+ list_del(&pas->assocs_list);
+ }
list_for_each_entry_safe(entry, entry_tmp, &psd->assoc_dev_list,
dev_list) {
diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
index 1a2a6b7516b0..045389671d7f 100644
--- a/net/psp/psp_sock.c
+++ b/net/psp/psp_sock.c
@@ -85,9 +85,7 @@ static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)
{
- if (pas->tx.spi)
- psd->ops->tx_key_del(psd, pas);
- list_del(&pas->assocs_list);
+ psd->ops->tx_key_del(psd, pas);
}
static void psp_assoc_free(struct work_struct *work)
@@ -96,8 +94,11 @@ static void psp_assoc_free(struct work_struct *work)
struct psp_dev *psd = pas->psd;
mutex_lock(&psd->lock);
- if (psp_dev_is_registered(psd))
- psp_dev_tx_key_del(psd, pas);
+ if (psp_dev_is_registered(psd)) {
+ if (psp_assoc_needs_tx_key_del(pas))
+ psp_dev_tx_key_del(psd, pas);
+ list_del(&pas->assocs_list);
+ }
mutex_unlock(&psd->lock);
psp_dev_put(psd);
kfree(pas);
--
2.52.0