aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Zhilin <mizhka@FreeBSD.org>2024-04-13 09:59:24 +0000
committerMichael Zhilin <mizhka@FreeBSD.org>2024-04-19 07:23:36 +0000
commite7a1904fe1ced461b2a31f03b6592ae6564a243a (patch)
tree75f75f276130e0d16a407a64a00d601465cf4386
parent792937105454bed3bd23ff169fe2841265be095f (diff)
downloadsrc-e7a1904fe1ced461b2a31f03b6592ae6564a243a.tar.gz
src-e7a1904fe1ced461b2a31f03b6592ae6564a243a.zip
snd_hda: fix "duplicated free" on module unloading
This is trivial fix of hdacc_detach to avoid duplicated free on snd_hda unloading. The first try of detaching (kldunload) may results into "device busy" error, but codec->fgs is freed by detach. Second try attempts to free codec->fgs again and system panicks. Here is example: pcm0: unregister: channel pcm0:virtual:dsp0.vp0 busy (pid 3428) pulseaudio[3428] [oss] module-oss.c: DSP shutdown. pcm0: detached hdaa0: detached panic: Duplicate free of 0xfffff80412ee7d20 from zone 0xfffffe006bc0ba00 (malloc-32) slab 0xfffff80412ee7fc8(105) cpuid = 6 time = 1712999565 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0202f859e0 vpanic() at vpanic+0x135/frame 0xfffffe0202f85b10 panic() at panic+0x43/frame 0xfffffe0202f85b70 uma_dbg_free() at uma_dbg_free+0x105/frame 0xfffffe0202f85b90 uma_zfree_arg() at uma_zfree_arg+0x95/frame 0xfffffe0202f85be0 free() at free+0xa1/frame 0xfffffe0202f85c20 hdacc_detach() at hdacc_detach+0x2f/frame 0xfffffe0202f85c40 device_detach() at device_detach+0x197/frame 0xfffffe0202f85c80 devclass_driver_deleted() at devclass_driver_deleted+0x66/frame 0xfffffe0202f85c devclass_delete_driver() at devclass_delete_driver+0x81/frame 0xfffffe0202f85d00 driver_module_handler() at driver_module_handler+0xff/frame 0xfffffe0202f85d50 module_unload() at module_unload+0x32/frame 0xfffffe0202f85d70 linker_file_unload() at linker_file_unload+0x1eb/frame 0xfffffe0202f85db0 kern_kldunload() at kern_kldunload+0x18e/frame 0xfffffe0202f85e00 amd64_syscall() at amd64_syscall+0x153/frame 0xfffffe0202f85f30 fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe0202f85f30 MFC after: 3 days Reviewed by: markj, christos Differential Revision: https://reviews.freebsd.org/D44778 Sponsored by: Postgres Professional (cherry picked from commit bed0b2146faa2e9a445d9f9196c7b46f50034631)
-rw-r--r--sys/dev/sound/pci/hda/hdacc.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sys/dev/sound/pci/hda/hdacc.c b/sys/dev/sound/pci/hda/hdacc.c
index afcc145626e1..86c50a88f3e0 100644
--- a/sys/dev/sound/pci/hda/hdacc.c
+++ b/sys/dev/sound/pci/hda/hdacc.c
@@ -541,9 +541,10 @@ hdacc_detach(device_t dev)
struct hdacc_softc *codec = device_get_softc(dev);
int error;
- error = device_delete_children(dev);
+ if ((error = device_delete_children(dev)) != 0)
+ return (error);
free(codec->fgs, M_HDACC);
- return (error);
+ return (0);
}
static int