git: 532b1efd2d2e - stable/14 - sound: Merge pcm_chn_destroy() and chn_kill()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 17 May 2024 19:30:56 UTC
The branch stable/14 has been updated by christos:
URL: https://cgit.FreeBSD.org/src/commit/?id=532b1efd2d2e659a488bf147ca817ceabb5d8997
commit 532b1efd2d2e659a488bf147ca817ceabb5d8997
Author: Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-04-28 19:46:08 +0000
Commit: Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-17 19:30:34 +0000
sound: Merge pcm_chn_destroy() and chn_kill()
pcm_chn_destroy() acts like a wrapper around chn_kill(), and
additionally calls a few more functions that should in fact be part of
chn_kill()'s logic. Merge pcm_chn_destroy()'s functionality in
chn_kill() to improve readability, as well as code layering.
While here, convert chn_kill() to void as it currently always returns 0.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44984
(cherry picked from commit b3ea087c05d8c75978a302cbb3fa92ce1afa3e49)
---
sys/dev/sound/pcm/channel.c | 12 +++++++-----
sys/dev/sound/pcm/channel.h | 2 +-
sys/dev/sound/pcm/sound.c | 26 ++------------------------
sys/dev/sound/pcm/sound.h | 1 -
sys/dev/sound/pcm/vchan.c | 6 +++---
5 files changed, 13 insertions(+), 34 deletions(-)
diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c
index 1527d5ea3d2c..21a91ff13186 100644
--- a/sys/dev/sound/pcm/channel.c
+++ b/sys/dev/sound/pcm/channel.c
@@ -1279,11 +1279,13 @@ out:
return 0;
}
-int
+void
chn_kill(struct pcm_channel *c)
{
- struct snd_dbuf *b = c->bufhard;
- struct snd_dbuf *bs = c->bufsoft;
+ struct snd_dbuf *b = c->bufhard;
+ struct snd_dbuf *bs = c->bufsoft;
+
+ PCM_BUSYASSERT(c->parentsnddev);
if (CHN_STARTED(c)) {
CHN_LOCK(c);
@@ -1299,8 +1301,8 @@ chn_kill(struct pcm_channel *c)
CHN_LOCK(c);
c->flags |= CHN_F_DEAD;
chn_lockdestroy(c);
-
- return (0);
+ kobj_delete(c->methods, M_DEVBUF);
+ free(c, M_DEVBUF);
}
void
diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h
index d4f73275ed39..45381b907fa2 100644
--- a/sys/dev/sound/pcm/channel.h
+++ b/sys/dev/sound/pcm/channel.h
@@ -260,7 +260,7 @@ int chn_flush(struct pcm_channel *c);
int chn_poll(struct pcm_channel *c, int ev, struct thread *td);
int chn_init(struct pcm_channel *c, void *devinfo, int dir, int direction);
-int chn_kill(struct pcm_channel *c);
+void chn_kill(struct pcm_channel *c);
void chn_shutdown(struct pcm_channel *c);
int chn_reset(struct pcm_channel *c, u_int32_t fmt, u_int32_t spd);
int chn_setvolume_multi(struct pcm_channel *c, int vc, int left, int right,
diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index 652f59494697..b3ae93b77a5d 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -515,28 +515,6 @@ pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t c
return (ch);
}
-int
-pcm_chn_destroy(struct pcm_channel *ch)
-{
- struct snddev_info *d __diagused;
- int err;
-
- d = ch->parentsnddev;
- PCM_BUSYASSERT(d);
-
- err = chn_kill(ch);
- if (err) {
- device_printf(ch->dev, "chn_kill(%s) failed, err = %d\n",
- ch->name, err);
- return (err);
- }
-
- kobj_delete(ch->methods, M_DEVBUF);
- free(ch, M_DEVBUF);
-
- return (0);
-}
-
int
pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
{
@@ -630,7 +608,7 @@ pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
if (err) {
device_printf(d->dev, "pcm_chn_add(%s) failed, err=%d\n",
ch->name, err);
- pcm_chn_destroy(ch);
+ chn_kill(ch);
}
return (err);
@@ -678,7 +656,7 @@ pcm_killchans(struct snddev_info *d)
error = pcm_chn_remove(d, ch);
PCM_UNLOCK(d);
if (error == 0)
- pcm_chn_destroy(ch);
+ chn_kill(ch);
} while (!CHN_EMPTY(d, channels.pcm));
}
diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h
index 1f2dda880742..70addf32bddd 100644
--- a/sys/dev/sound/pcm/sound.h
+++ b/sys/dev/sound/pcm/sound.h
@@ -300,7 +300,6 @@ int pcm_chnrelease(struct pcm_channel *c);
int pcm_chnref(struct pcm_channel *c, int ref);
struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo);
-int pcm_chn_destroy(struct pcm_channel *ch);
int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);
int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch);
diff --git a/sys/dev/sound/pcm/vchan.c b/sys/dev/sound/pcm/vchan.c
index ac5a0535ddce..c3bc36d924bd 100644
--- a/sys/dev/sound/pcm/vchan.c
+++ b/sys/dev/sound/pcm/vchan.c
@@ -709,7 +709,7 @@ vchan_create(struct pcm_channel *parent, int num)
ret = pcm_chn_add(d, ch);
PCM_UNLOCK(d);
if (ret != 0) {
- pcm_chn_destroy(ch);
+ chn_kill(ch);
CHN_LOCK(parent);
return (ret);
}
@@ -837,7 +837,7 @@ vchan_create(struct pcm_channel *parent, int num)
PCM_LOCK(d);
if (pcm_chn_remove(d, ch) == 0) {
PCM_UNLOCK(d);
- pcm_chn_destroy(ch);
+ chn_kill(ch);
} else
PCM_UNLOCK(d);
CHN_LOCK(parent);
@@ -890,7 +890,7 @@ vchan_destroy(struct pcm_channel *c)
/* destroy ourselves */
if (ret == 0)
- ret = pcm_chn_destroy(c);
+ chn_kill(c);
CHN_LOCK(parent);