Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178300515
D62322.1796461022.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D62322.1796461022.diff
View Options
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -184,8 +184,8 @@
("Periph driver '%s' was not registered", drv->driver_name));
for (; n + 1 < nperiph_drivers; n++)
periph_drivers[n] = periph_drivers[n + 1];
- periph_drivers[n + 1] = NULL;
nperiph_drivers--;
+ periph_drivers[nperiph_drivers] = NULL;
xpt_unlock_buses();
return (0);
}
diff --git a/tests/sys/cam/Makefile b/tests/sys/cam/Makefile
--- a/tests/sys/cam/Makefile
+++ b/tests/sys/cam/Makefile
@@ -1,7 +1,14 @@
.include <src.opts.mk>
+PACKAGE= tests
+
TESTSDIR= ${TESTSBASE}/sys/cam
TESTS_SUBDIRS+= ctl
+ATF_TESTS_SH+= periph_unload
+
+# Loading and unloading ctl(4) perturbs CAM for anything running alongside.
+TEST_METADATA.periph_unload+= is_exclusive="true"
+
.include <bsd.test.mk>
diff --git a/tests/sys/cam/periph_unload.sh b/tests/sys/cam/periph_unload.sh
new file mode 100644
--- /dev/null
+++ b/tests/sys/cam/periph_unload.sh
@@ -0,0 +1,71 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Advanced Micro Devices, Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+atf_test_case devmatch_after_unload cleanup
+
+devmatch_after_unload_head()
+{
+ atf_set "descr" "XPT_DEV_MATCH after unloading a periph driver; an" \
+ "unfixed kernel panics here rather than failing"
+ atf_set "require.user" "root"
+}
+
+devmatch_after_unload_body()
+{
+ if kldstat -q -m ctl; then
+ atf_skip "ctl(4) is already present"
+ fi
+ kldload ctl || atf_skip "cannot load ctl(4)"
+ touch ctl.loaded
+
+ # Nothing has attached, so this is expected to succeed.
+ atf_check kldunload ctl
+ rm -f ctl.loaded
+
+ # devlist issues XPT_DEV_MATCH, which walks periph_drivers[] to the
+ # NULL terminator. Before the fix the unload left the last slot
+ # pointing into the unmapped module and this faulted in the kernel,
+ # so the check is that it returns at all.
+ #
+ # Only the removal of the last entry is covered. A driver loaded at
+ # runtime is always last, and ctl(4) is the only one in the tree that
+ # unregisters, so the duplicate left by removing any other entry
+ # cannot be reached from userland.
+ atf_check -o ignore camcontrol devlist
+}
+
+devmatch_after_unload_cleanup()
+{
+ # Only undo what the body did: ctl(4) may belong to the operator.
+ if [ -f ctl.loaded ]; then
+ kldunload ctl > /dev/null 2>&1
+ fi
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case devmatch_after_unload
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 5, 8:57 AM (23 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42192021
Default Alt Text
D62322.1796461022.diff (3 KB)
Attached To
Mode
D62322: cam: Fix the array terminator when unregistering a periph driver
Attached
Detach File
Event Timeline