Index | Thread | Search

From:
Vitaliy Makkoveev <mvs@openbsd.org>
Subject:
Re: sysctl(2): unlock sysctl_audio()
To:
Mark Kettenis <mark.kettenis@xs4all.nl>
Cc:
tech@openbsd.org
Date:
Sun, 18 Aug 2024 22:53:16 +0300

Download raw body.

Thread
On Sun, Aug 18, 2024 at 09:06:14PM +0200, Mark Kettenis wrote:
> > Date: Sun, 18 Aug 2024 21:59:28 +0300
> > From: Vitaliy Makkoveev <mvs@openbsd.org>
> > 
> > It is the only KERN_AUDIO_RECORD. `audio_record_enable' is atomically
> > accessed integer.
> > 
> > I have no ability to test this diff with gcc archs. llvm allows empty
> > 'switch' blocks, but I'm not sure in gcc.
> 
> Just put in a:
> 
>      	 default:
> 		break;
> 
> ?
> 

Done, thanks.

Index: sys/dev/audio.c
===================================================================
RCS file: /cvs/src/sys/dev/audio.c,v
diff -u -p -r1.207 audio.c
--- sys/dev/audio.c	7 Jun 2024 08:48:10 -0000	1.207
+++ sys/dev/audio.c	18 Aug 2024 19:49:31 -0000
@@ -27,11 +27,17 @@
 #include <sys/malloc.h>
 #include <sys/device.h>
 #include <sys/audioio.h>
+#include <sys/atomic.h>
 #include <dev/audio_if.h>
 #include <dev/mulaw.h>
 #include "audio.h"
 #include "wskbd.h"
 
+/*
+ * Locks used to protect data:
+ *	a	atomic
+ */
+
 #ifdef AUDIO_DEBUG
 #define DPRINTF(...)				\
 	do {					\
@@ -225,7 +231,7 @@ struct mutex audio_lock = MUTEX_INITIALI
  * Global flag to control if audio recording is enabled when the
  * mixerctl setting is record.enable=sysctl
  */
-int audio_record_enable = 0;
+int audio_record_enable = 0;	/* [a] */
 
 #ifdef AUDIO_DEBUG
 /*
@@ -590,7 +596,7 @@ audio_rintr(void *addr)
 
 	sc->rec.pos += sc->rec.blksz;
 	if ((sc->record_enable == MIXER_RECORD_ENABLE_SYSCTL &&
-	    !audio_record_enable) ||
+	    atomic_load_int(&audio_record_enable) == 0) ||
 	    sc->record_enable == MIXER_RECORD_ENABLE_OFF) {
 		ptr = audio_buf_wgetblk(&sc->rec, &count);
 		audio_fill_sil(sc, ptr, sc->rec.blksz);
Index: sys/kern/kern_sysctl.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
diff -u -p -r1.439 kern_sysctl.c
--- sys/kern/kern_sysctl.c	14 Aug 2024 17:52:47 -0000	1.439
+++ sys/kern/kern_sysctl.c	18 Aug 2024 19:49:34 -0000
@@ -455,11 +455,6 @@ kern_sysctl_dirs(int top_name, int *name
 		return witness_sysctl(name, namelen, oldp, oldlenp,
 		    newp, newlen);
 #endif
-#if NAUDIO > 0
-	case KERN_AUDIO:
-		return (sysctl_audio(name, namelen, oldp, oldlenp,
-		    newp, newlen));
-#endif
 #if NVIDEO > 0
 	case KERN_VIDEO:
 		return (sysctl_video(name, namelen, oldp, oldlenp,
@@ -488,6 +483,16 @@ kern_sysctl(int *name, u_int namelen, vo
 
 	/* dispatch the non-terminal nodes first */
 	if (namelen != 1) {
+		switch (name[0]) {
+#if NAUDIO > 0
+		case KERN_AUDIO:
+			return (sysctl_audio(name, namelen, oldp, oldlenp,
+			    newp, newlen));
+#endif
+		default:
+			break;
+		}
+
 		savelen = *oldlenp;
 		if ((error = sysctl_vslock(oldp, savelen)))
 			return (error);