From nobody Fri Oct 18 08:45:00 2024 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 4XVJDY30mgz5YwMk; Fri, 18 Oct 2024 08:45:01 +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 4XVJDX483Jz4m8w; Fri, 18 Oct 2024 08:45:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729241100; 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=2MkhIGBQJF2xoXke8YZFzjP1wJWXdzfj5d+4Uo5/ypQ=; b=V5meOHiGQbYM3aXWKJrvbaYVtguqu2WzX7ea/0TNAJ4Un6YPY90p2VLnxaOYRPIBPWs7bz V6zLeXwzZa9RbQEZt5kU8B5vGhllVeo1y48XpuawmLFrIsV30cazTEpB6DI/uzsHta7Cnn //DVngOEWUPGdsOA6PmgSSD6aya3iU1B0dv+4PI9Xqa+lk4FMd5O+f08KWNb6bWweENemo c/+nbTnw3xwGxi2df2Nzssh5xDAL+1Y9doHM9+Nz0GBj38HPOE4A9r25ZlBcM2m4P1ALa1 jEHlKYbEhFsxYXFFSO/aJxbVxWMYgutrMqcydtdkdpmIN6TXiaTVfGQQk6wX9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729241100; 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=2MkhIGBQJF2xoXke8YZFzjP1wJWXdzfj5d+4Uo5/ypQ=; b=kySk3YVX4VmWp1qrujZuACBSoPaDBaCGP4zsPrcYM01knW71jdkPRIg6IrLftcQvKC5Mgy s7rjGuvAF9nCfOurNEfeGod5hN8UUH4In247mBaSAqAIHCKPnl7BYNEaZkCC4VV9zWevJ7 YnQqL35VBLBQVjhtvgOwff5AzXHJeH+NX3Kw9bfj2mGJfSOwWtSpTUngo70Hhsm+Rakiw2 +JKCWF/p3jYb0zLj9n+flWHCn8faxFfoDt5Az6TtjCxDygrOjhbRRgc620/AG7RdCL6dXW srRKLCDYAkBKTFYYK208f7jLLjyPkj3stV+mICIOPzqu/SGDnBn7ODI+45SeoA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729241100; a=rsa-sha256; cv=none; b=sZSxdyrj5RZRpZvxeWqxhMNYUxl3g7K2bTzVuNLyCtujuQ03O7Qz52xxjiJgGBjAaScGpu Ctnz4S0ZphnCuo24nBBgSM+xcb/pnH5iD+XFJ3hCcQaSFjZUBJiWUchV2kH/83LaS7jhC6 m31OjYc82siL2TL8ykEgl/GkmI9hw/uL2D92h/tpkwPczc3gsdfnDRN78Z67zunhxGG4Pr gysmzx1+lHhuakQWleEewyDQeil+s3/JDn36ulMfRpEMt4Z8JcirXcZRgQjk/KLlXCHY1Q M4J5pHXhDSTTiFlYjd/v749riTHG63ofHqNY7llkwQNYhDZXLQqsj3VravP+BA== 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 4XVJDX3llVzRnm; Fri, 18 Oct 2024 08:45:00 +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 49I8j0r4088148; Fri, 18 Oct 2024 08:45:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49I8j0ps088145; Fri, 18 Oct 2024 08:45:00 GMT (envelope-from git) Date: Fri, 18 Oct 2024 08:45:00 GMT Message-Id: <202410180845.49I8j0ps088145@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 3cab66d12d43 - main - sound: Simplify vchan_create() error paths 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: 3cab66d12d439357b948093756ca1af87967c8cc Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=3cab66d12d439357b948093756ca1af87967c8cc commit 3cab66d12d439357b948093756ca1af87967c8cc Author: Christos Margiolis AuthorDate: 2024-10-18 08:40:23 +0000 Commit: Christos Margiolis CommitDate: 2024-10-18 08:40:23 +0000 sound: Simplify vchan_create() error paths Instead of checking the value of "ret" multiple times, just set a goto label and jump there immediately in case of an error. While here, remove a redundant assignment to "d". Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch, markj, emaste Differential Revision: https://reviews.freebsd.org/D46833 --- sys/dev/sound/pcm/vchan.c | 76 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/sys/dev/sound/pcm/vchan.c b/sys/dev/sound/pcm/vchan.c index c1ad9b9ec2ba..9046c144b41b 100644 --- a/sys/dev/sound/pcm/vchan.c +++ b/sys/dev/sound/pcm/vchan.c @@ -674,8 +674,11 @@ vchan_create(struct pcm_channel *parent) struct pcm_channel *ch; struct pcmchan_caps *parent_caps; uint32_t vchanfmt, vchanspd; - int ret, direction, r, save; + int ret, direction, r; + bool save; + ret = 0; + save = false; d = parent->parentsnddev; PCM_BUSYASSERT(d); @@ -688,8 +691,6 @@ vchan_create(struct pcm_channel *parent) parent->direction == PCMDIR_REC)) return (EINVAL); - d = parent->parentsnddev; - CHN_UNLOCK(parent); PCM_LOCK(d); @@ -728,14 +729,13 @@ vchan_create(struct pcm_channel *parent) parent->flags |= CHN_F_HAS_VCHAN; - ret = 0; parent_caps = chn_getcaps(parent); - if (parent_caps == NULL) + if (parent_caps == NULL) { ret = EINVAL; + goto fail; + } - save = 0; - - if (ret == 0 && vchanfmt == 0) { + if (vchanfmt == 0) { const char *vfmt; CHN_UNLOCK(parent); @@ -752,10 +752,10 @@ vchan_create(struct pcm_channel *parent) } if (vchanfmt == 0) vchanfmt = VCHAN_DEFAULT_FORMAT; - save = 1; + save = true; } - if (ret == 0 && vchanspd == 0) { + if (vchanspd == 0) { /* * This is very sad. Few soundcards advertised as being * able to do (insanely) higher/lower speed, but in @@ -773,26 +773,25 @@ vchan_create(struct pcm_channel *parent) RANGE(vchanspd, parent_caps->minspeed, parent_caps->maxspeed); } - save = 1; + save = true; } - if (ret == 0) { - /* - * Limit the speed between feeder_rate_min <-> feeder_rate_max. - */ - RANGE(vchanspd, feeder_rate_min, feeder_rate_max); - - if (feeder_rate_round) { - RANGE(vchanspd, parent_caps->minspeed, - parent_caps->maxspeed); - vchanspd = CHANNEL_SETSPEED(parent->methods, - parent->devinfo, vchanspd); - } + /* + * Limit the speed between feeder_rate_min <-> feeder_rate_max. + */ + RANGE(vchanspd, feeder_rate_min, feeder_rate_max); - ret = chn_reset(parent, vchanfmt, vchanspd); + if (feeder_rate_round) { + RANGE(vchanspd, parent_caps->minspeed, + parent_caps->maxspeed); + vchanspd = CHANNEL_SETSPEED(parent->methods, + parent->devinfo, vchanspd); } - if (ret == 0 && save) { + if ((ret = chn_reset(parent, vchanfmt, vchanspd)) != 0) + goto fail; + + if (save) { /* * Save new value. */ @@ -809,23 +808,24 @@ vchan_create(struct pcm_channel *parent) * If the parent channel supports digital format, * enable passthrough mode. */ - if (ret == 0 && snd_fmtvalid(AFMT_PASSTHROUGH, parent_caps->fmtlist)) { + if (snd_fmtvalid(AFMT_PASSTHROUGH, parent_caps->fmtlist)) { parent->flags &= ~CHN_F_VCHAN_DYNAMIC; parent->flags |= CHN_F_VCHAN_PASSTHROUGH; } - if (ret != 0) { - CHN_REMOVE(parent, ch, children); - parent->flags &= ~CHN_F_HAS_VCHAN; - CHN_UNLOCK(parent); - PCM_LOCK(d); - if (pcm_chn_remove(d, ch) == 0) { - PCM_UNLOCK(d); - chn_kill(ch); - } else - PCM_UNLOCK(d); - CHN_LOCK(parent); - } + return (ret); + +fail: + CHN_REMOVE(parent, ch, children); + parent->flags &= ~CHN_F_HAS_VCHAN; + CHN_UNLOCK(parent); + PCM_LOCK(d); + if (pcm_chn_remove(d, ch) == 0) { + PCM_UNLOCK(d); + chn_kill(ch); + } else + PCM_UNLOCK(d); + CHN_LOCK(parent); return (ret); }