diff options
| author | isaki <isaki@NetBSD.org> | 2019-07-07 06:29:14 +0000 |
|---|---|---|
| committer | isaki <isaki@NetBSD.org> | 2019-07-07 06:29:14 +0000 |
| commit | 336aefe466b477ecbdeb8935bb9efccfda15da13 (patch) | |
| tree | b4fa574ee03121b1401a128cae344ee48760fe97 /sys/dev/audio | |
| parent | a1790d6c3520e99bbee2e73c321bf542cb984367 (diff) | |
Avoid memory reallocation on SET_FORMAT.
Diffstat (limited to 'sys/dev/audio')
| -rw-r--r-- | sys/dev/audio/audio.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/sys/dev/audio/audio.c b/sys/dev/audio/audio.c index 1bb45671843..58a9ef00fd5 100644 --- a/sys/dev/audio/audio.c +++ b/sys/dev/audio/audio.c @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.25 2019/07/07 06:14:21 isaki Exp $ */ +/* $NetBSD: audio.c,v 1.26 2019/07/07 06:29:14 isaki Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -142,7 +142,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.25 2019/07/07 06:14:21 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.26 2019/07/07 06:29:14 isaki Exp $"); #ifdef _KERNEL_OPT #include "audio.h" @@ -5967,11 +5967,14 @@ audio_mixers_init(struct audio_softc *sc, int mode, KASSERT(mutex_owned(sc->sc_lock)); if ((mode & AUMODE_PLAY)) { - if (sc->sc_pmixer) { + if (sc->sc_pmixer == NULL) { + sc->sc_pmixer = kmem_zalloc(sizeof(*sc->sc_pmixer), + KM_SLEEP); + } else { + /* destroy() doesn't free memory. */ audio_mixer_destroy(sc, sc->sc_pmixer); - kmem_free(sc->sc_pmixer, sizeof(*sc->sc_pmixer)); + memset(sc->sc_pmixer, 0, sizeof(*sc->sc_pmixer)); } - sc->sc_pmixer = kmem_zalloc(sizeof(*sc->sc_pmixer), KM_SLEEP); error = audio_mixer_init(sc, AUMODE_PLAY, phwfmt, pfil); if (error) { aprint_error_dev(sc->sc_dev, @@ -5982,11 +5985,14 @@ audio_mixers_init(struct audio_softc *sc, int mode, } } if ((mode & AUMODE_RECORD)) { - if (sc->sc_rmixer) { + if (sc->sc_rmixer == NULL) { + sc->sc_rmixer = kmem_zalloc(sizeof(*sc->sc_rmixer), + KM_SLEEP); + } else { + /* destroy() doesn't free memory. */ audio_mixer_destroy(sc, sc->sc_rmixer); - kmem_free(sc->sc_rmixer, sizeof(*sc->sc_rmixer)); + memset(sc->sc_rmixer, 0, sizeof(*sc->sc_rmixer)); } - sc->sc_rmixer = kmem_zalloc(sizeof(*sc->sc_rmixer), KM_SLEEP); error = audio_mixer_init(sc, AUMODE_RECORD, rhwfmt, rfil); if (error) { aprint_error_dev(sc->sc_dev, |
