git: 810530aa2648 - main - sound: Add device status string to sndstat nvlist
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=810530aa2648812860e84d951d9cf96dfd24e595 commit 810530aa2648812860e84d951d9cf96dfd24e595 Author: Christos Margiolis AuthorDate: 2024-07-27 11:54:14 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:54:14 + sound: Add device status string to sndstat nvlist Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D46163 --- share/man/man4/sndstat.4| 6 +- sys/dev/sound/pcm/sndstat.c | 1 + sys/sys/sndstat.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/share/man/man4/sndstat.4 b/share/man/man4/sndstat.4 index 2af0619961d8..eca1e391f130 100644 --- a/share/man/man4/sndstat.4 +++ b/share/man/man4/sndstat.4 @@ -29,7 +29,7 @@ .\" .\" Note: The date here should be updated whenever a non-trivial .\" change is made to the manual page. -.Dd June 5, 2024 +.Dd July 26, 2024 .Dt SNDSTAT 4 .Os .Sh NAME @@ -74,6 +74,7 @@ dsps (NVLIST ARRAY): 1 max_chn (NUMBER): 2 provider_info (NVLIST): unit (NUMBER): 0 + status (STRING): on hdaa0 bitperfect (BOOL): FALSE pvchan (NUMBER): 1 rvchan (NUMBER): 0 @@ -169,6 +170,9 @@ provider, there are a number of name/value pairs inside this field: .Bl -tag -width ".Dv channel_info" .It Dv unit Sound card unit. +.It Dv status +Status string. +Usually reports the driver the device is attached on. .It Dv bitperfect Whether the sound card has bit-perfect mode enabled. .It Dv pvchan diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index 753531f3694e..fda7a2ad6d48 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -440,6 +440,7 @@ sndstat_build_sound4_nvlist(struct snddev_info *d, nvlist_t **dip) nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_UNIT, device_get_unit(d->dev)); // XXX: I want signed integer here + nvlist_add_string(sound4di, SNDST_DSPS_SOUND4_STATUS, d->status); nvlist_add_bool( sound4di, SNDST_DSPS_SOUND4_BITPERFECT, d->flags & SD_F_BITPERFECT); nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_PVCHAN, d->pvchancount); diff --git a/sys/sys/sndstat.h b/sys/sys/sndstat.h index 6fef6502ec89..2f2965bb3d05 100644 --- a/sys/sys/sndstat.h +++ b/sys/sys/sndstat.h @@ -70,6 +70,7 @@ struct sndstioc_nv_arg { */ #define SNDST_DSPS_SOUND4_PROVIDER "sound(4)" #define SNDST_DSPS_SOUND4_UNIT "unit" +#define SNDST_DSPS_SOUND4_STATUS "status" #define SNDST_DSPS_SOUND4_BITPERFECT "bitperfect" #define SNDST_DSPS_SOUND4_PVCHAN "pvchan" #define SNDST_DSPS_SOUND4_RVCHAN "rvchan"
git: a62837175770 - main - sound: Add *vchanrate and *vchanformat to sndstat nvlist
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=a6283717577066b0ff6c62053145470ff4134051 commit a6283717577066b0ff6c62053145470ff4134051 Author: Christos Margiolis AuthorDate: 2024-07-27 11:54:21 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:54:21 + sound: Add *vchanrate and *vchanformat to sndstat nvlist Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D46164 --- share/man/man4/sndstat.4| 12 sys/dev/sound/pcm/sndstat.c | 8 sys/sys/sndstat.h | 4 3 files changed, 24 insertions(+) diff --git a/share/man/man4/sndstat.4 b/share/man/man4/sndstat.4 index eca1e391f130..2f745f418b79 100644 --- a/share/man/man4/sndstat.4 +++ b/share/man/man4/sndstat.4 @@ -77,7 +77,11 @@ dsps (NVLIST ARRAY): 1 status (STRING): on hdaa0 bitperfect (BOOL): FALSE pvchan (NUMBER): 1 + pvchanrate (NUMBER): 48000 + pvchanformat (NUMBER): 0x0010 rvchan (NUMBER): 0 + rvchanrate (NUMBER): 48000 + rvchanformat (NUMBER): 0x0010 channel_info (NVLIST_ARRAY): 1 name (STRING): pcm0:virtual_play:dsp0.vp0 parentchan (STRING): pcm0:play:dsp0.p0 @@ -177,8 +181,16 @@ Usually reports the driver the device is attached on. Whether the sound card has bit-perfect mode enabled. .It Dv pvchan Number of playback virtual channels. +.It Dv pvchanrate +Playback virtual channel sample rate. +.It Dv pvchanformat +Playback virtual channel format. .It Dv rvchan Number of recording virtual channels. +.It Dv rvchanrate +Recording virtual channel sample rate. +.It Dv rvchanformat +Recording virtual channel format. .It Dv channel_info Channel information. There are a number of name/value pairs inside this field: diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index fda7a2ad6d48..b0d2c5b6ca21 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -444,7 +444,15 @@ sndstat_build_sound4_nvlist(struct snddev_info *d, nvlist_t **dip) nvlist_add_bool( sound4di, SNDST_DSPS_SOUND4_BITPERFECT, d->flags & SD_F_BITPERFECT); nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_PVCHAN, d->pvchancount); + nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_PVCHANRATE, + d->pvchanrate); + nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_PVCHANFORMAT, + d->pvchanformat); nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_RVCHAN, d->rvchancount); + nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_RVCHANRATE, + d->rvchanrate); + nvlist_add_number(sound4di, SNDST_DSPS_SOUND4_RVCHANFORMAT, + d->rvchanformat); nchan = 0; CHN_FOREACH(c, d, channels.pcm) { diff --git a/sys/sys/sndstat.h b/sys/sys/sndstat.h index 2f2965bb3d05..f7d0b2f29bd5 100644 --- a/sys/sys/sndstat.h +++ b/sys/sys/sndstat.h @@ -73,7 +73,11 @@ struct sndstioc_nv_arg { #define SNDST_DSPS_SOUND4_STATUS "status" #define SNDST_DSPS_SOUND4_BITPERFECT "bitperfect" #define SNDST_DSPS_SOUND4_PVCHAN "pvchan" +#define SNDST_DSPS_SOUND4_PVCHANRATE "pvchanrate" +#define SNDST_DSPS_SOUND4_PVCHANFORMAT "pvchanformat" #define SNDST_DSPS_SOUND4_RVCHAN "rvchan" +#define SNDST_DSPS_SOUND4_RVCHANRATE "rvchanrate" +#define SNDST_DSPS_SOUND4_RVCHANFORMAT "rvchanformat" #define SNDST_DSPS_SOUND4_CHAN_INFO"channel_info" #define SNDST_DSPS_SOUND4_CHAN_NAME"name" #define SNDST_DSPS_SOUND4_CHAN_PARENTCHAN "parentchan"
git: bd5bcc848c57 - main - sound: Add OSS channel capabilities to sndstat nvlist
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=bd5bcc848c5764229926ad27a4bd77af4f87d189 commit bd5bcc848c5764229926ad27a4bd77af4f87d189 Author: Christos Margiolis AuthorDate: 2024-07-27 11:54:27 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:54:27 + sound: Add OSS channel capabilities to sndstat nvlist Assignment taken from dsp_oss_engineinfo(). Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D46166 --- share/man/man4/sndstat.4| 3 +++ sys/dev/sound/pcm/sndstat.c | 7 ++- sys/sys/sndstat.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/share/man/man4/sndstat.4 b/share/man/man4/sndstat.4 index 2f745f418b79..2fc55f0045c1 100644 --- a/share/man/man4/sndstat.4 +++ b/share/man/man4/sndstat.4 @@ -86,6 +86,7 @@ dsps (NVLIST ARRAY): 1 name (STRING): pcm0:virtual_play:dsp0.vp0 parentchan (STRING): pcm0:play:dsp0.p0 unit (NUMBER): 1 + caps (NUMBER): 0x073200 latency (NUMBER): 2 rate (NUMBER): 48000 format (NUMBER): 0x201000 @@ -201,6 +202,8 @@ Channel name. Parent channel name (e.g., in the case of virtual channels). .It Dv unit Channel unit. +.It Dv caps +OSS capabilities. .It Dv latency Latency. .It Dv rate diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index b0d2c5b6ca21..f09fa7139884 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -385,7 +385,7 @@ sndstat_build_sound4_nvlist(struct snddev_info *d, nvlist_t **dip) struct pcm_channel *c; struct pcm_feeder *f; struct sbuf sb; - uint32_t maxrate, minrate, fmts, minchn, maxchn; + uint32_t maxrate, minrate, fmts, minchn, maxchn, caps; nvlist_t *di = NULL, *sound4di = NULL, *diinfo = NULL, *cdi = NULL; int err, nchan; @@ -467,10 +467,15 @@ sndstat_build_sound4_nvlist(struct snddev_info *d, nvlist_t **dip) CHN_LOCK(c); + caps = PCM_CAP_REALTIME | PCM_CAP_MMAP | PCM_CAP_TRIGGER | + ((c->flags & CHN_F_VIRTUAL) ? PCM_CAP_VIRTUAL : 0) | + ((c->direction == PCMDIR_PLAY) ? PCM_CAP_OUTPUT : PCM_CAP_INPUT); + nvlist_add_string(cdi, SNDST_DSPS_SOUND4_CHAN_NAME, c->name); nvlist_add_string(cdi, SNDST_DSPS_SOUND4_CHAN_PARENTCHAN, c->parentchannel != NULL ? c->parentchannel->name : ""); nvlist_add_number(cdi, SNDST_DSPS_SOUND4_CHAN_UNIT, nchan++); + nvlist_add_number(cdi, SNDST_DSPS_SOUND4_CHAN_CAPS, caps); nvlist_add_number(cdi, SNDST_DSPS_SOUND4_CHAN_LATENCY, c->latency); nvlist_add_number(cdi, SNDST_DSPS_SOUND4_CHAN_RATE, c->speed); diff --git a/sys/sys/sndstat.h b/sys/sys/sndstat.h index f7d0b2f29bd5..6fd2e06ac483 100644 --- a/sys/sys/sndstat.h +++ b/sys/sys/sndstat.h @@ -82,6 +82,7 @@ struct sndstioc_nv_arg { #define SNDST_DSPS_SOUND4_CHAN_NAME"name" #define SNDST_DSPS_SOUND4_CHAN_PARENTCHAN "parentchan" #define SNDST_DSPS_SOUND4_CHAN_UNIT"unit" +#define SNDST_DSPS_SOUND4_CHAN_CAPS"caps" #define SNDST_DSPS_SOUND4_CHAN_LATENCY "latency" #define SNDST_DSPS_SOUND4_CHAN_RATE"rate" #define SNDST_DSPS_SOUND4_CHAN_FORMAT "format"
git: cb00491fbc51 - main - sound examples: Organize files in directories
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=cb00491fbc51751fe166056cc69e23beeb26fee4 commit cb00491fbc51751fe166056cc69e23beeb26fee4 Author: Christos Margiolis AuthorDate: 2024-07-27 11:54:35 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:54:35 + sound examples: Organize files in directories More examples will be added, so it's better to be organized. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45968 --- share/examples/Makefile | 11 +++ share/examples/sound/{ => oss}/README| 0 share/examples/sound/{ => oss}/basic.c | 0 share/examples/sound/{ => oss}/midi.c| 0 share/examples/sound/{ => oss}/ossinit.h | 0 share/examples/sound/{ => oss}/ossmidi.h | 0 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/share/examples/Makefile b/share/examples/Makefile index 61e21f9350c1..8839075452af 100644 --- a/share/examples/Makefile +++ b/share/examples/Makefile @@ -314,12 +314,15 @@ SE_SCSI_TARGET= \ scsi_cmds.c SE_DIRS+= sound -SE_SOUND= \ +SE_SOUND= + +SE_DIRS+= sound/oss +SE_SOUND_OSS= \ + README \ basic.c \ - ossinit.h \ - ossmidi.h \ midi.c \ - README + ossinit.h \ + ossmidi.h SE_DIRS+= sunrpc SE_SUNRPC= Makefile diff --git a/share/examples/sound/README b/share/examples/sound/oss/README similarity index 100% rename from share/examples/sound/README rename to share/examples/sound/oss/README diff --git a/share/examples/sound/basic.c b/share/examples/sound/oss/basic.c similarity index 100% rename from share/examples/sound/basic.c rename to share/examples/sound/oss/basic.c diff --git a/share/examples/sound/midi.c b/share/examples/sound/oss/midi.c similarity index 100% rename from share/examples/sound/midi.c rename to share/examples/sound/oss/midi.c diff --git a/share/examples/sound/ossinit.h b/share/examples/sound/oss/ossinit.h similarity index 100% rename from share/examples/sound/ossinit.h rename to share/examples/sound/oss/ossinit.h diff --git a/share/examples/sound/ossmidi.h b/share/examples/sound/oss/ossmidi.h similarity index 100% rename from share/examples/sound/ossmidi.h rename to share/examples/sound/oss/ossmidi.h
git: f08ecd24a19b - main - sound examples: Add sndstat nvlist example
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=f08ecd24a19ba772701fc35caaad92b9fe91fa9c commit f08ecd24a19ba772701fc35caaad92b9fe91fa9c Author: Christos Margiolis AuthorDate: 2024-07-27 11:54:40 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:54:40 + sound examples: Add sndstat nvlist example Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45969 --- share/examples/Makefile | 3 +- share/examples/sound/sndstat_nv.c | 206 ++ 2 files changed, 208 insertions(+), 1 deletion(-) diff --git a/share/examples/Makefile b/share/examples/Makefile index 8839075452af..211ec2272c05 100644 --- a/share/examples/Makefile +++ b/share/examples/Makefile @@ -314,7 +314,8 @@ SE_SCSI_TARGET= \ scsi_cmds.c SE_DIRS+= sound -SE_SOUND= +SE_SOUND= \ + sndstat_nv.c SE_DIRS+= sound/oss SE_SOUND_OSS= \ diff --git a/share/examples/sound/sndstat_nv.c b/share/examples/sound/sndstat_nv.c new file mode 100644 index ..1056c1f4a08f --- /dev/null +++ b/share/examples/sound/sndstat_nv.c @@ -0,0 +1,206 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 The FreeBSD Foundation + * + * This software was developed by Christos Margiolis + * under sponsorship from the FreeBSD Foundation. + * + * 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. + */ + +#include +#include + +#include +#include +#include +#include +#include + +/* + * Example program showcasing how to use sndstat(4)'s nvlist interface, and how + * to fetch all currently supported fields, with the appropriate error checks. + * + * For more detailed information on what each nvlist field represents, please + * read sndstat(4)'s man page. + */ + +int +main(int argc, char *argv[]) +{ + nvlist_t *nvl; + const nvlist_t * const *di; + const nvlist_t * const *cdi; + struct sndstioc_nv_arg arg; + size_t nitems, nchans, i, j; + int fd, pchan, rchan; + + if ((fd = open("/dev/sndstat", O_RDONLY)) < 0) + err(1, "open(/dev/sndstat)"); + + if (ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL) < 0) + err(1, "ioctl(SNDSTIOC_REFRESH_DEVS)"); + + arg.nbytes = 0; + arg.buf = NULL; + if (ioctl(fd, SNDSTIOC_GET_DEVS, &arg) < 0) + err(1, "ioctl(SNDSTIOC_GET_DEVS#1)"); + + if ((arg.buf = malloc(arg.nbytes)) == NULL) + err(1, "malloc"); + + if (ioctl(fd, SNDSTIOC_GET_DEVS, &arg) < 0) + err(1, "ioctl(SNDSTIOC_GET_DEVS#2)"); + + if ((nvl = nvlist_unpack(arg.buf, arg.nbytes, 0)) == NULL) + err(1, "nvlist_unpack"); + + if (nvlist_empty(nvl) || !nvlist_exists(nvl, SNDST_DSPS)) + errx(1, "no soundcards attached"); + + di = nvlist_get_nvlist_array(nvl, SNDST_DSPS, &nitems); + for (i = 0; i < nitems; i++) { +#define NV(type, item) \ + nvlist_get_ ## type (di[i], SNDST_DSPS_ ## item) + printf("nameunit=%s\n", NV(string, NAMEUNIT)); + printf("\tfrom_user=%d\n", NV(bool, FROM_USER)); + printf("\tdevnode=%s\n", NV(string, DEVNODE)); + printf("\tdesc=%s\n", NV(string, DESC)); + printf("\tprovider=%s\n", NV(string, PROVIDER)); + printf("\tpchan=%d\n", (int)NV(number, PCHAN)); + printf("\trchan=%d\n", (int)NV(number, RCHAN)); + pchan = NV(number, PCHAN); + rchan = NV(number, RCHAN); +#undef NV + + if (pchan && !nvlist_exists(di[i], SNDST_DSPS_INFO_PLAY))
git: 95eb4b873b6a - main - sound tests: Add sndstat nvlist ATF test
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=95eb4b873b6a8b527c5bd78d7191975dfca38998 commit 95eb4b873b6a8b527c5bd78d7191975dfca38998 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:03 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:03 + sound tests: Add sndstat nvlist ATF test Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45901 --- tests/sys/Makefile| 1 + tests/sys/sound/Makefile | 9 ++ tests/sys/sound/sndstat.c | 214 ++ 3 files changed, 224 insertions(+) diff --git a/tests/sys/Makefile b/tests/sys/Makefile index 7167f77ff471..e64268e5a397 100644 --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -30,6 +30,7 @@ TESTS_SUBDIRS+= netpfil TESTS_SUBDIRS+=opencrypto TESTS_SUBDIRS+=posixshm TESTS_SUBDIRS+=ses +TESTS_SUBDIRS+=sound TESTS_SUBDIRS+=sys TESTS_SUBDIRS+=vfs TESTS_SUBDIRS+=vm diff --git a/tests/sys/sound/Makefile b/tests/sys/sound/Makefile new file mode 100644 index ..fb731fb8ab61 --- /dev/null +++ b/tests/sys/sound/Makefile @@ -0,0 +1,9 @@ +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/sys/sound + +ATF_TESTS_C+= sndstat + +LDFLAGS+= -lnv + +.include diff --git a/tests/sys/sound/sndstat.c b/tests/sys/sound/sndstat.c new file mode 100644 index ..7c030dfa8b58 --- /dev/null +++ b/tests/sys/sound/sndstat.c @@ -0,0 +1,214 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 The FreeBSD Foundation + * + * This software was developed by Christos Margiolis + * under sponsorship from the FreeBSD Foundation. + * + * 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. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static void +load_dummy(void) +{ + if (kldload("snd_dummy.ko") < 0 && errno != EEXIST) + atf_tc_skip("snd_dummy.ko not found"); +} + +ATF_TC(sndstat_nv); +ATF_TC_HEAD(sndstat_nv, tc) +{ + atf_tc_set_md_var(tc, "descr", "/dev/sndstat nvlist test"); +} + +ATF_TC_BODY(sndstat_nv, tc) +{ + nvlist_t *nvl; + const nvlist_t * const *di; + const nvlist_t * const *cdi; + struct sndstioc_nv_arg arg; + size_t nitems, nchans, i, j; + int fd, rc; + int pchan, rchan; + + load_dummy(); + + if ((fd = open("/dev/sndstat", O_RDONLY)) < 0) + atf_tc_skip("/dev/sndstat not found, load sound(4)"); + + rc = ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL); + ATF_REQUIRE_EQ(rc, 0); + + arg.nbytes = 0; + arg.buf = NULL; + rc = ioctl(fd, SNDSTIOC_GET_DEVS, &arg); + ATF_REQUIRE_EQ_MSG(rc, 0, "ioctl(SNDSTIOC_GET_DEVS#1) failed"); + + arg.buf = malloc(arg.nbytes); + ATF_REQUIRE(arg.buf != NULL); + + rc = ioctl(fd, SNDSTIOC_GET_DEVS, &arg); + ATF_REQUIRE_EQ_MSG(rc, 0, "ioctl(SNDSTIOC_GET_DEVS#2) failed"); + + nvl = nvlist_unpack(arg.buf, arg.nbytes, 0); + ATF_REQUIRE(nvl != NULL); + + if (nvlist_empty(nvl) || !nvlist_exists(nvl, SNDST_DSPS)) + atf_tc_skip("no soundcards attached"); + + di = nvlist_get_nvlist_array(nvl, SNDST_DSPS, &nitems); + for (i = 0; i < nitems; i++) { +#define NV(type, item) do {\ + ATF_REQUIRE_MSG(nvlist_exists(di[i], SNDST_DSPS_ ## item), \ + "SNDST_DSPS_" #item " does not exist"); \ +
git: c15c9315b2cb - main - sound: Implement dummy driver
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=c15c9315b2cb7601cc337f7d5a8e124f4b2d5861 commit c15c9315b2cb7601cc337f7d5a8e124f4b2d5861 Author: Christos Margiolis AuthorDate: 2024-07-27 11:54:45 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:54:45 + sound: Implement dummy driver Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45967 --- share/man/man4/Makefile | 1 + share/man/man4/snd_dummy.4 | 69 +++ sys/dev/sound/dummy.c | 353 sys/modules/sound/driver/Makefile | 1 + sys/modules/sound/driver/dummy/Makefile | 7 + 5 files changed, 431 insertions(+) diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 36d945d64a60..b4a8e484b137 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -528,6 +528,7 @@ MAN=aac.4 \ snd_cmi.4 \ snd_cs4281.4 \ snd_csa.4 \ + snd_dummy.4 \ snd_emu10k1.4 \ snd_emu10kx.4 \ snd_envy24.4 \ diff --git a/share/man/man4/snd_dummy.4 b/share/man/man4/snd_dummy.4 new file mode 100644 index ..2b9d26d318ef --- /dev/null +++ b/share/man/man4/snd_dummy.4 @@ -0,0 +1,69 @@ +.\"- +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.\" Copyright (c) 2024 The FreeBSD Foundation +.\" +.\" Portions of this software were developed by Christos Margiolis +.\" under sponsorship from the FreeBSD Foundation. +.\" +.\" 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. +.\" +.Dd July 15, 2024 +.Dt SND_DUMMY 4 +.Os +.Sh NAME +.Nm snd_dummy +.Nd Dummy audio driver +.Sh SYNOPSIS +To load the driver at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +snd_dummy_load="YES" +.Ed +.Sh DESCRIPTION +The +.Nm +driver implements a virtual testing device, meaning it does not correspond to a +physical sound card. +It is intended for testing, so that test programs do not need to rely on +hardware being present in the machine in order to run. +.Pp +The driver attaches as a regular PCM device, with two channels (one playback +and one recording), as well as a mixer. +.Pp +Playback works by discarding all input, and recording by returning silence +(zeros). +.Sh SEE ALSO +.Xr sound 4 , +.Xr loader.conf 5 , +.Xr loader 8 +.Sh AUTHORS +The +.Nm +driver was implemented by +.An Christos Margiolis Aq Mt chris...@freebsd.org +under sponsorship from the +.Fx +Foundation. +.Sh CAVEATS +Because the driver automatically attaches once the module is loaded, it can +only be attached once. diff --git a/sys/dev/sound/dummy.c b/sys/dev/sound/dummy.c new file mode 100644 index ..f8193a73fcc8 --- /dev/null +++ b/sys/dev/sound/dummy.c @@ -0,0 +1,353 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 The FreeBSD Foundation + * + * This software was developed by Christos Margiolis + * under sponsorship from the FreeBSD Foundation. + * + * 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 EXPRE
git: 8ca73331ef81 - main - mixer(8): Make mute and recsrc argument parsing more robust
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=8ca73331ef810cd0e0b9e3c37cddc1d89fbe8c6b commit 8ca73331ef810cd0e0b9e3c37cddc1d89fbe8c6b Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:09 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:09 + mixer(8): Make mute and recsrc argument parsing more robust For the deprecated argument interfaces of the mute (1, 0, ^) and recsrc (+, -, =, ^) controls, we only check the first character of the argument, which means that an argument such as "vol.mute=10" would be valid. Fix this by checking the whole argument string. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45973 --- usr.sbin/mixer/mixer.c | 21 ++--- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index 07dd16536495..109d3ad09bc5 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -426,11 +426,14 @@ mod_mute(struct mix_dev *d, void *p) m = d->parent_mixer; cp = mixer_get_ctl(m->dev, C_MUT); val = p; - if (strncmp(val, "off", strlen(val)) == 0 || *val == '0') + if (strncmp(val, "off", strlen(val)) == 0 || + strncmp(val, "0", strlen(val)) == 0) opt = MIX_UNMUTE; - else if (strncmp(val, "on", strlen(val)) == 0 || *val == '1') + else if (strncmp(val, "on", strlen(val)) == 0 || + strncmp(val, "1", strlen(val)) == 0) opt = MIX_MUTE; - else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^') + else if (strncmp(val, "toggle", strlen(val)) == 0 || + strncmp(val, "^", strlen(val)) == 0) opt = MIX_TOGGLEMUTE; else { warnx("%s: no such modifier", val); @@ -459,13 +462,17 @@ mod_recsrc(struct mix_dev *d, void *p) m = d->parent_mixer; cp = mixer_get_ctl(m->dev, C_SRC); val = p; - if (strncmp(val, "add", strlen(val)) == 0 || *val == '+') + if (strncmp(val, "add", strlen(val)) == 0 || + strncmp(val, "+", strlen(val)) == 0) opt = MIX_ADDRECSRC; - else if (strncmp(val, "remove", strlen(val)) == 0 || *val == '-') + else if (strncmp(val, "remove", strlen(val)) == 0 || + strncmp(val, "-", strlen(val)) == 0) opt = MIX_REMOVERECSRC; - else if (strncmp(val, "set", strlen(val)) == 0 || *val == '=') + else if (strncmp(val, "set", strlen(val)) == 0 || + strncmp(val, "=", strlen(val)) == 0) opt = MIX_SETRECSRC; - else if (strncmp(val, "toggle", strlen(val)) == 0 || *val == '^') + else if (strncmp(val, "toggle", strlen(val)) == 0 || + strncmp(val, "^", strlen(val)) == 0) opt = MIX_TOGGLERECSRC; else { warnx("%s: no such modifier", val);
git: 94a86f3f6920 - main - mixer(8): Add tests
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=94a86f3f69205a6de3c07ae60daf4f5f920e9b82 commit 94a86f3f69205a6de3c07ae60daf4f5f920e9b82 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:14 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:14 + mixer(8): Add tests Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45974 --- usr.sbin/mixer/Makefile| 3 + usr.sbin/mixer/tests/Makefile | 3 + usr.sbin/mixer/tests/mixer_test.sh | 285 + 3 files changed, 291 insertions(+) diff --git a/usr.sbin/mixer/Makefile b/usr.sbin/mixer/Makefile index 7789a28e99ad..9e96c2f2d2e8 100644 --- a/usr.sbin/mixer/Makefile +++ b/usr.sbin/mixer/Makefile @@ -5,4 +5,7 @@ SRCS= ${PROG}.c MAN= ${PROG}.8 LDFLAGS+= -lmixer +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/usr.sbin/mixer/tests/Makefile b/usr.sbin/mixer/tests/Makefile new file mode 100644 index ..9a5bb3a183ab --- /dev/null +++ b/usr.sbin/mixer/tests/Makefile @@ -0,0 +1,3 @@ +ATF_TESTS_SH+= mixer_test + +.include diff --git a/usr.sbin/mixer/tests/mixer_test.sh b/usr.sbin/mixer/tests/mixer_test.sh new file mode 100755 index ..e1321ad9ee13 --- /dev/null +++ b/usr.sbin/mixer/tests/mixer_test.sh @@ -0,0 +1,285 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 The FreeBSD Foundation +# +# This software was developed by Christos Margiolis +# under sponsorship from the FreeBSD Foundation. +# +# 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. + +mixer_exists() +{ + if ! mixer >/dev/null 2>&1; then + atf_skip "no mixer available" + fi +} + +save_conf() +{ + atf_check -o save:test_mixer_conf mixer -o +} + +restore_conf() +{ + mixer_exists + test -r "test_mixer_conf" && mixer $(cat test_mixer_conf) +} + +load_dummy() +{ + if ! kldload -n snd_dummy; then + atf_skip "cannot load snd_dummy.ko" + fi +} + +set_default() +{ + deflt_unit="$(mixer | grep ^pcm | cut -f1 -d:)" + dummy_unit="$(mixer -a | grep "Dummy Audio Device" | cut -f1 -d:)" + + atf_check -o save:test_mixer_deflt_unit echo ${deflt_unit} + atf_check -o save:test_mixer_dummy_unit echo ${dummy_unit} + + # Set the dummy as the default + mixer -d ${dummy_unit} +} + +restore_default() +{ + test -r "test_mixer_deflt_unit" && mixer -d $(cat test_mixer_deflt_unit) +} + +atf_test_case o_flag cleanup +o_flag_head() +{ + atf_set "descr" "Verify that the output of the -o flag can be used " \ + "as valid input" +} +o_flag_body() +{ + load_dummy + mixer_exists + set_default + + atf_check -o ignore -e empty mixer $(mixer -o) +} +o_flag_cleanup() +{ + restore_default +} + +atf_test_case d_flag cleanup +d_flag_head() +{ + atf_set "descr" "Test default unit setting" +} +d_flag_body() +{ + load_dummy + mixer_exists + set_default + + dev="${dummy_unit}" + unit=$(echo ${dev} | sed 's/pcm//') + + atf_check -o ignore -e empty mixer -d ${dev} + atf_check -o ignore -e empty mixer -d ${unit} +} +d_flag_cleanup() +{ + restore_default +} + +atf_test_case volume cleanup +volume_head() +{ + atf_set "descr" "Test volume setting" +} +volume_body() +{ + load_dummy + mixer_exists + set_default + save_conf + + # Test lower bound + mixer vol.volume=0 + atf_check -o match:"0.00:0.00" mixer vol.volume + + mixer vol.volume=-2 + atf_check -
git: 16329b7b3276 - main - sound: Fix memory leak in chn_init()
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=16329b7b3276f09dc70bdd1ca8bc605546fe71e0 commit 16329b7b3276f09dc70bdd1ca8bc605546fe71e0 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:19 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:19 + sound: Fix memory leak in chn_init() In case chn_init() fails, we are leaking memory by not freeing the feeder. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45979 --- sys/dev/sound/pcm/channel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index a18ef1cf4234..19808a43631a 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1365,6 +1365,8 @@ out2: if (CHN_LOCKOWNED(c)) CHN_UNLOCK(c); if (ret) { + while (chn_removefeeder(c) == 0) + ; if (c->devinfo) { if (CHANNEL_FREE(c->methods, c->devinfo)) sndbuf_free(b);
git: 85d1c84c2406 - main - snd_hdsp*: Free up channel resources in case of CHANNEL_INIT() failure
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=85d1c84c2406aa2e4e2114215b01eee65714848f commit 85d1c84c2406aa2e4e2114215b01eee65714848f Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:32 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:32 + snd_hdsp*: Free up channel resources in case of CHANNEL_INIT() failure Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45982 --- sys/dev/sound/pci/hdsp-pcm.c | 59 ++- sys/dev/sound/pci/hdspe-pcm.c | 59 ++- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/sys/dev/sound/pci/hdsp-pcm.c b/sys/dev/sound/pci/hdsp-pcm.c index 9ba0e5e345d0..29bd0bc70ee4 100644 --- a/sys/dev/sound/pci/hdsp-pcm.c +++ b/sys/dev/sound/pci/hdsp-pcm.c @@ -661,6 +661,35 @@ clean(struct sc_chinfo *ch) } /* Channel interface. */ +static int +hdspchan_free(kobj_t obj, void *data) +{ + struct sc_pcminfo *scp; + struct sc_chinfo *ch; + struct sc_info *sc; + + ch = data; + scp = ch->parent; + sc = scp->sc; + +#if 0 + device_printf(scp->dev, "hdspchan_free()\n"); +#endif + + snd_mtxlock(sc->lock); + if (ch->data != NULL) { + free(ch->data, M_HDSP); + ch->data = NULL; + } + if (ch->caps != NULL) { + free(ch->caps, M_HDSP); + ch->caps = NULL; + } + snd_mtxunlock(sc->lock); + + return (0); +} + static void * hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir) @@ -720,6 +749,7 @@ hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, if (sndbuf_setup(ch->buffer, ch->data, ch->size) != 0) { device_printf(scp->dev, "Can't setup sndbuf.\n"); + hdspchan_free(obj, ch); return (NULL); } @@ -793,35 +823,6 @@ hdspchan_getptr(kobj_t obj, void *data) return (pos); } -static int -hdspchan_free(kobj_t obj, void *data) -{ - struct sc_pcminfo *scp; - struct sc_chinfo *ch; - struct sc_info *sc; - - ch = data; - scp = ch->parent; - sc = scp->sc; - -#if 0 - device_printf(scp->dev, "hdspchan_free()\n"); -#endif - - snd_mtxlock(sc->lock); - if (ch->data != NULL) { - free(ch->data, M_HDSP); - ch->data = NULL; - } - if (ch->caps != NULL) { - free(ch->caps, M_HDSP); - ch->caps = NULL; - } - snd_mtxunlock(sc->lock); - - return (0); -} - static int hdspchan_setformat(kobj_t obj, void *data, uint32_t format) { diff --git a/sys/dev/sound/pci/hdspe-pcm.c b/sys/dev/sound/pci/hdspe-pcm.c index e7fa03904595..79bfcbea3406 100644 --- a/sys/dev/sound/pci/hdspe-pcm.c +++ b/sys/dev/sound/pci/hdspe-pcm.c @@ -650,6 +650,35 @@ clean(struct sc_chinfo *ch) } /* Channel interface. */ +static int +hdspechan_free(kobj_t obj, void *data) +{ + struct sc_pcminfo *scp; + struct sc_chinfo *ch; + struct sc_info *sc; + + ch = data; + scp = ch->parent; + sc = scp->sc; + +#if 0 + device_printf(scp->dev, "hdspechan_free()\n"); +#endif + + snd_mtxlock(sc->lock); + if (ch->data != NULL) { + free(ch->data, M_HDSPE); + ch->data = NULL; + } + if (ch->caps != NULL) { + free(ch->caps, M_HDSPE); + ch->caps = NULL; + } + snd_mtxunlock(sc->lock); + + return (0); +} + static void * hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir) @@ -702,6 +731,7 @@ hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, if (sndbuf_setup(ch->buffer, ch->data, ch->size) != 0) { device_printf(scp->dev, "Can't setup sndbuf.\n"); + hdspechan_free(obj, ch); return (NULL); } @@ -774,35 +804,6 @@ hdspechan_getptr(kobj_t obj, void *data) return (pos); } -static int -hdspechan_free(kobj_t obj, void *data) -{ - struct sc_pcminfo *scp; - struct sc_chinfo *ch; - struct sc_info *sc; - - ch = data; - scp = ch->parent; - sc = scp->sc; - -#if 0 - device_printf(scp->dev, "hdspechan_free()\n"); -#endif - - snd_mtxlock(sc->lock); - if (ch->data != NULL) { - free(ch->data, M_HDSPE); - ch->data = NULL; - } - if (ch->caps != NULL) { - free(ch->caps, M_HDSPE); - ch->caps = NULL; - } - snd_mtxunlock(sc->lock); - - return (0); -} - static int hdspechan_setformat(kobj_t obj, void *data, uint32_t format) {
git: 29ff7b08be36 - main - sound: Rename chn_* feeder functions to feeder_*
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=29ff7b08be363f0d4345794bb951d5c0c8406a0a commit 29ff7b08be363f0d4345794bb951d5c0c8406a0a Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:37 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:37 + sound: Rename chn_* feeder functions to feeder_* Avoid layering violation. No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45983 --- sys/dev/sound/pcm/channel.c | 8 sys/dev/sound/pcm/feeder.c | 6 +++--- sys/dev/sound/pcm/feeder.h | 6 +++--- sys/dev/sound/pcm/feeder_chain.c | 16 sys/dev/sound/pcm/feeder_eq.c| 4 ++-- sys/dev/sound/pcm/feeder_rate.c | 2 +- sys/dev/sound/pcm/mixer.c| 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index 19808a43631a..511d5256c06b 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1287,7 +1287,7 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, __func__); goto out2; } - if (chn_addfeeder(c, fc, NULL)) { + if (feeder_add(c, fc, NULL)) { device_printf(d->dev, "%s(): failed to add feeder\n", __func__); goto out2; } @@ -1365,7 +1365,7 @@ out2: if (CHN_LOCKOWNED(c)) CHN_UNLOCK(c); if (ret) { - while (chn_removefeeder(c) == 0) + while (feeder_remove(c) == 0) ; if (c->devinfo) { if (CHANNEL_FREE(c->methods, c->devinfo)) @@ -1407,7 +1407,7 @@ chn_kill(struct pcm_channel *c) chn_trigger(c, PCMTRIG_ABORT); CHN_UNLOCK(c); } - while (chn_removefeeder(c) == 0) + while (feeder_remove(c) == 0) ; if (CHANNEL_FREE(c->methods, c->devinfo)) sndbuf_free(b); @@ -2300,7 +2300,7 @@ chn_syncstate(struct pcm_channel *c) else bass = ((bass & 0x7f) + ((bass >> 8) & 0x7f)) >> 1; - f = chn_findfeeder(c, FEEDER_EQ); + f = feeder_find(c, FEEDER_EQ); if (f != NULL) { if (FEEDER_SET(f, FEEDEQ_TREBLE, treble) != 0) device_printf(c->dev, diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c index 0113299bd0d4..fdbf2a8353e0 100644 --- a/sys/dev/sound/pcm/feeder.c +++ b/sys/dev/sound/pcm/feeder.c @@ -232,7 +232,7 @@ feeder_getclass(struct pcm_feederdesc *desc) } int -chn_addfeeder(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc *desc) +feeder_add(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc *desc) { struct pcm_feeder *nf; @@ -250,7 +250,7 @@ chn_addfeeder(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederd } int -chn_removefeeder(struct pcm_channel *c) +feeder_remove(struct pcm_channel *c) { struct pcm_feeder *f; @@ -264,7 +264,7 @@ chn_removefeeder(struct pcm_channel *c) } struct pcm_feeder * -chn_findfeeder(struct pcm_channel *c, u_int32_t type) +feeder_find(struct pcm_channel *c, u_int32_t type) { struct pcm_feeder *f; diff --git a/sys/dev/sound/pcm/feeder.h b/sys/dev/sound/pcm/feeder.h index c3d6f89d102e..f2a865d3d2f9 100644 --- a/sys/dev/sound/pcm/feeder.h +++ b/sys/dev/sound/pcm/feeder.h @@ -58,10 +58,10 @@ u_int32_t snd_fmtbestbit(u_int32_t fmt, u_int32_t *fmts); u_int32_t snd_fmtbestchannel(u_int32_t fmt, u_int32_t *fmts); u_int32_t snd_fmtbest(u_int32_t fmt, u_int32_t *fmts); -int chn_addfeeder(struct pcm_channel *c, struct feeder_class *fc, +int feeder_add(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc *desc); -int chn_removefeeder(struct pcm_channel *c); -struct pcm_feeder *chn_findfeeder(struct pcm_channel *c, u_int32_t type); +int feeder_remove(struct pcm_channel *c); +struct pcm_feeder *feeder_find(struct pcm_channel *c, u_int32_t type); void feeder_printchain(struct pcm_feeder *head); int feeder_chain(struct pcm_channel *); diff --git a/sys/dev/sound/pcm/feeder_chain.c b/sys/dev/sound/pcm/feeder_chain.c index 52351ef58510..555cd86d60e5 100644 --- a/sys/dev/sound/pcm/feeder_chain.c +++ b/sys/dev/sound/pcm/feeder_chain.c @@ -157,7 +157,7 @@ feeder_build_format(struct pcm_channel *c, struct feeder_chain_desc *cdesc) desc->in = cdesc->current.afmt; desc->out = cdesc->target.afmt; - ret = chn_addfeeder(c, fc, desc); + ret = feeder_add(c, fc, desc); if (ret != 0) { device_printf(c->dev, "%s(): can't add feeder_format\n", __func__); @@ -230,7 +2
git: c55f995502cb - main - sound: Remove unused FEEDER_DEBUG
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=c55f995502cbaa2d38b7a7003bc27805b28a6a29 commit c55f995502cbaa2d38b7a7003bc27805b28a6a29 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:42 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:42 + sound: Remove unused FEEDER_DEBUG No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45984 --- sys/dev/sound/pcm/feeder.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c index fdbf2a8353e0..ad6966331f02 100644 --- a/sys/dev/sound/pcm/feeder.c +++ b/sys/dev/sound/pcm/feeder.c @@ -39,7 +39,6 @@ static MALLOC_DEFINE(M_FEEDER, "feeder", "pcm feeder"); #define MAXFEEDERS 256 -#undef FEEDER_DEBUG struct feedertab_entry { SLIST_ENTRY(feedertab_entry) link;
git: 5b209e153b58 - main - sound: Simplify chn_init()
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=5b209e153b58515c0315f5902e18ecd7d75ecd2a commit 5b209e153b58515c0315f5902e18ecd7d75ecd2a Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:47 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:47 + sound: Simplify chn_init() - Remove unnecessary CHN_[UN]LOCKs. - Improve device_printf() messages. - Remove redundant checks. - Remove 0 assignments, since the channel is allocated with M_ZERO. - Re-organize sections in a more coherent way. - Remove "out1" label, just return NULL directly. - Rename "out2" to "fail" and simplify logic. - Do not check the return value of dsp_unit2name(), as it is guaranteed not to fail (we pass a valid channel type). Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45985 --- sys/dev/sound/pcm/channel.c | 177 1 file changed, 63 insertions(+), 114 deletions(-) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index 511d5256c06b..ce4fb7222ddb 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1164,8 +1164,8 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, struct pcm_channel *c; struct feeder_class *fc; struct snd_dbuf *b, *bs; - char *dirs, *devname, buf[CHN_NAMELEN]; - int i, ret, direction, rpnum, *pnum, max, type, unit; + char *dirs, buf[CHN_NAMELEN]; + int i, direction, *pnum, max, type, unit; PCM_BUSYASSERT(d); PCM_LOCKASSERT(d); @@ -1203,148 +1203,106 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, device_printf(d->dev, "%s(): invalid channel direction: %d\n", __func__, dir); - goto out1; + return (NULL); } - unit = 0; - - if (*pnum >= max || unit >= max) { - device_printf(d->dev, "%s(): unit=%d or pnum=%d >= than " - "max=%d\n", __func__, unit, *pnum, max); - goto out1; + if (*pnum >= max) { + device_printf(d->dev, "%s(): cannot allocate more channels " + "(max=%d)\n", __func__, max); + return (NULL); } - rpnum = 0; - + unit = 0; CHN_FOREACH(c, d, channels.pcm) { if (c->type != type) continue; unit++; if (unit >= max) { - device_printf(d->dev, - "%s(): chan=%d >= max=%d\n", __func__, unit, max); - goto out1; + device_printf(d->dev, "%s(): cannot allocate more " + "channels for type=%d (max=%d)\n", + __func__, type, max); + return (NULL); } - rpnum++; - } - - if (*pnum != rpnum) { - device_printf(d->dev, - "%s(): pnum screwed: dirs=%s pnum=%d rpnum=%d\n", - __func__, dirs, *pnum, rpnum); - goto out1; } PCM_UNLOCK(d); b = NULL; bs = NULL; + c = malloc(sizeof(*c), M_DEVBUF, M_WAITOK | M_ZERO); c->methods = kobj_create(cls, M_DEVBUF, M_WAITOK | M_ZERO); + chn_lockinit(c, dir); + CHN_INIT(c, children); + CHN_INIT(c, children.busy); + c->direction = direction; c->type = type; c->unit = unit; + c->format = SND_FORMAT(AFMT_U8, 1, 0); + c->speed = DSP_DEFAULT_SPEED; c->pid = -1; + c->latency = -1; + c->timeout = 1; strlcpy(c->comm, CHN_COMM_UNUSED, sizeof(c->comm)); c->parentsnddev = d; c->parentchannel = parent; c->dev = d->dev; c->trigger = PCMTRIG_STOP; - chn_lockinit(c, dir); - devname = dsp_unit2name(buf, sizeof(buf), c); - if (devname == NULL) { - ret = EINVAL; - device_printf(d->dev, "%s(): failed to create channel name", - __func__); - goto out2; - } + snprintf(c->name, sizeof(c->name), "%s:%s:%s", - device_get_nameunit(c->dev), dirs, devname); + device_get_nameunit(c->dev), dirs, + dsp_unit2name(buf, sizeof(buf), c)); - CHN_INIT(c, children); - CHN_INIT(c, children.busy); - c->latency = -1; - c->timeout = 1; + c->matrix = *feeder_matrix_id_map(SND_CHN_MATRIX_1_0); + c->matrix.id = SND_CHN_MATRIX_PCMCHANNEL; - ret = ENOMEM; - b = sndbuf_create(c->dev, c->name, "primary", c); - if (b == NULL) { - device_printf(d->dev, "%s(): failed to create hardware
git: f477d412530a - main - sound: Remove unused defines from pcm/sound.h
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=f477d412530a8cb9d8e058d00189ce127584f6f6 commit f477d412530a8cb9d8e058d00189ce127584f6f6 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:52 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:52 + sound: Remove unused defines from pcm/sound.h Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj, emaste Differential Revision: https://reviews.freebsd.org/D45986 --- sys/dev/sound/pcm/sound.h | 17 + 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h index e4a3ba41ee7f..5f32dd767fe8 100644 --- a/sys/dev/sound/pcm/sound.h +++ b/sys/dev/sound/pcm/sound.h @@ -126,9 +126,6 @@ struct snd_mixer; #define SD_F_PRIO_RD 0x1000 #define SD_F_PRIO_WR 0x2000 -#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) -#define SD_F_DIR_SET 0x4000 -#define SD_F_TRANSIENT 0xf000 #define SD_F_BITS "\020" \ "\001SIMPLEX" \ @@ -146,8 +143,7 @@ struct snd_mixer; "\015EQ_BYPASSED" \ "\016EQ_PC" \ "\035PRIO_RD" \ - "\036PRIO_WR" \ - "\037DIR_SET" + "\036PRIO_WR" #define PCM_ALIVE(x) ((x) != NULL && (x)->lock != NULL &&\ !((x)->flags & SD_F_DYING)) @@ -162,7 +158,6 @@ struct snd_mixer; /* many variables should be reduced to a range. Here define a macro */ #define RANGE(var, low, high) (var) = \ (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) -#define DSP_BUFFSIZE (8192) /* make figuring out what a format is easier. got AFMT_STEREO already */ #define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) @@ -242,22 +237,12 @@ enum { #define DSP_DEFAULT_SPEED 8000 -#define ON 1 -#define OFF0 - extern int pcm_veto_load; extern int snd_unit; extern int snd_verbose; extern devclass_t pcm_devclass; extern struct unrhdr *pcmsg_unrhdr; -/* - * some macros for debugging purposes - * DDB/DEB to enable/disable debugging stuff - * BVDDB to enable debugging when bootverbose - */ -#define BVDDB(x) if (bootverbose) x - #ifndef DEB #define DEB(x) #endif
git: 00172d20070a - main - sound: Simplify feeder_remove()
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=00172d20070a544e0514cce9f94475c5525fd15e commit 00172d20070a544e0514cce9f94475c5525fd15e Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:57 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:57 + sound: Simplify feeder_remove() Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:dev_submerge.ch, markj, emaste Differential Revision: https://reviews.freebsd.org/D46100 --- sys/dev/sound/pcm/channel.c | 6 ++ sys/dev/sound/pcm/feeder.c | 14 ++ sys/dev/sound/pcm/feeder.h | 2 +- sys/dev/sound/pcm/feeder_chain.c | 3 +-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index ce4fb7222ddb..e0fd24805a21 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1324,8 +1324,7 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, return (c); fail: - while (feeder_remove(c) == 0) - ; + feeder_remove(c); if (c->devinfo && CHANNEL_FREE(c->methods, c->devinfo)) sndbuf_free(b); if (bs) @@ -1356,8 +1355,7 @@ chn_kill(struct pcm_channel *c) chn_trigger(c, PCMTRIG_ABORT); CHN_UNLOCK(c); } - while (feeder_remove(c) == 0) - ; + feeder_remove(c); if (CHANNEL_FREE(c->methods, c->devinfo)) sndbuf_free(b); sndbuf_destroy(bs); diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c index ad6966331f02..716eb07feaae 100644 --- a/sys/dev/sound/pcm/feeder.c +++ b/sys/dev/sound/pcm/feeder.c @@ -248,18 +248,16 @@ feeder_add(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc return 0; } -int +void feeder_remove(struct pcm_channel *c) { struct pcm_feeder *f; - if (c->feeder == NULL) - return -1; - f = c->feeder; - c->feeder = c->feeder->source; - feeder_destroy(f); - - return 0; + while (c->feeder != NULL) { + f = c->feeder; + c->feeder = c->feeder->source; + feeder_destroy(f); + } } struct pcm_feeder * diff --git a/sys/dev/sound/pcm/feeder.h b/sys/dev/sound/pcm/feeder.h index f2a865d3d2f9..1e240d934e94 100644 --- a/sys/dev/sound/pcm/feeder.h +++ b/sys/dev/sound/pcm/feeder.h @@ -60,7 +60,7 @@ u_int32_t snd_fmtbest(u_int32_t fmt, u_int32_t *fmts); int feeder_add(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc *desc); -int feeder_remove(struct pcm_channel *c); +void feeder_remove(struct pcm_channel *c); struct pcm_feeder *feeder_find(struct pcm_channel *c, u_int32_t type); void feeder_printchain(struct pcm_feeder *head); int feeder_chain(struct pcm_channel *); diff --git a/sys/dev/sound/pcm/feeder_chain.c b/sys/dev/sound/pcm/feeder_chain.c index 555cd86d60e5..588bae2ff281 100644 --- a/sys/dev/sound/pcm/feeder_chain.c +++ b/sys/dev/sound/pcm/feeder_chain.c @@ -588,8 +588,7 @@ feeder_chain(struct pcm_channel *c) CHN_LOCKASSERT(c); /* Remove everything first. */ - while (feeder_remove(c) == 0) - ; + feeder_remove(c); KASSERT(c->feeder == NULL, ("feeder chain not empty"));
git: f0eceecf5ab5 - main - sndstat.4: Fix typo
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=f0eceecf5ab51a68d713f9a5a7f360964d0a49ce commit f0eceecf5ab51a68d713f9a5a7f360964d0a49ce Author: Christos Margiolis AuthorDate: 2024-07-27 11:56:02 + Commit: Christos Margiolis CommitDate: 2024-07-27 11:56:02 + sndstat.4: Fix typo Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by:markj Differential Revision: https://reviews.freebsd.org/D46165 --- share/man/man4/sndstat.4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/man/man4/sndstat.4 b/share/man/man4/sndstat.4 index 2fc55f0045c1..44c3f3152610 100644 --- a/share/man/man4/sndstat.4 +++ b/share/man/man4/sndstat.4 @@ -198,7 +198,7 @@ There are a number of name/value pairs inside this field: .Bl -tag -width ".Dv hwbuf_blkcnt" .It Dv name Channel name. -.It Dv parenchan +.It Dv parentchan Parent channel name (e.g., in the case of virtual channels). .It Dv unit Channel unit.
git: 21e98f6d195a - main - BSD.tests.dist: Add entry for mixer tests
The branch main has been updated by lwhsu: URL: https://cgit.FreeBSD.org/src/commit/?id=21e98f6d195a5db63b17025f339684048834e1aa commit 21e98f6d195a5db63b17025f339684048834e1aa Author: Li-Wen Hsu AuthorDate: 2024-07-27 18:44:28 + Commit: Li-Wen Hsu CommitDate: 2024-07-27 18:44:28 + BSD.tests.dist: Add entry for mixer tests Fixes: 94a86f3f6920 mixer(8): Add tests Sponsored by: The FreeBSD Foundation --- etc/mtree/BSD.tests.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index bd9edc786f17..5c724e5a8e5b 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1241,6 +1241,8 @@ .. makefs .. +mixer +.. newsyslog .. nmtree
git: b3cec803eaa4 - main - vm_fault: avoid vm_page_next()
The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=b3cec803eaa4ae3495f9844f93c1f0cadc1b2d6a commit b3cec803eaa4ae3495f9844f93c1f0cadc1b2d6a Author: Doug Moore AuthorDate: 2024-07-27 21:11:53 + Commit: Doug Moore CommitDate: 2024-07-27 21:11:53 + vm_fault: avoid vm_page_next() Where vm_fault calls vm_page_next, replace it with a use of TAILQ_NEXT and a KASSERT. This avoids needless computation in a NODEBUG kernel and makes the error checking clearer in a GENERIC kernel. Reviewed by:kib Differential Revision: https://reviews.freebsd.org/D46168 --- sys/vm/vm_fault.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index df686f3e46dc..6e0415b30600 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -485,7 +485,9 @@ vm_fault_populate_cleanup(vm_object_t object, vm_pindex_t first, VM_OBJECT_ASSERT_WLOCKED(object); MPASS(first <= last); for (pidx = first, m = vm_page_lookup(object, pidx); - pidx <= last; pidx++, m = vm_page_next(m)) { + pidx <= last; pidx++, m = TAILQ_NEXT(m, listq)) { + KASSERT(m != NULL && m->pindex == pidx, + ("%s: pindex mismatch", __func__)); vm_fault_populate_check_page(m); vm_page_deactivate(m); vm_page_xunbusy(m); @@ -623,9 +625,10 @@ vm_fault_populate(struct faultstate *fs) } for (pidx = pager_first, m = vm_page_lookup(fs->first_object, pidx); pidx <= pager_last; - pidx += npages, m = vm_page_next(&m[npages - 1])) { + pidx += npages, m = TAILQ_NEXT(&m[npages - 1], listq)) { vaddr = fs->entry->start + IDX_TO_OFF(pidx) - fs->entry->offset; - + KASSERT(m != NULL && m->pindex == pidx, + ("%s: pindex mismatch", __func__)); psind = m->psind; while (psind > 0 && ((vaddr & (pagesizes[psind] - 1)) != 0 || pidx + OFF_TO_IDX(pagesizes[psind]) - 1 > pager_last ||
git: d55de30efd09 - main - tools/build/make.py: Minor typo fix
The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=d55de30efd09ee011bf4604be1c15ce4155775c1 commit d55de30efd09ee011bf4604be1c15ce4155775c1 Author: Jose Luis Duran AuthorDate: 2024-07-25 04:32:33 + Commit: Ed Maste CommitDate: 2024-07-28 03:04:24 + tools/build/make.py: Minor typo fix If the object directory prefix does not exist, make.py previously exited with a message indicating that the chosen prefix does not exit. Reviewed by:emaste Pull request: https://github.com/freebsd/freebsd-src/pull/1348 --- tools/build/make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build/make.py b/tools/build/make.py index 73788a8896c7..ec42cb70dd21 100755 --- a/tools/build/make.py +++ b/tools/build/make.py @@ -243,7 +243,7 @@ if __name__ == "__main__": sys.exit("MAKEOBJDIRPREFIX is not set, cannot continue!") if not Path(MAKEOBJDIRPREFIX).is_dir(): sys.exit( -"Chosen MAKEOBJDIRPREFIX=" + MAKEOBJDIRPREFIX + " doesn't exit!") +"Chosen MAKEOBJDIRPREFIX=" + MAKEOBJDIRPREFIX + " doesn't exist!") objdir_prefix = Path(MAKEOBJDIRPREFIX).absolute() source_root = Path(__file__).absolute().parent.parent.parent
git: 9328ded386d5 - stable/14 - nfscl: Scan readdir reply filenames for invalid characters
The branch stable/14 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=9328ded386d570c8455b9021e047520ef72e0e79 commit 9328ded386d570c8455b9021e047520ef72e0e79 Author: Rick Macklem AuthorDate: 2024-07-21 22:56:16 + Commit: Rick Macklem CommitDate: 2024-07-28 03:53:17 + nfscl: Scan readdir reply filenames for invalid characters The NFS RFCs are pretty loose with respect to what characters can be in a filename returned by a Readdir. However, FreeBSD, as a POSIX system will not handle imbedded '/' or nul characters in file names. Also, for NFSv4, the file names "." and ".." are handcrafted on the client and should not be returned by a NFSv4 server. This patch scans for the above in filenames returned by Readdir and ignores any entry returned by Readdir which has them in it. Because an imbedded nul would be a string terminator, it was not possible to code this check efficiently using string(3) functions. Reported by:Apple Security Engineering and Architecture (SEAR) (cherry picked from commit 026cdaa3b3a92574d9ac3155216e5cc0b0bd4c51) --- sys/fs/nfsclient/nfs_clrpcops.c | 137 1 file changed, 110 insertions(+), 27 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c index 13bdc74655dd..8947b608b743 100644 --- a/sys/fs/nfsclient/nfs_clrpcops.c +++ b/sys/fs/nfsclient/nfs_clrpcops.c @@ -142,6 +142,7 @@ static int nfsrpc_createv4(vnode_t , char *, int, struct vattr *, nfsquad_t, int, struct nfsclowner *, struct nfscldeleg **, struct ucred *, NFSPROC_T *, struct nfsvattr *, struct nfsvattr *, struct nfsfh **, int *, int *, int *); +static bool nfscl_invalidfname(bool, char *, int); static int nfsrpc_locku(struct nfsrv_descript *, struct nfsmount *, struct nfscllockowner *, u_int64_t, u_int64_t, u_int32_t, struct ucred *, NFSPROC_T *, int); @@ -3321,6 +3322,31 @@ nfsrpc_rmdir(vnode_t dvp, char *name, int namelen, struct ucred *cred, return (error); } +/* + * Check to make sure the file name in a Readdir reply is valid. + */ +static bool +nfscl_invalidfname(bool is_v4, char *name, int len) +{ + int i; + char *cp; + + if (is_v4 && ((len == 1 && name[0] == '.') || + (len == 2 && name[0] == '.' && name[1] == '.'))) { + printf("Readdir NFSv4 reply has dot or dotdot in it\n"); + return (true); + } + cp = name; + for (i = 0; i < len; i++, cp++) { + if (*cp == '/' || *cp == '\0') { + printf("Readdir reply file name had imbedded / or nul" + " byte\n"); + return (true); + } + } + return (false); +} + /* * Readdir rpc. * Always returns with either uio_resid unchanged, if you are at the @@ -3373,6 +3399,8 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, KASSERT(uiop->uio_iovcnt == 1 && (uiop->uio_resid & (DIRBLKSIZ - 1)) == 0, ("nfs readdirrpc bad uio")); + KASSERT(uiop->uio_segflg == UIO_SYSSPACE, + ("nfsrpc_readdir: uio userspace")); ncookie.lval[0] = ncookie.lval[1] = 0; /* * There is no point in reading a lot more than uio_resid, however @@ -3630,6 +3658,17 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, uiop->uio_resid) bigenough = 0; if (bigenough) { + struct iovec saviov; + off_t savoff; + ssize_t savresid; + int savblksiz; + + saviov.iov_base = uiop->uio_iov->iov_base; + saviov.iov_len = uiop->uio_iov->iov_len; + savoff = uiop->uio_offset; + savresid = uiop->uio_resid; + savblksiz = blksiz; + dp = (struct dirent *)uiop->uio_iov->iov_base; dp->d_pad0 = dp->d_pad1 = 0; dp->d_off = 0; @@ -3645,20 +3684,35 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, uiop->uio_iov->iov_base = (char *)uiop->uio_iov->iov_base + DIRHDSIZ; uiop->uio_iov->iov_len -= DIRHDSIZ; + cp = uiop->uio_iov->iov_base; error = nfsm_mbufuio(nd, uiop, len); if (error) goto nfsmout; - cp = uiop->uio_iov->iov_base; - tlen -= len; - NFSBZ
git: 0172b5145ad9 - stable/13 - nfscl: Scan readdir reply filenames for invalid characters
The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=0172b5145ad9435569978ed4d268b9f65ac59526 commit 0172b5145ad9435569978ed4d268b9f65ac59526 Author: Rick Macklem AuthorDate: 2024-07-21 22:56:16 + Commit: Rick Macklem CommitDate: 2024-07-28 04:00:36 + nfscl: Scan readdir reply filenames for invalid characters The NFS RFCs are pretty loose with respect to what characters can be in a filename returned by a Readdir. However, FreeBSD, as a POSIX system will not handle imbedded '/' or nul characters in file names. Also, for NFSv4, the file names "." and ".." are handcrafted on the client and should not be returned by a NFSv4 server. This patch scans for the above in filenames returned by Readdir and ignores any entry returned by Readdir which has them in it. Because an imbedded nul would be a string terminator, it was not possible to code this check efficiently using string(3) functions. Reported by:Apple Security Engineering and Architecture (SEAR) (cherry picked from commit 026cdaa3b3a92574d9ac3155216e5cc0b0bd4c51) --- sys/fs/nfsclient/nfs_clrpcops.c | 137 1 file changed, 110 insertions(+), 27 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c index 475034768e04..b3062b5a5d88 100644 --- a/sys/fs/nfsclient/nfs_clrpcops.c +++ b/sys/fs/nfsclient/nfs_clrpcops.c @@ -140,6 +140,7 @@ static int nfsrpc_createv4(vnode_t , char *, int, struct vattr *, nfsquad_t, int, struct nfsclowner *, struct nfscldeleg **, struct ucred *, NFSPROC_T *, struct nfsvattr *, struct nfsvattr *, struct nfsfh **, int *, int *, void *, int *); +static bool nfscl_invalidfname(bool, char *, int); static int nfsrpc_locku(struct nfsrv_descript *, struct nfsmount *, struct nfscllockowner *, u_int64_t, u_int64_t, u_int32_t, struct ucred *, NFSPROC_T *, int); @@ -3005,6 +3006,31 @@ nfsrpc_rmdir(vnode_t dvp, char *name, int namelen, struct ucred *cred, return (error); } +/* + * Check to make sure the file name in a Readdir reply is valid. + */ +static bool +nfscl_invalidfname(bool is_v4, char *name, int len) +{ + int i; + char *cp; + + if (is_v4 && ((len == 1 && name[0] == '.') || + (len == 2 && name[0] == '.' && name[1] == '.'))) { + printf("Readdir NFSv4 reply has dot or dotdot in it\n"); + return (true); + } + cp = name; + for (i = 0; i < len; i++, cp++) { + if (*cp == '/' || *cp == '\0') { + printf("Readdir reply file name had imbedded / or nul" + " byte\n"); + return (true); + } + } + return (false); +} + /* * Readdir rpc. * Always returns with either uio_resid unchanged, if you are at the @@ -3057,6 +3083,8 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, KASSERT(uiop->uio_iovcnt == 1 && (uiop->uio_resid & (DIRBLKSIZ - 1)) == 0, ("nfs readdirrpc bad uio")); + KASSERT(uiop->uio_segflg == UIO_SYSSPACE, + ("nfsrpc_readdir: uio userspace")); ncookie.lval[0] = ncookie.lval[1] = 0; /* * There is no point in reading a lot more than uio_resid, however @@ -3315,6 +3343,17 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, uiop->uio_resid) bigenough = 0; if (bigenough) { + struct iovec saviov; + off_t savoff; + ssize_t savresid; + int savblksiz; + + saviov.iov_base = uiop->uio_iov->iov_base; + saviov.iov_len = uiop->uio_iov->iov_len; + savoff = uiop->uio_offset; + savresid = uiop->uio_resid; + savblksiz = blksiz; + dp = (struct dirent *)uiop->uio_iov->iov_base; dp->d_pad0 = dp->d_pad1 = 0; dp->d_off = 0; @@ -3330,20 +3369,35 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep, uiop->uio_iov->iov_base = (char *)uiop->uio_iov->iov_base + DIRHDSIZ; uiop->uio_iov->iov_len -= DIRHDSIZ; + cp = uiop->uio_iov->iov_base; error = nfsm_mbufuio(nd, uiop, len); if (error) goto nfsmout; - cp = uiop->uio_iov->iov_base; - tlen -= len; -