Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/audio Avoid memory reallocation on SET_FORMAT.



details:   https://anonhg.NetBSD.org/src/rev/a582efae2f65
branches:  trunk
changeset: 461777:a582efae2f65
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sun Jul 07 06:29:14 2019 +0000

description:
Avoid memory reallocation on SET_FORMAT.

diffstat:

 sys/dev/audio/audio.c |  26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diffs (56 lines):

diff -r d619d4f471d8 -r a582efae2f65 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Sun Jul 07 06:14:21 2019 +0000
+++ b/sys/dev/audio/audio.c     Sun Jul 07 06:29:14 2019 +0000
@@ -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 @@
        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));
-               }
-               sc->sc_pmixer = kmem_zalloc(sizeof(*sc->sc_pmixer), KM_SLEEP);
+                       memset(sc->sc_pmixer, 0, sizeof(*sc->sc_pmixer));
+               }
                error = audio_mixer_init(sc, AUMODE_PLAY, phwfmt, pfil);
                if (error) {
                        aprint_error_dev(sc->sc_dev,
@@ -5982,11 +5985,14 @@
                }
        }
        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));
-               }
-               sc->sc_rmixer = kmem_zalloc(sizeof(*sc->sc_rmixer), KM_SLEEP);
+                       memset(sc->sc_rmixer, 0, sizeof(*sc->sc_rmixer));
+               }
                error = audio_mixer_init(sc, AUMODE_RECORD, rhwfmt, rfil);
                if (error) {
                        aprint_error_dev(sc->sc_dev,



Home | Main Index | Thread Index | Old Index