Module Name: src Committed By: isaki Date: Sat Feb 22 06:58:40 UTC 2020
Modified Files: src/sys/dev/audio: audio.c audiodef.h Log Message: Improve KASSERT messages. To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/sys/dev/audio/audio.c cvs rdiff -u -r1.8 -r1.9 src/sys/dev/audio/audiodef.h 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.46 src/sys/dev/audio/audio.c:1.47 --- src/sys/dev/audio/audio.c:1.46 Sat Feb 22 06:36:07 2020 +++ src/sys/dev/audio/audio.c Sat Feb 22 06:58:39 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $ */ +/* $NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 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.46 2020/02/22 06:36:07 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $"); #ifdef _KERNEL_OPT #include "audio.h" @@ -2062,7 +2062,7 @@ audio_open(dev_t dev, struct audio_softc *bellfile = af; } else { error = fd_clone(fp, fd, flags, &audio_fileops, af); - KASSERT(error == EMOVEFD); + KASSERTMSG(error == EMOVEFD, "error=%d", error); } TRACEF(3, af, "done"); @@ -3060,7 +3060,7 @@ audioctl_open(dev_t dev, struct audio_so /* Not necessary to insert sc_files. */ error = fd_clone(fp, fd, flags, &audio_fileops, af); - KASSERT(error == EMOVEFD); + KASSERTMSG(error == EMOVEFD, "error=%d", error); return error; } @@ -3213,9 +3213,12 @@ audio_track_chvol(audio_filter_arg_t *ar u_int channels; DIAGNOSTIC_filter_arg(arg); - KASSERT(arg->srcfmt->channels == arg->dstfmt->channels); + KASSERTMSG(arg->srcfmt->channels == arg->dstfmt->channels, + "arg->srcfmt->channels=%d, arg->dstfmt->channels=%d", + arg->srcfmt->channels, arg->dstfmt->channels); KASSERT(arg->context != NULL); - KASSERT(arg->srcfmt->channels <= AUDIO_MAX_CHANNELS); + KASSERTMSG(arg->srcfmt->channels <= AUDIO_MAX_CHANNELS, + "arg->srcfmt->channels=%d", arg->srcfmt->channels); s = arg->src; d = arg->dst; @@ -3373,8 +3376,12 @@ audio_track_freq_up(audio_filter_arg_t * DIAGNOSTIC_ring(dst); DIAGNOSTIC_ring(src); KASSERT(src->used > 0); - KASSERT(src->fmt.channels == dst->fmt.channels); - KASSERT(src->head % track->mixer->frames_per_block == 0); + KASSERTMSG(src->fmt.channels == dst->fmt.channels, + "src->fmt.channels=%d dst->fmt.channels=%d", + src->fmt.channels, dst->fmt.channels); + KASSERTMSG(src->head % track->mixer->frames_per_block == 0, + "src->head=%d track->mixer->frames_per_block=%d", + src->head, track->mixer->frames_per_block); s = arg->src; d = arg->dst; @@ -3499,9 +3506,11 @@ audio_track_freq_down(audio_filter_arg_t DIAGNOSTIC_ring(dst); DIAGNOSTIC_ring(src); KASSERT(src->used > 0); - KASSERT(src->fmt.channels == dst->fmt.channels); + KASSERTMSG(src->fmt.channels == dst->fmt.channels, + "src->fmt.channels=%d dst->fmt.channels=%d", + src->fmt.channels, dst->fmt.channels); KASSERTMSG(src->head % track->mixer->frames_per_block == 0, - "src->head=%d fpb=%d", + "src->head=%d track->mixer->frames_per_block=%d", src->head, track->mixer->frames_per_block); s0 = arg->src; @@ -4192,7 +4201,9 @@ audio_append_silence(audio_track_t *trac n = (ring->capacity - ring->used) % fpb; - KASSERT(auring_get_contig_free(ring) >= n); + KASSERTMSG(auring_get_contig_free(ring) >= n, + "auring_get_contig_free(ring)=%d n=%d", + auring_get_contig_free(ring), n); memset(auring_tailptr_aint(ring), 0, n * ring->fmt.channels * sizeof(aint_t)); @@ -4225,7 +4236,7 @@ audio_apply_stage(audio_track_t *track, dstcount = auring_get_contig_free(stage->dst); if (isfreq) { - KASSERTMSG(srccount > 0, "freq but srccount == %d", srccount); + KASSERTMSG(srccount > 0, "freq but srccount=%d", srccount); count = uimin(dstcount, track->mixer->frames_per_block); } else { count = uimin(srccount, dstcount); @@ -4310,7 +4321,8 @@ audio_track_play(audio_track_t *track) int bytes2; bytes1 = auring_get_contig_used(usrbuf); - KASSERT(bytes1 % framesize == 0); + KASSERTMSG(bytes1 % framesize == 0, + "bytes1=%d framesize=%d", bytes1, framesize); memcpy((uint8_t *)input->mem + auring_tail(input) * framesize, (uint8_t *)usrbuf->mem + usrbuf->head, bytes1); @@ -4473,7 +4485,8 @@ audio_track_record(audio_track_t *track) int bytes2; bytes1 = auring_get_contig_free(usrbuf); - KASSERT(bytes1 % framesize == 0); + KASSERTMSG(bytes1 % framesize == 0, + "bytes1=%d framesize=%d", bytes1, framesize); memcpy((uint8_t *)usrbuf->mem + auring_tail(usrbuf), (uint8_t *)outbuf->mem + outbuf->head * framesize, bytes1); @@ -4869,7 +4882,9 @@ audio_pmixer_process(struct audio_softc mixer = sc->sc_pmixer; frame_count = mixer->frames_per_block; - KASSERT(auring_get_contig_free(&mixer->hwbuf) >= frame_count); + KASSERTMSG(auring_get_contig_free(&mixer->hwbuf) >= frame_count, + "auring_get_contig_free()=%d frame_count=%d", + auring_get_contig_free(&mixer->hwbuf), frame_count); sample_count = frame_count * mixer->mixfmt.channels; mixer->mixseq++; @@ -5160,7 +5175,9 @@ audio_pmixer_output(struct audio_softc * TRACE(4, "pbusy=%d hwbuf=%d/%d/%d", sc->sc_pbusy, mixer->hwbuf.head, mixer->hwbuf.used, mixer->hwbuf.capacity); - KASSERT(mixer->hwbuf.used >= mixer->frames_per_block); + KASSERTMSG(mixer->hwbuf.used >= mixer->frames_per_block, + "mixer->hwbuf.used=%d mixer->frames_per_block=%d", + mixer->hwbuf.used, mixer->frames_per_block); blksize = frametobyte(&mixer->hwbuf.fmt, mixer->frames_per_block); @@ -5398,7 +5415,9 @@ audio_rmixer_process(struct audio_softc input->head, input->used, input->capacity); auring_take(input, drops); } - KASSERT(input->used % mixer->frames_per_block == 0); + KASSERTMSG(input->used % mixer->frames_per_block == 0, + "input->used=%d mixer->frames_per_block=%d", + input->used, mixer->frames_per_block); memcpy(auring_tailptr_aint(input), auring_headptr_aint(mixersrc), @@ -6039,8 +6058,7 @@ audio_hw_probe(struct audio_softc *sc, i KASSERT(mutex_owned(sc->sc_lock)); mode = *modep; - KASSERTMSG((mode & (AUMODE_PLAY | AUMODE_RECORD)) != 0, - "invalid mode = %x", mode); + KASSERTMSG((mode & (AUMODE_PLAY | AUMODE_RECORD)) != 0, "mode=0x%x", mode); if (is_indep) { int errorp = 0, errorr = 0; @@ -7535,62 +7553,60 @@ audio_print_format2(const char *s, const #ifdef DIAGNOSTIC void -audio_diagnostic_format2(const char *func, const audio_format2_t *fmt) +audio_diagnostic_format2(const char *where, const audio_format2_t *fmt) { - KASSERTMSG(fmt, "%s: fmt == NULL", func); + KASSERTMSG(fmt, "called from %s", where); /* XXX MSM6258 vs(4) only has 4bit stride format. */ if (fmt->encoding == AUDIO_ENCODING_ADPCM) { KASSERTMSG(fmt->stride == 4 || fmt->stride == 8, - "%s: stride(%d) is invalid", func, fmt->stride); + "called from %s: fmt->stride=%d", where, fmt->stride); } else { KASSERTMSG(fmt->stride % NBBY == 0, - "%s: stride(%d) is invalid", func, fmt->stride); + "called from %s: fmt->stride=%d", where, fmt->stride); } KASSERTMSG(fmt->precision <= fmt->stride, - "%s: precision(%d) <= stride(%d)", - func, fmt->precision, fmt->stride); + "called from %s: fmt->precision=%d fmt->stride=%d", + where, fmt->precision, fmt->stride); KASSERTMSG(1 <= fmt->channels && fmt->channels <= AUDIO_MAX_CHANNELS, - "%s: channels(%d) is out of range", - func, fmt->channels); + "called from %s: fmt->channels=%d", where, fmt->channels); /* XXX No check for encodings? */ } void -audio_diagnostic_filter_arg(const char *func, const audio_filter_arg_t *arg) +audio_diagnostic_filter_arg(const char *where, const audio_filter_arg_t *arg) { KASSERT(arg != NULL); KASSERT(arg->src != NULL); KASSERT(arg->dst != NULL); - DIAGNOSTIC_format2(arg->srcfmt); - DIAGNOSTIC_format2(arg->dstfmt); - KASSERTMSG(arg->count > 0, - "%s: count(%d) is out of range", func, arg->count); + audio_diagnostic_format2(where, arg->srcfmt); + audio_diagnostic_format2(where, arg->dstfmt); + KASSERT(arg->count > 0); } void -audio_diagnostic_ring(const char *func, const audio_ring_t *ring) +audio_diagnostic_ring(const char *where, const audio_ring_t *ring) { - KASSERTMSG(ring, "%s: ring == NULL", func); - DIAGNOSTIC_format2(&ring->fmt); + KASSERTMSG(ring, "called from %s", where); + audio_diagnostic_format2(where, &ring->fmt); KASSERTMSG(0 <= ring->capacity && ring->capacity < INT_MAX / 2, - "%s: capacity(%d) is out of range", func, ring->capacity); + "called from %s: ring->capacity=%d", where, ring->capacity); KASSERTMSG(0 <= ring->used && ring->used <= ring->capacity, - "%s: used(%d) is out of range (capacity:%d)", - func, ring->used, ring->capacity); + "called from %s: ring->used=%d ring->capacity=%d", + where, ring->used, ring->capacity); if (ring->capacity == 0) { KASSERTMSG(ring->mem == NULL, - "%s: capacity == 0 but mem != NULL", func); + "called from %s: capacity == 0 but mem != NULL", where); } else { KASSERTMSG(ring->mem != NULL, - "%s: capacity != 0 but mem == NULL", func); + "called from %s: capacity != 0 but mem == NULL", where); KASSERTMSG(0 <= ring->head && ring->head < ring->capacity, - "%s: head(%d) is out of range (capacity:%d)", - func, ring->head, ring->capacity); + "called from %s: ring->head=%d ring->capacity=%d", + where, ring->head, ring->capacity); } } #endif /* DIAGNOSTIC */ Index: src/sys/dev/audio/audiodef.h diff -u src/sys/dev/audio/audiodef.h:1.8 src/sys/dev/audio/audiodef.h:1.9 --- src/sys/dev/audio/audiodef.h:1.8 Sat Jan 25 12:15:35 2020 +++ src/sys/dev/audio/audiodef.h Sat Feb 22 06:58:39 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: audiodef.h,v 1.8 2020/01/25 12:15:35 jmcneill Exp $ */ +/* $NetBSD: audiodef.h,v 1.9 2020/02/22 06:58:39 isaki Exp $ */ /* * Copyright (C) 2017 Tetsuya Isaki. All rights reserved. @@ -296,8 +296,9 @@ static __inline int auring_round(const audio_ring_t *ring, int idx) { DIAGNOSTIC_ring(ring); - KASSERT(idx >= 0); - KASSERT(idx < ring->capacity * 2); + KASSERTMSG(idx >= 0, "idx=%d", idx); + KASSERTMSG(idx < ring->capacity * 2, + "idx=%d ring->capacity=%d", idx, ring->capacity); if (idx < ring->capacity) { return idx; @@ -324,7 +325,9 @@ auring_tail(const audio_ring_t *ring) static __inline aint_t * auring_headptr_aint(const audio_ring_t *ring) { - KASSERT(ring->fmt.stride == sizeof(aint_t) * NBBY); + KASSERTMSG(ring->fmt.stride == sizeof(aint_t) * NBBY, + "ring->fmt.stride=%d sizeof(aint_t)*NBBY=%zd", + ring->fmt.stride, sizeof(aint_t) * NBBY); return (aint_t *)ring->mem + ring->head * ring->fmt.channels; } @@ -337,7 +340,9 @@ auring_headptr_aint(const audio_ring_t * static __inline aint_t * auring_tailptr_aint(const audio_ring_t *ring) { - KASSERT(ring->fmt.stride == sizeof(aint_t) * NBBY); + KASSERTMSG(ring->fmt.stride == sizeof(aint_t) * NBBY, + "ring->fmt.stride=%d sizeof(aint_t)*NBBY=%zd", + ring->fmt.stride, sizeof(aint_t) * NBBY); return (aint_t *)ring->mem + auring_tail(ring) * ring->fmt.channels; }