From nobody Mon Jul 29 15:35:25 2024 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 4WXj9V05Jkz5RSSR; Mon, 29 Jul 2024 15:35:26 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WXj9T4skDz42Mt; Mon, 29 Jul 2024 15:35:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722267325; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JbXda1LX+za3VjJV0uupNlZHSOEGUUimoOb8SgQ0yCU=; b=a3PCELQwUXEAc376/5fsdU18qVTXOxU41wezXvTAmhZTpIwDy9f55BaBQKF3Wytrq7L90K ZXelcHHlxLJlTWP9azkIOEOP3aI/W7vpx1O9Vz7YDqAYCVoue7bJwAuta5T60voyvP5yFL sA1TUvjC/G318dgfmAGFkhee+8RBavMNNVxwP/6Cwb3Wrd2+A1BY/2MbKtLmdIXfHPXps1 wXPKQziVK4LCfFufx20CpEdSPMb7YBzcyusAxHUUUMCu6H/SMZPxT00iT+Vyv0Tdwn7QV+ Y/2AwNoMlfxD5GhzDXKze2ZmvyWnJi/khtRZnajMDnLCYgl8bN4YTEd4kFMi+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722267325; a=rsa-sha256; cv=none; b=vrO+HYMY6zz0HQsl11+9Z4/3ICT30R2SfNjTJGtF7oeaOHLFZLVnIWbLRsy6U5Wh+Hy6N1 JKqGVCyxyb2ypI436qK/xnRjNG8S8M3G+vRVkZ2OMS63DNZImJ++45FJl/+Uo3WeWAKVNQ HyOVOPzsxuZHG1a7exrSy90zmtuQ/DfCSlP7i0JzUvI57Z0Lgly8EaxKCX5sFLfV1ixglT NyYg6xpECHajY96jI8VJiX0awRnktuK1SBkK9ec/lpITQeeyIa62XDzZRHdqVI8xRnR7T9 nzgI6ou2+snqscKOZHpJplG9Et3w7xGJgVQkmJalIEvWL0fo7DorSfJFKyRf4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722267325; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JbXda1LX+za3VjJV0uupNlZHSOEGUUimoOb8SgQ0yCU=; b=QszogF7V9qGRn4XsRJKqS7ow7ml58xoqTnMZyOJ2Y87EEpNjSBzW3MNrMRl92MMQJ4KHQT 93VYXfs2cYNleOKOStqrS7dpyDbHxXpoXgGS/6Rd9lm7xqHbNIuuyoPTr84GaUBl6MGI71 OYYLZzsxg+cqYCcpj7XC4BszmI3VpHqBRaq3Lsnka/5hsCoDXkR1X5XNVqvDbVftXIivnI D+kj5UWB/Oj1OAMyY5znIa+SbWEIEepd4vGxyWwK4VbKsBKAQOjHpv03VpxQkeU70exaZn kPtbRlAosWGWH/IbB9FdyfVfWmYDqJlXhAABFp2ZW66uMS/pN29u+TO9SsplEg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WXj9T4V9YzgDK; Mon, 29 Jul 2024 15:35:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46TFZPxW002627; Mon, 29 Jul 2024 15:35:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46TFZPTT002624; Mon, 29 Jul 2024 15:35:25 GMT (envelope-from git) Date: Mon, 29 Jul 2024 15:35:25 GMT Message-Id: <202407291535.46TFZPTT002624@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: a619d8c76c63 - stable/14 - sound: Simplify chn_init() 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/14 X-Git-Reftype: branch X-Git-Commit: a619d8c76c635ab7b3d851b2630700ab46b534db Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=a619d8c76c635ab7b3d851b2630700ab46b534db commit a619d8c76c635ab7b3d851b2630700ab46b534db Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:47 +0000 Commit: Christos Margiolis CommitDate: 2024-07-29 15:34:55 +0000 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 (cherry picked from commit 5b209e153b58515c0315f5902e18ecd7d75ecd2a) --- 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 buffer\n", - __func__); - goto out2; - } - bs = sndbuf_create(c->dev, c->name, "secondary", c); - if (bs == NULL) { - device_printf(d->dev, "%s(): failed to create software buffer\n", - __func__); - goto out2; - } + for (i = 0; i < SND_CHN_T_MAX; i++) + c->volume[SND_VOL_C_MASTER][i] = SND_VOL_0DB_MASTER; + + c->volume[SND_VOL_C_MASTER][SND_CHN_T_VOL_0DB] = SND_VOL_0DB_MASTER; + c->volume[SND_VOL_C_PCM][SND_CHN_T_VOL_0DB] = chn_vol_0db_pcm; CHN_LOCK(c); + chn_vpc_reset(c, SND_VOL_C_PCM, 1); + CHN_UNLOCK(c); - ret = EINVAL; fc = feeder_getclass(NULL); if (fc == NULL) { device_printf(d->dev, "%s(): failed to get feeder class\n", __func__); - goto out2; + goto fail; } if (feeder_add(c, fc, NULL)) { device_printf(d->dev, "%s(): failed to add feeder\n", __func__); - goto out2; + goto fail; } - /* - * XXX - sndbuf_setup() & sndbuf_resize() expect to be called - * with the channel unlocked because they are also called - * from driver methods that don't know about locking - */ - CHN_UNLOCK(c); - sndbuf_setup(bs, NULL, 0); - CHN_LOCK(c); + b = sndbuf_create(c->dev, c->name, "primary", c); + bs = sndbuf_create(c->dev, c->name, "secondary", c); + if (b == NULL || bs == NULL) { + device_printf(d->dev, "%s(): failed to create %s buffer\n", + __func__, b == NULL ? "hardware" : "software"); + goto fail; + } c->bufhard = b; c->bufsoft = bs; - c->flags = 0; - c->feederflags = 0; - c->sm = NULL; - c->format = SND_FORMAT(AFMT_U8, 1, 0); - c->speed = DSP_DEFAULT_SPEED; - c->matrix = *feeder_matrix_id_map(SND_CHN_MATRIX_1_0); - c->matrix.id = SND_CHN_MATRIX_PCMCHANNEL; - - for (i = 0; i < SND_CHN_T_MAX; i++) { - c->volume[SND_VOL_C_MASTER][i] = SND_VOL_0DB_MASTER; - } - - c->volume[SND_VOL_C_MASTER][SND_CHN_T_VOL_0DB] = SND_VOL_0DB_MASTER; - c->volume[SND_VOL_C_PCM][SND_CHN_T_VOL_0DB] = chn_vol_0db_pcm; - - memset(c->muted, 0, sizeof(c->muted)); - - chn_vpc_reset(c, SND_VOL_C_PCM, 1); - - ret = ENODEV; - CHN_UNLOCK(c); /* XXX - Unlock for CHANNEL_INIT() malloc() call */ c->devinfo = CHANNEL_INIT(c->methods, devinfo, b, c, direction); - CHN_LOCK(c); if (c->devinfo == NULL) { - device_printf(d->dev, "%s(): NULL devinfo\n", __func__); - goto out2; + device_printf(d->dev, "%s(): CHANNEL_INIT() failed\n", __func__); + goto fail; } - ret = ENOMEM; if ((sndbuf_getsize(b) == 0) && ((c->flags & CHN_F_VIRTUAL) == 0)) { device_printf(d->dev, "%s(): hardware buffer's size is 0\n", __func__); - goto out2; + goto fail; } - ret = 0; - c->direction = direction; - sndbuf_setfmt(b, c->format); sndbuf_setspd(b, c->speed); sndbuf_setfmt(bs, c->format); sndbuf_setspd(bs, c->speed); + sndbuf_setup(bs, NULL, 0); /** * @todo Should this be moved somewhere else? The primary buffer @@ -1355,42 +1313,33 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, bs->sl = sndbuf_getmaxsize(bs); bs->shadbuf = malloc(bs->sl, M_DEVBUF, M_NOWAIT); if (bs->shadbuf == NULL) { - ret = ENOMEM; device_printf(d->dev, "%s(): failed to create shadow " "buffer\n", __func__); - goto out2; + goto fail; } } -out2: - if (CHN_LOCKOWNED(c)) - CHN_UNLOCK(c); - if (ret) { - while (feeder_remove(c) == 0) - ; - if (c->devinfo) { - if (CHANNEL_FREE(c->methods, c->devinfo)) - sndbuf_free(b); - } - if (bs) - sndbuf_destroy(bs); - if (b) - sndbuf_destroy(b); - CHN_LOCK(c); - c->flags |= CHN_F_DEAD; - chn_lockdestroy(c); - PCM_LOCK(d); + PCM_LOCK(d); - kobj_delete(c->methods, M_DEVBUF); - free(c, M_DEVBUF); + return (c); - return (NULL); - } +fail: + while (feeder_remove(c) == 0) + ; + if (c->devinfo && CHANNEL_FREE(c->methods, c->devinfo)) + sndbuf_free(b); + if (bs) + sndbuf_destroy(bs); + if (b) + sndbuf_destroy(b); + CHN_LOCK(c); + chn_lockdestroy(c); + + kobj_delete(c->methods, M_DEVBUF); + free(c, M_DEVBUF); PCM_LOCK(d); - return (c); -out1: return (NULL); }