From nobody Fri Nov 28 14:35:32 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dHwnd2FHrz6HZmd for ; Fri, 28 Nov 2025 14:35:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dHwnc6xbHz3spf for ; Fri, 28 Nov 2025 14:35:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764340533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Bqv9Jqe1pWJ5+574IxKH1tWKniRMLcREF3dpqi3eMpI=; b=rw6F6boSDsFApj223Hz5c+miw2+g02dn22vI3zCtT19TXA8wmnXZYZEiAaU0GBam6+znqB 0NR+hQqJehq8FzeAotun+m98TopXzuP6bAdzO41S73dvh5EdFKMhTh3MrWMrWHO6LSMp0n fVIyxGo+6aVY0V0rbhg0quNfbsmUVTZgbYoKgwvpRQSbMKTQvj8rLFryC3iVmdXJSffWBl Dh1uCXkcd4pPOczsUAkYiuTujmjLoWzrfRr9jTLhneOt0t5MwxdMfHN8vJe4VF8K3aXLVu xgKXJKXao/NOzt53cWoNY/QylNXNRF1qV4QJHGW3n16p5ot8gY3/bBLgWim4vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764340533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Bqv9Jqe1pWJ5+574IxKH1tWKniRMLcREF3dpqi3eMpI=; b=rkS4DI7tYvuVCrpcFyCps1ofTw5lnpfv6G//2HT/hhvwg6Lm4s4TZ+hUpYv6QL95qW54TG ccwQOUAAaTqYtVqnq6luMqxRqa7kS6VXgLZPuD8CY+rSlgSYTFmRJ7aH5ni9iQorCP7p/t TJXXDO+WvRIrIB5Iynco72G7uUZrcSSi01hbAvGthj4k+Oid0zljFOby0jTksFo1NGD2cp L2uf23ZM7pSLxSX4auJuPAL3o4LqUoEfKfdip16BKmGvCvRjCyWQ4GQOGKMQksss4f9CFy JxPnT8+oq7s0UiZb9VB7g1J4fI+Lrr30kUtC/zm7oPeKgbTSKQu0vNQXBRFa7g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1764340533; a=rsa-sha256; cv=none; b=xkKHfXpR0j8gJ/+5QQXaWMKw1uoL05WzroOEbYfPF+dIev3GIoE6CoKF0pdjs6Q/zE6mge yPK/YNy+dbWKLJ8zNkq72UU4Lrz+zfGODGZNo2zn8Pw1JP2q/L3BID2qlp1EYwNBWceT3d EeO8GjbEnctbJ6/mXxUdaCuNTo5cXweDSX9qhOZAPpZR7xv6LyPEoB+1bSEXsMi3cw5oUy o2KysOhlF6sAIck/I1Hw0QkqZwpuoO+TCxYZsp6yyHxhN9NDfElOSGqsUjhyhzWw5wnapL QAJ8w6L4oNthUSnkw0Jm7m1Gw5pBA69F5oMAYThIC+zLwC0TrV2xy8aEhGzw9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dHwnc6DDnz15Pc for ; Fri, 28 Nov 2025 14:35:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2a528 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 28 Nov 2025 14:35:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Goran=?utf-8?Q? Meki=C4=87?= From: Christos Margiolis Subject: git: 7587270512d1 - stable/15 - sound examples: Fix buffer mapping/allocation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 7587270512d12f13d2d225dc893ec85bfb6501a7 Auto-Submitted: auto-generated Date: Fri, 28 Nov 2025 14:35:32 +0000 Message-Id: <6929b334.2a528.3774ff06@gitrepo.freebsd.org> The branch stable/15 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=7587270512d12f13d2d225dc893ec85bfb6501a7 commit 7587270512d12f13d2d225dc893ec85bfb6501a7 Author: Goran Mekić AuthorDate: 2025-11-26 19:33:05 +0000 Commit: Christos Margiolis CommitDate: 2025-11-28 14:35:00 +0000 sound examples: Fix buffer mapping/allocation The buffer in struct config should be allocated or mmap'ed. The code without this patch allocates the buffer unconditionally, even for mmap configs. MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D53939 (cherry picked from commit ebf1d98d60725feccd726ef8e4fa518661f9eae0) --- share/examples/sound/oss.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/share/examples/sound/oss.h b/share/examples/sound/oss.h index 437c6d69d454..e1ba4165810f 100644 --- a/share/examples/sound/oss.h +++ b/share/examples/sound/oss.h @@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#include #include #include @@ -84,7 +85,7 @@ static void oss_init(struct config *config) { unsigned long request = SNDCTL_DSP_GETOSPACE; - int tmp = 0; + int tmp = 0, prot = 0; if ((config->fd = open(config->device, config->mode)) < 0) err(1, "Error opening the device %s", config->device); @@ -194,7 +195,6 @@ oss_init(struct config *config) } config->sample_count = config->buffer_info.bytes / config->sample_size; config->chsamples = config->sample_count / config->audio_info.max_channels; - config->buf = malloc(config->buffer_info.bytes); printf("bytes: %d, fragments: %d, fragsize: %d, fragstotal: %d, " "samples: %d\n", @@ -202,21 +202,36 @@ oss_init(struct config *config) config->buffer_info.fragsize, config->buffer_info.fragstotal, config->sample_count); - /* Set the trigger */ + /* Set trigger direction and mmap protection */ switch (config->mode & O_ACCMODE) { case O_RDONLY: tmp = PCM_ENABLE_INPUT; + prot = PROT_READ; break; case O_WRONLY: tmp = PCM_ENABLE_OUTPUT; + prot = PROT_WRITE; break; case O_RDWR: tmp = PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT; + prot = PROT_READ | PROT_WRITE; break; default: errx(1, "Invalid mode %d", config->mode); break; } + + /* Map or allocate the buffer */ + if (config->mmap) { + config->buf = mmap(NULL, config->buffer_info.bytes, prot, MAP_SHARED, config->fd, 0); + if (config->buf == MAP_FAILED) + err(1, "Memory map failed"); + } else { + if ((config->buf = malloc(config->buffer_info.bytes)) == NULL) + err(1, "Allocating buffer failed"); + } + + /* Set the trigger */ if (ioctl(config->fd, SNDCTL_DSP_SETTRIGGER, &tmp) < 0) err(1, "Failed to set trigger"); }