Module Name: src Committed By: isaki Date: Sun Jul 7 06:29:15 UTC 2019
Modified Files: src/sys/dev/audio: audio.c Log Message: Avoid memory reallocation on SET_FORMAT. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/dev/audio/audio.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/audio/audio.c diff -u src/sys/dev/audio/audio.c:1.25 src/sys/dev/audio/audio.c:1.26 --- src/sys/dev/audio/audio.c:1.25 Sun Jul 7 06:14:21 2019 +++ src/sys/dev/audio/audio.c Sun Jul 7 06:29:14 2019 @@ -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 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 } } 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,