summaryrefslogtreecommitdiff
path: root/sys/opencrypto
diff options
context:
space:
mode:
authorpgoyette <pgoyette@NetBSD.org>2022-03-31 19:30:15 +0000
committerpgoyette <pgoyette@NetBSD.org>2022-03-31 19:30:15 +0000
commit74849b7b725a6b694bebdbb34a7b9cc04de02a3a (patch)
tree18b599ca229761cdd1b30ca12abb144cb7327147 /sys/opencrypto
parentae0a0824b9f0f9382d9a354526c13241aa44f6e7 (diff)
For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction follow the proper sequence. This is triggered by the recent changes to the devsw stuff; per riastradh@ the required call sequence is: devsw_attach() config_init_component() or config_cf*_attach() ... config_fini_component() or config_cf*_detach() devsw_detach() While here, add a few missing calls to some of the detach routines. Testing of these changes has been limited to: 1. compile without build break 2. no related test failures from atf 3. modload/modunload work as well as before. No functional device testing done, since I don't have any of these devices. Let me know of any damage I might cause here! XXX Some of the modules affected by this commit are already XXX broken; see kern/56772. This commit does not break any additional modules (as far as I know).
Diffstat (limited to 'sys/opencrypto')
-rw-r--r--sys/opencrypto/cryptodev.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c
index 4060d3643e6..a0ce2439366 100644
--- a/sys/opencrypto/cryptodev.c
+++ b/sys/opencrypto/cryptodev.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cryptodev.c,v 1.106 2020/06/30 04:14:55 riastradh Exp $ */
+/* $NetBSD: cryptodev.c,v 1.107 2022/03/31 19:30:17 pgoyette Exp $ */
/* $FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $ */
/* $OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $ */
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.106 2020/06/30 04:14:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.107 2022/03/31 19:30:17 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2199,7 +2199,6 @@ crypto_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
#ifdef _MODULE
- int error2;
devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR;
#endif
@@ -2207,14 +2206,24 @@ crypto_modcmd(modcmd_t cmd, void *arg)
case MODULE_CMD_INIT:
#ifdef _MODULE
+ error = devsw_attach(crypto_cd.cd_name, NULL, &bmajor,
+ &crypto_cdevsw, &cmajor);
+ if (error) {
+ aprint_error("%s: unable to register devsw, error %d\n",
+ crypto_cd.cd_name, error);
+ return error;
+ }
+
error = config_cfdriver_attach(&crypto_cd);
if (error) {
+ devsw_detach(NULL, &crypto_cdevsw);
return error;
}
error = config_cfattach_attach(crypto_cd.cd_name, &crypto_ca);
if (error) {
config_cfdriver_detach(&crypto_cd);
+ devsw_detach(NULL, &crypto_cdevsw);
aprint_error("%s: unable to register cfattach\n",
crypto_cd.cd_name);
@@ -2225,27 +2234,13 @@ crypto_modcmd(modcmd_t cmd, void *arg)
if (error) {
config_cfattach_detach(crypto_cd.cd_name, &crypto_ca);
config_cfdriver_detach(&crypto_cd);
+ devsw_detach(NULL, &crypto_cdevsw);
aprint_error("%s: unable to register cfdata\n",
crypto_cd.cd_name);
return error;
}
- error = devsw_attach(crypto_cd.cd_name, NULL, &bmajor,
- &crypto_cdevsw, &cmajor);
- if (error) {
- error2 = config_cfdata_detach(crypto_cfdata);
- if (error2) {
- return error2;
- }
- config_cfattach_detach(crypto_cd.cd_name, &crypto_ca);
- config_cfdriver_detach(&crypto_cd);
- aprint_error("%s: unable to register devsw, error %d\n",
- crypto_cd.cd_name, error);
-
- return error;
- }
-
(void)config_attach_pseudo(crypto_cfdata);
#endif