From nobody Wed Nov 26 19:33:52 2025 X-Original-To: dev-commits-src-main@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 4dGqVm4zGdz6JWfc for ; Wed, 26 Nov 2025 19:33:52 +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 4dGqVm3rxmz49Ll for ; Wed, 26 Nov 2025 19:33:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764185632; 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=a9aME2Bid3jnlumrIakJYs5xptHs+Ajcrq0WatiVLKo=; b=TjRXJfHKHJSI7yuEdOna6wy0QZnJkq6gzA61Wmi0LT55USNVykOPQMQ66wixwaWeEqasX9 kCneSPoCGJZH+3F/jFJdZypx1MuhVH19/NFP9RV+B04wiUSxe5CeNKd22JGuTQ1SFMYyng CyuXd14SqNMXIZfh+M8cPQF0lFov+/ii3Lc4JTEahHZkhYFz1Oll3elE6EU5m22MFXugWZ WbwPlrw2piWaUMc4b+dKzYT42ojyvK0ejz5a7B6O62OKfyGK6D4yV8Zjmq0FvUQ3xa7sq7 NCDh5Q2yr1jrjsbA5cyprw8HCP6wf5vSvFzgRBpD9NNq2CNswFoi27yr7ebK5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764185632; 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=a9aME2Bid3jnlumrIakJYs5xptHs+Ajcrq0WatiVLKo=; b=xEK1xZSKyKLbg4FL79oywMnsWpA3jvK5fDyzsweQ53zNps9XjJqWFMXOb/k59hk5/sGakH ZQYHkyGCD54kLooNUH/9jeGBMzSe4OMTFfx2mw/A/rwCoV/jU8UbN7qjGHATGTKy+Jy2Yu ImULuIhVLAS1P+SkgdJ8Ise54Fm3U74YLGUHpfSD4mUoN5cp72VysnKm8Qt5MvDttjEAvq svktnscuIecMROpkrP6wlxRYWPpHT4UpntLfkAQf6YBVQzSYpv3jTKWd+YJ21pngdXAXtZ C39G7my0zNFgNHBbhTeiVCvGYqfkCB00oaVj1Tq5nAI8/CAJiHiXjkcgqajG2A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1764185632; a=rsa-sha256; cv=none; b=vWsTMhGqPohoERHX8uXF4RNi5TpAUqVpWzv453h4v+hSb1j25TEk6QqrPJ2WSnt/jYaZWn tJ+GrzqUla6cr5b0+hT9F2LzD6ZJFnDgEA1GOyNu1YOvulEDIyQegYMdoXLu5zCpao7tgS hwcto4rl14Sqx7N+aJw3Ftwm2qpGElnO/Wf5QMDRcoPqKFELHFnYMsH9UyAH5bSZwqtNwD 8l9c5evl/WFW9Z/S/y641CXDVbc6uI54l3I4zUKTlP8jgRtS51BJBhuNeWVRa/bChs5NIS dFxsbG9fiPElgUjtUzDnVrQsiaJKf2frl/SaKsUpG4I0MfUBfrB7N/T+6ZuIHg== 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 4dGqVm3Rqgz10vP for ; Wed, 26 Nov 2025 19:33:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2b794 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 26 Nov 2025 19:33:52 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Goran=?utf-8?Q? Meki=C4=87?= From: Christos Margiolis Subject: git: ebf1d98d6072 - main - sound examples: Fix buffer mapping/allocation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ebf1d98d60725feccd726ef8e4fa518661f9eae0 Auto-Submitted: auto-generated Date: Wed, 26 Nov 2025 19:33:52 +0000 Message-Id: <69275620.2b794.778d748@gitrepo.freebsd.org> The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=ebf1d98d60725feccd726ef8e4fa518661f9eae0 commit ebf1d98d60725feccd726ef8e4fa518661f9eae0 Author: Goran Mekić AuthorDate: 2025-11-26 19:33:05 +0000 Commit: Christos Margiolis CommitDate: 2025-11-26 19:33:05 +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 --- 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"); }