Index | Thread | Search

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

Download raw body.

Thread
> 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;

?

> 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 18:53:12 -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 18:53:12 -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,14 @@ 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
> +		}
> +
>  		savelen = *oldlenp;
>  		if ((error = sysctl_vslock(oldp, savelen)))
>  			return (error);
> 
>