aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Margiolis <christos@FreeBSD.org>2024-07-27 11:55:32 +0000
committerChristos Margiolis <christos@FreeBSD.org>2024-07-27 11:55:32 +0000
commit85d1c84c2406aa2e4e2114215b01eee65714848f (patch)
tree71b3f51919c7206309351a6baa13534cf59bfb88
parent16329b7b3276f09dc70bdd1ca8bc605546fe71e0 (diff)
downloadsrc-85d1c84c2406aa2e4e2114215b01eee65714848f.tar.gz
src-85d1c84c2406aa2e4e2114215b01eee65714848f.zip
snd_hdsp*: Free up channel resources in case of CHANNEL_INIT() failure
Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45982
-rw-r--r--sys/dev/sound/pci/hdsp-pcm.c59
-rw-r--r--sys/dev/sound/pci/hdspe-pcm.c59
2 files changed, 60 insertions, 58 deletions
diff --git a/sys/dev/sound/pci/hdsp-pcm.c b/sys/dev/sound/pci/hdsp-pcm.c
index 9ba0e5e345d0..29bd0bc70ee4 100644
--- a/sys/dev/sound/pci/hdsp-pcm.c
+++ b/sys/dev/sound/pci/hdsp-pcm.c
@@ -661,6 +661,35 @@ clean(struct sc_chinfo *ch)
}
/* Channel interface. */
+static int
+hdspchan_free(kobj_t obj, void *data)
+{
+ struct sc_pcminfo *scp;
+ struct sc_chinfo *ch;
+ struct sc_info *sc;
+
+ ch = data;
+ scp = ch->parent;
+ sc = scp->sc;
+
+#if 0
+ device_printf(scp->dev, "hdspchan_free()\n");
+#endif
+
+ snd_mtxlock(sc->lock);
+ if (ch->data != NULL) {
+ free(ch->data, M_HDSP);
+ ch->data = NULL;
+ }
+ if (ch->caps != NULL) {
+ free(ch->caps, M_HDSP);
+ ch->caps = NULL;
+ }
+ snd_mtxunlock(sc->lock);
+
+ return (0);
+}
+
static void *
hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
struct pcm_channel *c, int dir)
@@ -720,6 +749,7 @@ hdspchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
if (sndbuf_setup(ch->buffer, ch->data, ch->size) != 0) {
device_printf(scp->dev, "Can't setup sndbuf.\n");
+ hdspchan_free(obj, ch);
return (NULL);
}
@@ -794,35 +824,6 @@ hdspchan_getptr(kobj_t obj, void *data)
}
static int
-hdspchan_free(kobj_t obj, void *data)
-{
- struct sc_pcminfo *scp;
- struct sc_chinfo *ch;
- struct sc_info *sc;
-
- ch = data;
- scp = ch->parent;
- sc = scp->sc;
-
-#if 0
- device_printf(scp->dev, "hdspchan_free()\n");
-#endif
-
- snd_mtxlock(sc->lock);
- if (ch->data != NULL) {
- free(ch->data, M_HDSP);
- ch->data = NULL;
- }
- if (ch->caps != NULL) {
- free(ch->caps, M_HDSP);
- ch->caps = NULL;
- }
- snd_mtxunlock(sc->lock);
-
- return (0);
-}
-
-static int
hdspchan_setformat(kobj_t obj, void *data, uint32_t format)
{
struct sc_chinfo *ch;
diff --git a/sys/dev/sound/pci/hdspe-pcm.c b/sys/dev/sound/pci/hdspe-pcm.c
index e7fa03904595..79bfcbea3406 100644
--- a/sys/dev/sound/pci/hdspe-pcm.c
+++ b/sys/dev/sound/pci/hdspe-pcm.c
@@ -650,6 +650,35 @@ clean(struct sc_chinfo *ch)
}
/* Channel interface. */
+static int
+hdspechan_free(kobj_t obj, void *data)
+{
+ struct sc_pcminfo *scp;
+ struct sc_chinfo *ch;
+ struct sc_info *sc;
+
+ ch = data;
+ scp = ch->parent;
+ sc = scp->sc;
+
+#if 0
+ device_printf(scp->dev, "hdspechan_free()\n");
+#endif
+
+ snd_mtxlock(sc->lock);
+ if (ch->data != NULL) {
+ free(ch->data, M_HDSPE);
+ ch->data = NULL;
+ }
+ if (ch->caps != NULL) {
+ free(ch->caps, M_HDSPE);
+ ch->caps = NULL;
+ }
+ snd_mtxunlock(sc->lock);
+
+ return (0);
+}
+
static void *
hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
struct pcm_channel *c, int dir)
@@ -702,6 +731,7 @@ hdspechan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
if (sndbuf_setup(ch->buffer, ch->data, ch->size) != 0) {
device_printf(scp->dev, "Can't setup sndbuf.\n");
+ hdspechan_free(obj, ch);
return (NULL);
}
@@ -775,35 +805,6 @@ hdspechan_getptr(kobj_t obj, void *data)
}
static int
-hdspechan_free(kobj_t obj, void *data)
-{
- struct sc_pcminfo *scp;
- struct sc_chinfo *ch;
- struct sc_info *sc;
-
- ch = data;
- scp = ch->parent;
- sc = scp->sc;
-
-#if 0
- device_printf(scp->dev, "hdspechan_free()\n");
-#endif
-
- snd_mtxlock(sc->lock);
- if (ch->data != NULL) {
- free(ch->data, M_HDSPE);
- ch->data = NULL;
- }
- if (ch->caps != NULL) {
- free(ch->caps, M_HDSPE);
- ch->caps = NULL;
- }
- snd_mtxunlock(sc->lock);
-
- return (0);
-}
-
-static int
hdspechan_setformat(kobj_t obj, void *data, uint32_t format)
{
struct sc_chinfo *ch;