Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/audio Improve and simplify around audio_realloc().
details: https://anonhg.NetBSD.org/src/rev/99e551f26e92
branches: trunk
changeset: 1005922:99e551f26e92
user: isaki <isaki%NetBSD.org@localhost>
date: Thu Dec 26 11:27:03 2019 +0000
description:
Improve and simplify around audio_realloc().
diffstat:
sys/dev/audio/audio.c | 90 +++++++++-----------------------------------------
1 files changed, 16 insertions(+), 74 deletions(-)
diffs (237 lines):
diff -r de73212c2030 -r 99e551f26e92 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c Thu Dec 26 11:24:55 2019 +0000
+++ b/sys/dev/audio/audio.c Thu Dec 26 11:27:03 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audio.c,v 1.34 2019/12/26 11:24:55 isaki Exp $ */
+/* $NetBSD: audio.c,v 1.35 2019/12/26 11:27:03 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.34 2019/12/26 11:24:55 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.35 2019/12/26 11:27:03 isaki Exp $");
#ifdef _KERNEL_OPT
#include "audio.h"
@@ -3061,30 +3061,6 @@
}
/*
- * Reallocate 'memblock' with specified 'bytes' if 'bytes' > 0.
- * Or free 'memblock' and return NULL if 'byte' is zero.
- */
-static void *
-audio_realloc(void *memblock, size_t bytes)
-{
-
- if (memblock != NULL) {
- if (bytes != 0) {
- return kern_realloc(memblock, bytes, M_WAITOK);
- } else {
- kern_free(memblock);
- return NULL;
- }
- } else {
- if (bytes != 0) {
- return kern_malloc(bytes, M_WAITOK);
- } else {
- return NULL;
- }
- }
-}
-
-/*
* Free 'mem' if available, and initialize the pointer.
* For this reason, this is implemented as macro.
*/
@@ -3096,6 +3072,20 @@
} while (0)
/*
+ * (Re)allocate 'memblock' with specified 'bytes'.
+ * bytes must not be 0.
+ * This function never returns NULL.
+ */
+static void *
+audio_realloc(void *memblock, size_t bytes)
+{
+
+ KASSERT(bytes != 0);
+ audio_free(memblock);
+ return kern_malloc(bytes, M_WAITOK);
+}
+
+/*
* (Re)allocate usrbuf with 'newbufsize' bytes.
* Use this function for usrbuf because only usrbuf can be mmapped.
* If successful, it updates track->usrbuf.mem, track->usrbuf.capacity and
@@ -3660,7 +3650,6 @@
static int
audio_track_init_codec(audio_track_t *track, audio_ring_t **last_dstp)
{
- struct audio_softc *sc;
audio_ring_t *last_dst;
audio_ring_t *srcbuf;
audio_format2_t *srcfmt;
@@ -3671,7 +3660,6 @@
KASSERT(track);
- sc = track->mixer->sc;
last_dst = *last_dstp;
dstfmt = &last_dst->fmt;
srcfmt = &track->inputfmt;
@@ -3700,12 +3688,6 @@
srcbuf->capacity = frame_per_block(track->mixer, &srcbuf->fmt);
len = auring_bytelen(srcbuf);
srcbuf->mem = audio_realloc(srcbuf->mem, len);
- if (srcbuf->mem == NULL) {
- device_printf(sc->sc_dev, "%s: malloc(%d) failed\n",
- __func__, len);
- error = ENOMEM;
- goto abort;
- }
arg = &track->codec.arg;
arg->srcfmt = &srcbuf->fmt;
@@ -3731,7 +3713,6 @@
static int
audio_track_init_chvol(audio_track_t *track, audio_ring_t **last_dstp)
{
- struct audio_softc *sc;
audio_ring_t *last_dst;
audio_ring_t *srcbuf;
audio_format2_t *srcfmt;
@@ -3742,7 +3723,6 @@
KASSERT(track);
- sc = track->mixer->sc;
last_dst = *last_dstp;
dstfmt = &last_dst->fmt;
srcfmt = &track->inputfmt;
@@ -3770,12 +3750,6 @@
srcbuf->capacity = frame_per_block(track->mixer, &srcbuf->fmt);
len = auring_bytelen(srcbuf);
srcbuf->mem = audio_realloc(srcbuf->mem, len);
- if (srcbuf->mem == NULL) {
- device_printf(sc->sc_dev, "%s: malloc(%d) failed\n",
- __func__, len);
- error = ENOMEM;
- goto abort;
- }
arg = &track->chvol.arg;
arg->srcfmt = &srcbuf->fmt;
@@ -3786,7 +3760,6 @@
return 0;
}
-abort:
track->chvol.filter = NULL;
audio_free(srcbuf->mem);
return error;
@@ -3801,7 +3774,6 @@
static int
audio_track_init_chmix(audio_track_t *track, audio_ring_t **last_dstp)
{
- struct audio_softc *sc;
audio_ring_t *last_dst;
audio_ring_t *srcbuf;
audio_format2_t *srcfmt;
@@ -3814,7 +3786,6 @@
KASSERT(track);
- sc = track->mixer->sc;
last_dst = *last_dstp;
dstfmt = &last_dst->fmt;
srcfmt = &track->inputfmt;
@@ -3845,12 +3816,6 @@
srcbuf->capacity = frame_per_block(track->mixer, &srcbuf->fmt);
len = auring_bytelen(srcbuf);
srcbuf->mem = audio_realloc(srcbuf->mem, len);
- if (srcbuf->mem == NULL) {
- device_printf(sc->sc_dev, "%s: malloc(%d) failed\n",
- __func__, len);
- error = ENOMEM;
- goto abort;
- }
arg = &track->chmix.arg;
arg->srcfmt = &srcbuf->fmt;
@@ -3861,7 +3826,6 @@
return 0;
}
-abort:
track->chmix.filter = NULL;
audio_free(srcbuf->mem);
return error;
@@ -3876,7 +3840,6 @@
static int
audio_track_init_freq(audio_track_t *track, audio_ring_t **last_dstp)
{
- struct audio_softc *sc;
audio_ring_t *last_dst;
audio_ring_t *srcbuf;
audio_format2_t *srcfmt;
@@ -3891,7 +3854,6 @@
KASSERT(track);
- sc = track->mixer->sc;
last_dst = *last_dstp;
dstfmt = &last_dst->fmt;
srcfmt = &track->inputfmt;
@@ -3930,12 +3892,6 @@
srcbuf->capacity = frame_per_block(track->mixer, &srcbuf->fmt);
len = auring_bytelen(srcbuf);
srcbuf->mem = audio_realloc(srcbuf->mem, len);
- if (srcbuf->mem == NULL) {
- device_printf(sc->sc_dev, "%s: malloc(%d) failed\n",
- __func__, len);
- error = ENOMEM;
- goto abort;
- }
arg = &track->freq.arg;
arg->srcfmt = &srcbuf->fmt;
@@ -3946,7 +3902,6 @@
return 0;
}
-abort:
track->freq.filter = NULL;
audio_free(srcbuf->mem);
return error;
@@ -4128,12 +4083,6 @@
frame_per_block(track->mixer, &track->input->fmt);
len = auring_bytelen(track->input);
track->input->mem = audio_realloc(track->input->mem, len);
- if (track->input->mem == NULL) {
- device_printf(sc->sc_dev, "malloc input(%d) failed\n",
- len);
- error = ENOMEM;
- goto error;
- }
}
/*
@@ -4728,13 +4677,6 @@
len = mixer->frames_per_block * mixer->mixfmt.channels *
mixer->mixfmt.stride / NBBY;
mixer->mixsample = audio_realloc(mixer->mixsample, len);
- if (mixer->mixsample == NULL) {
- device_printf(sc->sc_dev,
- "%s: malloc mixsample(%d) failed\n",
- __func__, len);
- error = ENOMEM;
- goto abort;
- }
} else {
/* No mixing buffer for recording */
}
Home |
Main Index |
Thread Index |
Old Index