From 74849b7b725a6b694bebdbb34a7b9cc04de02a3a Mon Sep 17 00:00:00 2001 From: pgoyette Date: Thu, 31 Mar 2022 19:30:15 +0000 Subject: 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). --- sys/modules/lua/lua.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'sys/modules/lua/lua.c') diff --git a/sys/modules/lua/lua.c b/sys/modules/lua/lua.c index bfe548343e6..3518d8ef2ef 100644 --- a/sys/modules/lua/lua.c +++ b/sys/modules/lua/lua.c @@ -1,4 +1,4 @@ -/* $NetBSD: lua.c,v 1.27 2021/08/08 22:26:32 rin Exp $ */ +/* $NetBSD: lua.c,v 1.28 2022/03/31 19:30:17 pgoyette Exp $ */ /* * Copyright (c) 2011 - 2017 by Marc Balmer . @@ -860,14 +860,25 @@ lua_modcmd(modcmd_t cmd, void *opaque) switch (cmd) { case MODULE_CMD_INIT: #ifdef _MODULE + error = devsw_attach(lua_cd.cd_name, NULL, &bmajor, + &lua_cdevsw, &cmajor); + if (error) { + aprint_error("%s: unable to register devsw\n", + lua_cd.cd_name); + return error; + } + error = config_cfdriver_attach(&lua_cd); - if (error) + if (error) { + devsw_detach(NULL, &lua_cdevsw); return error; + } error = config_cfattach_attach(lua_cd.cd_name, &lua_ca); if (error) { config_cfdriver_detach(&lua_cd); + devsw_detach(NULL, &lua_cdevsw); aprint_error("%s: unable to register cfattach\n", lua_cd.cd_name); return error; @@ -877,19 +888,11 @@ lua_modcmd(modcmd_t cmd, void *opaque) config_cfattach_detach(lua_cd.cd_name, &lua_ca); config_cfdriver_detach(&lua_cd); + devsw_detach(NULL, &lua_cdevsw); aprint_error("%s: unable to register cfdata\n", lua_cd.cd_name); return error; } - error = devsw_attach(lua_cd.cd_name, NULL, &bmajor, - &lua_cdevsw, &cmajor); - if (error) { - aprint_error("%s: unable to register devsw\n", - lua_cd.cd_name); - config_cfattach_detach(lua_cd.cd_name, &lua_ca); - config_cfdriver_detach(&lua_cd); - return error; - } config_attach_pseudo(lua_cfdata); #endif return 0; -- cgit