From nobody Sun Oct 20 11:21:39 2024 X-Original-To: dev-commits-src-branches@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 4XWbcN02wqz5YvTm; Sun, 20 Oct 2024 11:21:40 +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 4XWbcM6223z4X4q; Sun, 20 Oct 2024 11:21:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729423299; 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=aZQe67AzrhKb0qdZDGoYFRupNxQjV1HGZpMPxs5v/mA=; b=D9PWO1scE3xhtOW76v2Y8oGom/SMr4Hat33ftKuVFVA5+DasCimtqCjhubXV01+9Ct870u Rr8B7atA7ZDkGxKF232cB9XmAQgA2vcig0s3kMQFlIaxQ+ruQArXyQzpQgXtCIVvulQh23 FzTKRXmcuieWso4CDVZg/wmCW8Bfc5nIOHX/oPM8vbNsyJSGIPUtYTvwFSL1BXn2rdVj8K DKyTsvsg+XMKMgwoV5q+Vixlt7rHg2GW64xedLOpksjKIpTYrEf0lxPXU2fFu0s/1akWv1 lZDIuvJII3cb9PgTdbDwgf3DxTwYopmkFl2E9SEc1kT5tAAOqZnIJlaoe7COyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729423299; 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=aZQe67AzrhKb0qdZDGoYFRupNxQjV1HGZpMPxs5v/mA=; b=aRsmGKdzYpNTExSU4Y/f37uXT+JVgdI1iLCN6oJRS7dQdrMMiXrpflhHSnEl2hfzcca6VD WyuxYTx9+yD4ZhLzFNv4ACMyXfWjMwoRmpb24RMeoVeAmXUbUMAcSkKoDFGL9JTkEvzxNM nnYV3YyNi9BVAZZYhKp904a3cgo2bqbb7RB3gVNGgr+CSumFgWPLCZSlwVEjydcqwBm5vT gc4XZogGLWvXvbQwXMf7upUNUIk6wgAVXeGbn6Ltz0563ZjaB9saQYUB9+MaO8bnvvUnQD Sf+ekshymTOu+wmwn+jD9GkkIfjCrr9Nad6c7CFbYdLTMbYp3i1vthOYWVf/eg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729423299; a=rsa-sha256; cv=none; b=svpc0z9ZkCNgmLUtoJQBDb4as1HmDwCboqwLCNe5zxj0KPRlZTNYVqt+otw/cq5V3ThcxO LVeZFErn8/F0y0bRAJB7Djzld7DUiygCIeC5FIn09Cp4fzG+jQsQJgD6nZk/E5GnruEwN7 F+ZgFLQcabWPOktXFMxNv72RQHn8U8kNGWS0T0myQKI8vcfUpuNNx/E88spRh8zUWFjhyd Yo/OPoHWTZyuuERYMrgErr3hbGFKUE9XxZVH1wjJ1ZtXau8DJ0wXXkk0MbG4W4XOhxGx0k fqx521mEDOfIgT9ZD6u8JuU0aJfvfLI6L0v9v/NxNBi1EfMmjimpeg54wx2jNg== 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 4XWbcM5fSWz108R; Sun, 20 Oct 2024 11:21:39 +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 49KBLd6u062917; Sun, 20 Oct 2024 11:21:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49KBLdtO062914; Sun, 20 Oct 2024 11:21:39 GMT (envelope-from git) Date: Sun, 20 Oct 2024 11:21:39 GMT Message-Id: <202410201121.49KBLdtO062914@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: bf058bde2bca - stable/14 - sound: Simplify vchan_create() error paths List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: bf058bde2bca4d7be03713cadc53be5d5377e983 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=bf058bde2bca4d7be03713cadc53be5d5377e983 commit bf058bde2bca4d7be03713cadc53be5d5377e983 Author: Christos Margiolis AuthorDate: 2024-10-18 08:40:23 +0000 Commit: Christos Margiolis CommitDate: 2024-10-20 11:21:05 +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 (cherry picked from commit 3cab66d12d439357b948093756ca1af87967c8cc) --- 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); }