git: 43c0b593c2c3 - main - sound: Remove redundant refcount checks in vchan_setnew()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 25 Oct 2024 11:37:04 UTC
The branch main has been updated by christos:
URL: https://cgit.FreeBSD.org/src/commit/?id=43c0b593c2c3b2c07009c031a0e7e8190a45b31a
commit 43c0b593c2c3b2c07009c031a0e7e8190a45b31a
Author: Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-10-25 11:36:51 +0000
Commit: Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-10-25 11:36:51 +0000
sound: Remove redundant refcount checks in vchan_setnew()
When adding a new vchan, we are looking for a parent channel which
either already has vchans (i.e CHN_F_HAS_VCHAN), or does not, but is
also not being used (i.e !CHN_F_BUSY). Since CHN_F_BUSY essentially
tells us if the channel is currently being used or not, there is no need
to check if the channel's refcount is 0 as well.
When removing a vchan, we first check if we have only 1 vchan allocated
that is also being used (so we cannot remove it at the moment), and then
we check if the vchan is not busy and remove it. Again, checking
CHN_F_BUSY is enough.
Sponsored by: The FreeBSD Foundation
MFC after: 2 days
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D47268
---
sys/dev/sound/pcm/vchan.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sys/dev/sound/pcm/vchan.c b/sys/dev/sound/pcm/vchan.c
index c9db9d79847b..ed13a3c55961 100644
--- a/sys/dev/sound/pcm/vchan.c
+++ b/sys/dev/sound/pcm/vchan.c
@@ -928,7 +928,6 @@ vchan_setnew(struct snddev_info *d, int direction, int newcnt)
CHN_LOCK(c);
if (c->direction == direction &&
((c->flags & CHN_F_HAS_VCHAN) || (vcnt == 0 &&
- c->refcount < 1 &&
!(c->flags & (CHN_F_BUSY | CHN_F_VIRTUAL))))) {
/*
* Reuse hw channel with vchans already
@@ -987,12 +986,11 @@ vchan_setnew(struct snddev_info *d, int direction, int newcnt)
}
CHN_FOREACH_SAFE(ch, c, nch, children) {
CHN_LOCK(ch);
- if (vcnt == 1 && c->refcount > 0) {
+ if (vcnt == 1 && ch->flags & CHN_F_BUSY) {
CHN_UNLOCK(ch);
break;
}
- if (!(ch->flags & CHN_F_BUSY) &&
- ch->refcount < 1) {
+ if (!(ch->flags & CHN_F_BUSY)) {
err = vchan_destroy(ch);
if (err == 0)
vcnt--;