diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index f3193cc0ee40..b7a03ba7355d 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -1540,7 +1540,7 @@ crypto_select_kdriver(const struct cryptkop *krp, int flags) * match), then skip. */ cap = crypto_drivers[hid]; - if (cap->cc_dev == NULL || + if (cap == NULL || (cap->cc_flags & match) == 0) continue; @@ -1880,15 +1880,18 @@ crypto_kdone(struct cryptkop *krp) if (krp->krp_status != 0) CRYPTOSTAT_INC(cs_kerrs); - CRYPTO_DRIVER_LOCK(); cap = krp->krp_cap; - KASSERT(cap->cc_koperations > 0, ("cc_koperations == 0")); - cap->cc_koperations--; - if (cap->cc_koperations == 0 && cap->cc_flags & CRYPTOCAP_F_CLEANUP) - wakeup(cap); - CRYPTO_DRIVER_UNLOCK(); - krp->krp_cap = NULL; - cap_rele(cap); + if (cap != NULL) { + CRYPTO_DRIVER_LOCK(); + KASSERT(cap->cc_koperations > 0, ("cc_koperations == 0")); + cap->cc_koperations--; + if (cap->cc_koperations == 0 && + cap->cc_flags & CRYPTOCAP_F_CLEANUP) + wakeup(cap); + CRYPTO_DRIVER_UNLOCK(); + krp->krp_cap = NULL; + cap_rele(cap); + } ret_worker = CRYPTO_RETW(0);