[PATCH] crypto: chelsio - Fix potential NULL dereference after detach

From: Guangshuo Li

Date: Mon Nov 16 2026 - 09:17:43 EST


Detached contexts remain on the inactive list until module exit, but
their PCI driver data has already been cleared. Looking up the adapter
to reset its counters then dereferences NULL.

Skip the adapter lookup for detached contexts and free the contexts
without accessing the removed adapter.

This issue was found by our static analysis tool under development.

Fixes: c0271a053612 ("crypto: chelsio - Resetting crypto counters during the driver unregister")
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/crypto/chelsio/chcr_core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_core.c b/drivers/crypto/chelsio/chcr_core.c
index 2609a8c3c18b..96ac6ea482b2 100644
--- a/drivers/crypto/chelsio/chcr_core.c
+++ b/drivers/crypto/chelsio/chcr_core.c
@@ -295,8 +295,10 @@ static void __exit chcr_crypto_exit(void)
kfree(u_ctx);
}
list_for_each_entry_safe(u_ctx, tmp, &drv_data.inact_dev, entry) {
- adap = padap(&u_ctx->dev);
- memset(&adap->chcr_stats, 0, sizeof(adap->chcr_stats));
+ if (u_ctx->dev.state != CHCR_DETACH) {
+ adap = padap(&u_ctx->dev);
+ memset(&adap->chcr_stats, 0, sizeof(adap->chcr_stats));
+ }
list_del(&u_ctx->entry);
kfree(u_ctx);
}

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0