Module Name:    src
Committed By:   riastradh
Date:           Sun May 22 11:39:54 UTC 2022

Modified Files:
        src/sys/opencrypto: crypto.c

Log Message:
opencrypto: Assert nonnull callback up front in crypto_dispatch.

Same with crypto_kdispatch.

Convert some dead branches downstream to assertions too.


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/opencrypto/crypto.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.125 src/sys/opencrypto/crypto.c:1.126
--- src/sys/opencrypto/crypto.c:1.125	Sun May 22 11:39:37 2022
+++ src/sys/opencrypto/crypto.c	Sun May 22 11:39:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.125 2022/05/22 11:39:37 riastradh Exp $ */
+/*	$NetBSD: crypto.c,v 1.126 2022/05/22 11:39:54 riastradh Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.125 2022/05/22 11:39:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.126 2022/05/22 11:39:54 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -1283,6 +1283,7 @@ crypto_dispatch(struct cryptop *crp)
 	struct crypto_crp_q *crp_q;
 
 	KASSERT(crp != NULL);
+	KASSERT(crp->crp_callback != NULL);
 	KASSERT(crp->crp_desc != NULL);
 	KASSERT(crp->crp_buf != NULL);
 	KASSERT(!cpu_intr_p());
@@ -1395,6 +1396,7 @@ crypto_kdispatch(struct cryptkop *krp)
 	struct crypto_crp_kq *crp_kq;
 
 	KASSERT(krp != NULL);
+	KASSERT(krp->krp_callback != NULL);
 	KASSERT(!cpu_intr_p());
 
 	cryptostats.cs_kops++;
@@ -1462,15 +1464,9 @@ crypto_kinvoke(struct cryptkop *krp, int
 	int error;
 
 	KASSERT(krp != NULL);
+	KASSERT(krp->krp_callback != NULL);
 	KASSERT(!cpu_intr_p());
 
-	/* Sanity checks. */
-	if (krp->krp_callback == NULL) {
-		cv_destroy(&krp->krp_cv);
-		crypto_kfreereq(krp);
-		return EINVAL;
-	}
-
 	mutex_enter(&crypto_drv_mtx);
 	for (hid = 0; hid < crypto_drivers_num; hid++) {
 		cap = crypto_checkdriver(hid);
@@ -1548,21 +1544,14 @@ crypto_invoke(struct cryptop *crp, int h
 	struct cryptocap *cap;
 
 	KASSERT(crp != NULL);
+	KASSERT(crp->crp_callback != NULL);
+	KASSERT(crp->crp_desc != NULL);
 	KASSERT(!cpu_intr_p());
 
 #ifdef CRYPTO_TIMING
 	if (crypto_timing)
 		crypto_tstat(&cryptostats.cs_invoke, &crp->crp_tstamp);
 #endif
-	/* Sanity checks. */
-	if (crp->crp_callback == NULL) {
-		return EINVAL;
-	}
-	if (crp->crp_desc == NULL) {
-		crp->crp_etype = EINVAL;
-		crypto_done(crp);
-		return 0;
-	}
 
 	cap = crypto_checkdriver_lock(CRYPTO_SESID2HID(crp->crp_sid));
 	if (cap != NULL && (cap->cc_flags & CRYPTOCAP_F_CLEANUP) == 0) {

Reply via email to