git: 792251295cdf - main - sound: Do not check for NULL before free()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 02 Jan 2026 16:58:34 UTC
The branch main has been updated by christos:
URL: https://cgit.FreeBSD.org/src/commit/?id=792251295cdf6c3e1cbb1aa6291434539632912f
commit 792251295cdf6c3e1cbb1aa6291434539632912f
Author: Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-01-02 16:56:52 +0000
Commit: Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-01-02 16:58:06 +0000
sound: Do not check for NULL before free()
No functional change intended.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D54174
---
sys/dev/sound/dummy.c | 3 +--
sys/dev/sound/fdt/audio_soc.c | 6 ++----
sys/dev/sound/midi/midi.c | 6 ++----
sys/dev/sound/pci/cmi.c | 3 +--
sys/dev/sound/pci/envy24.c | 6 ++----
sys/dev/sound/pci/envy24ht.c | 6 ++----
sys/dev/sound/pci/es137x.c | 3 +--
sys/dev/sound/pci/hdsp-pcm.c | 12 ++++--------
sys/dev/sound/pci/hdspe-pcm.c | 12 ++++--------
sys/dev/sound/pci/via8233.c | 3 +--
sys/dev/sound/pci/via82c686.c | 2 +-
sys/dev/sound/pcm/buffer.c | 19 ++++++-------------
sys/dev/sound/pcm/dsp.c | 3 +--
sys/dev/sound/pcm/feeder_eq.c | 3 +--
sys/dev/sound/pcm/feeder_format.c | 3 +--
sys/dev/sound/pcm/feeder_matrix.c | 3 +--
sys/dev/sound/pcm/feeder_mixer.c | 3 +--
sys/dev/sound/pcm/feeder_rate.c | 37 ++++++++++++-------------------------
sys/dev/sound/pcm/feeder_volume.c | 3 +--
sys/dev/sound/usb/uaudio.c | 6 ++----
20 files changed, 47 insertions(+), 95 deletions(-)
diff --git a/sys/dev/sound/dummy.c b/sys/dev/sound/dummy.c
index aec76339ae17..91a198e3d9f6 100644
--- a/sys/dev/sound/dummy.c
+++ b/sys/dev/sound/dummy.c
@@ -132,8 +132,7 @@ dummy_chan_free(kobj_t obj, void *data)
uint8_t *buf;
buf = ch->buf->buf;
- if (buf != NULL)
- free(buf, M_DEVBUF);
+ free(buf, M_DEVBUF);
return (0);
}
diff --git a/sys/dev/sound/fdt/audio_soc.c b/sys/dev/sound/fdt/audio_soc.c
index 84867cb3d781..33269dc302fa 100644
--- a/sys/dev/sound/fdt/audio_soc.c
+++ b/sys/dev/sound/fdt/audio_soc.c
@@ -250,8 +250,7 @@ audio_soc_chan_free(kobj_t obj, void *data)
ausoc_chan = (struct audio_soc_channel *)data;
buffer = ausoc_chan->buf->buf;
- if (buffer)
- free(buffer, M_DEVBUF);
+ free(buffer, M_DEVBUF);
return (0);
}
@@ -508,8 +507,7 @@ audio_soc_detach(device_t dev)
struct audio_soc_aux_node *aux;
sc = device_get_softc(dev);
- if (sc->name)
- free(sc->name, M_DEVBUF);
+ free(sc->name, M_DEVBUF);
while ((aux = SLIST_FIRST(&sc->aux_devs)) != NULL) {
SLIST_REMOVE_HEAD(&sc->aux_devs, link);
diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index 7f968b6210f5..542282d81842 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -153,10 +153,8 @@ midi_init(kobj_class_t cls, void *cookie)
err2:
mtx_destroy(&m->lock);
- if (MIDIQ_BUF(m->inq))
- free(MIDIQ_BUF(m->inq), M_MIDI);
- if (MIDIQ_BUF(m->outq))
- free(MIDIQ_BUF(m->outq), M_MIDI);
+ free(MIDIQ_BUF(m->inq), M_MIDI);
+ free(MIDIQ_BUF(m->outq), M_MIDI);
err1:
free(m, M_MIDI);
return NULL;
diff --git a/sys/dev/sound/pci/cmi.c b/sys/dev/sound/pci/cmi.c
index 99925d236c08..b5465fed5a8b 100644
--- a/sys/dev/sound/pci/cmi.c
+++ b/sys/dev/sound/pci/cmi.c
@@ -1009,8 +1009,7 @@ cmi_attach(device_t dev)
if (sc->reg)
bus_release_resource(dev, SYS_RES_IOPORT, sc->regid, sc->reg);
mtx_destroy(&sc->lock);
- if (sc)
- free(sc, M_DEVBUF);
+ free(sc, M_DEVBUF);
return ENXIO;
}
diff --git a/sys/dev/sound/pci/envy24.c b/sys/dev/sound/pci/envy24.c
index 3adb22254b72..50864a9067fd 100644
--- a/sys/dev/sound/pci/envy24.c
+++ b/sys/dev/sound/pci/envy24.c
@@ -1611,10 +1611,8 @@ envy24chan_free(kobj_t obj, void *data)
device_printf(sc->dev, "envy24chan_free()\n");
#endif
mtx_lock(&sc->lock);
- if (ch->data != NULL) {
- free(ch->data, M_ENVY24);
- ch->data = NULL;
- }
+ free(ch->data, M_ENVY24);
+ ch->data = NULL;
mtx_unlock(&sc->lock);
return 0;
diff --git a/sys/dev/sound/pci/envy24ht.c b/sys/dev/sound/pci/envy24ht.c
index 2396a340cd84..3aca8f92f708 100644
--- a/sys/dev/sound/pci/envy24ht.c
+++ b/sys/dev/sound/pci/envy24ht.c
@@ -1522,10 +1522,8 @@ envy24htchan_free(kobj_t obj, void *data)
device_printf(sc->dev, "envy24htchan_free()\n");
#endif
mtx_lock(&sc->lock);
- if (ch->data != NULL) {
- free(ch->data, M_ENVY24HT);
- ch->data = NULL;
- }
+ free(ch->data, M_ENVY24HT);
+ ch->data = NULL;
mtx_unlock(&sc->lock);
return 0;
diff --git a/sys/dev/sound/pci/es137x.c b/sys/dev/sound/pci/es137x.c
index 4e8c7911e95e..45b953efc3fc 100644
--- a/sys/dev/sound/pci/es137x.c
+++ b/sys/dev/sound/pci/es137x.c
@@ -1886,8 +1886,7 @@ bad:
if (es->reg)
bus_release_resource(dev, es->regtype, es->regid, es->reg);
mtx_destroy(&es->lock);
- if (es)
- free(es, M_DEVBUF);
+ free(es, M_DEVBUF);
return (ENXIO);
}
diff --git a/sys/dev/sound/pci/hdsp-pcm.c b/sys/dev/sound/pci/hdsp-pcm.c
index b64cec281388..5a8f2ab57d6c 100644
--- a/sys/dev/sound/pci/hdsp-pcm.c
+++ b/sys/dev/sound/pci/hdsp-pcm.c
@@ -677,14 +677,10 @@ hdspchan_free(kobj_t obj, void *data)
#endif
mtx_lock(&sc->lock);
- if (ch->data != NULL) {
- free(ch->data, M_HDSP);
- ch->data = NULL;
- }
- if (ch->caps != NULL) {
- free(ch->caps, M_HDSP);
- ch->caps = NULL;
- }
+ free(ch->data, M_HDSP);
+ ch->data = NULL;
+ free(ch->caps, M_HDSP);
+ ch->caps = NULL;
mtx_unlock(&sc->lock);
return (0);
diff --git a/sys/dev/sound/pci/hdspe-pcm.c b/sys/dev/sound/pci/hdspe-pcm.c
index d78820732639..678693960e5e 100644
--- a/sys/dev/sound/pci/hdspe-pcm.c
+++ b/sys/dev/sound/pci/hdspe-pcm.c
@@ -668,14 +668,10 @@ hdspechan_free(kobj_t obj, void *data)
#endif
mtx_lock(&sc->lock);
- if (ch->data != NULL) {
- free(ch->data, M_HDSPE);
- ch->data = NULL;
- }
- if (ch->caps != NULL) {
- free(ch->caps, M_HDSPE);
- ch->caps = NULL;
- }
+ free(ch->data, M_HDSPE);
+ ch->data = NULL;
+ free(ch->caps, M_HDSPE);
+ ch->caps = NULL;
mtx_unlock(&sc->lock);
return (0);
diff --git a/sys/dev/sound/pci/via8233.c b/sys/dev/sound/pci/via8233.c
index 6c59397756e0..90e966b864e3 100644
--- a/sys/dev/sound/pci/via8233.c
+++ b/sys/dev/sound/pci/via8233.c
@@ -1385,8 +1385,7 @@ bad:
if (via->sgd_dmat)
bus_dma_tag_destroy(via->sgd_dmat);
mtx_destroy(&via->lock);
- if (via)
- free(via, M_DEVBUF);
+ free(via, M_DEVBUF);
return (ENXIO);
}
diff --git a/sys/dev/sound/pci/via82c686.c b/sys/dev/sound/pci/via82c686.c
index fe34583b1a25..144f0ff21fb6 100644
--- a/sys/dev/sound/pci/via82c686.c
+++ b/sys/dev/sound/pci/via82c686.c
@@ -601,7 +601,7 @@ bad:
if (via->sgd_table) bus_dmamem_free(via->sgd_dmat, via->sgd_table, via->sgd_dmamap);
if (via->sgd_dmat) bus_dma_tag_destroy(via->sgd_dmat);
mtx_destroy(&via->lock);
- if (via) free(via, M_DEVBUF);
+ free(via, M_DEVBUF);
return ENXIO;
}
diff --git a/sys/dev/sound/pcm/buffer.c b/sys/dev/sound/pcm/buffer.c
index eb2cbe667bf3..1db9e5661dc8 100644
--- a/sys/dev/sound/pcm/buffer.c
+++ b/sys/dev/sound/pcm/buffer.c
@@ -129,11 +129,8 @@ sndbuf_setup(struct snd_dbuf *b, void *buf, unsigned int size)
void
sndbuf_free(struct snd_dbuf *b)
{
- if (b->tmpbuf)
- free(b->tmpbuf, M_DEVBUF);
-
- if (b->shadbuf)
- free(b->shadbuf, M_DEVBUF);
+ free(b->tmpbuf, M_DEVBUF);
+ free(b->shadbuf, M_DEVBUF);
if (b->buf) {
if (b->flags & SNDBUF_F_MANAGED) {
@@ -188,8 +185,7 @@ sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
printf("%s(): b=%p %p -> %p [%d -> %d : %d]\n",
__func__, b, b->tmpbuf, tmpbuf,
b->allocsize, allocsize, bufsize);
- if (b->tmpbuf != NULL)
- free(b->tmpbuf, M_DEVBUF);
+ free(b->tmpbuf, M_DEVBUF);
b->tmpbuf = tmpbuf;
b->allocsize = allocsize;
} else if (snd_verbose > 3)
@@ -225,14 +221,11 @@ sndbuf_remalloc(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
tmpbuf = malloc(allocsize, M_DEVBUF, M_WAITOK);
shadbuf = malloc(allocsize, M_DEVBUF, M_WAITOK);
CHN_LOCK(b->channel);
- if (b->buf != NULL)
- free(b->buf, M_DEVBUF);
+ free(b->buf, M_DEVBUF);
b->buf = buf;
- if (b->tmpbuf != NULL)
- free(b->tmpbuf, M_DEVBUF);
+ free(b->tmpbuf, M_DEVBUF);
b->tmpbuf = tmpbuf;
- if (b->shadbuf != NULL)
- free(b->shadbuf, M_DEVBUF);
+ free(b->shadbuf, M_DEVBUF);
b->shadbuf = shadbuf;
if (snd_verbose > 3)
printf("%s(): b=%p %d -> %d [%d]\n",
diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
index 62db4592f206..c1e836691ac7 100644
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -2582,8 +2582,7 @@ dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgr
out:
if (ret != 0) {
- if (smrd != NULL)
- free(smrd, M_DEVBUF);
+ free(smrd, M_DEVBUF);
if ((sg != NULL) && SLIST_EMPTY(&sg->members)) {
sg_ids[2] = sg->id;
SLIST_REMOVE(&snd_pcm_syncgroups, sg, pcmchan_syncgroup, link);
diff --git a/sys/dev/sound/pcm/feeder_eq.c b/sys/dev/sound/pcm/feeder_eq.c
index 08e789f6a5ad..4cf9d4f6695f 100644
--- a/sys/dev/sound/pcm/feeder_eq.c
+++ b/sys/dev/sound/pcm/feeder_eq.c
@@ -353,8 +353,7 @@ feed_eq_free(struct pcm_feeder *f)
struct feed_eq_info *info;
info = f->data;
- if (info != NULL)
- free(info, M_DEVBUF);
+ free(info, M_DEVBUF);
f->data = NULL;
diff --git a/sys/dev/sound/pcm/feeder_format.c b/sys/dev/sound/pcm/feeder_format.c
index 3226aebf9580..0747b54cbbae 100644
--- a/sys/dev/sound/pcm/feeder_format.c
+++ b/sys/dev/sound/pcm/feeder_format.c
@@ -90,8 +90,7 @@ feed_format_free(struct pcm_feeder *f)
struct feed_format_info *info;
info = f->data;
- if (info != NULL)
- free(info, M_DEVBUF);
+ free(info, M_DEVBUF);
f->data = NULL;
diff --git a/sys/dev/sound/pcm/feeder_matrix.c b/sys/dev/sound/pcm/feeder_matrix.c
index 198fe86d994f..cba537c84efd 100644
--- a/sys/dev/sound/pcm/feeder_matrix.c
+++ b/sys/dev/sound/pcm/feeder_matrix.c
@@ -317,8 +317,7 @@ feed_matrix_free(struct pcm_feeder *f)
struct feed_matrix_info *info;
info = f->data;
- if (info != NULL)
- free(info, M_DEVBUF);
+ free(info, M_DEVBUF);
f->data = NULL;
diff --git a/sys/dev/sound/pcm/feeder_mixer.c b/sys/dev/sound/pcm/feeder_mixer.c
index 74ab633bf3c7..8c58e1c8ef33 100644
--- a/sys/dev/sound/pcm/feeder_mixer.c
+++ b/sys/dev/sound/pcm/feeder_mixer.c
@@ -100,8 +100,7 @@ feed_mixer_free(struct pcm_feeder *f)
struct feed_mixer_info *info;
info = f->data;
- if (info != NULL)
- free(info, M_DEVBUF);
+ free(info, M_DEVBUF);
f->data = NULL;
diff --git a/sys/dev/sound/pcm/feeder_rate.c b/sys/dev/sound/pcm/feeder_rate.c
index 63d7fe11003a..aee164840c4a 100644
--- a/sys/dev/sound/pcm/feeder_rate.c
+++ b/sys/dev/sound/pcm/feeder_rate.c
@@ -714,10 +714,8 @@ z_resampler_reset(struct z_info *info)
info->z_size = 1;
info->z_coeff = NULL;
info->z_dcoeff = NULL;
- if (info->z_pcoeff != NULL) {
- free(info->z_pcoeff, M_DEVBUF);
- info->z_pcoeff = NULL;
- }
+ free(info->z_pcoeff, M_DEVBUF);
+ info->z_pcoeff = NULL;
info->z_scale = Z_ONE;
info->z_dx = Z_FULL_ONE;
info->z_dy = Z_FULL_ONE;
@@ -1029,10 +1027,8 @@ z_resampler_build_polyphase(struct z_info *info)
int32_t alpha, c, i, z, idx;
/* Let this be here first. */
- if (info->z_pcoeff != NULL) {
- free(info->z_pcoeff, M_DEVBUF);
- info->z_pcoeff = NULL;
- }
+ free(info->z_pcoeff, M_DEVBUF);
+ info->z_pcoeff = NULL;
if (feeder_rate_polyphase_max < 1)
return (ENOTSUP);
@@ -1154,10 +1150,8 @@ z_resampler_setup(struct pcm_feeder *f)
* adaptive mode.
*/
z_setup_adaptive_sinc:
- if (info->z_pcoeff != NULL) {
- free(info->z_pcoeff, M_DEVBUF);
- info->z_pcoeff = NULL;
- }
+ free(info->z_pcoeff, M_DEVBUF);
+ info->z_pcoeff = NULL;
if (adaptive == 0) {
info->z_dy = z_scale << Z_DRIFT_SHIFT;
@@ -1333,8 +1327,7 @@ z_setup_adaptive_sinc:
if (info->z_delay == NULL || info->z_alloc < i ||
i <= (info->z_alloc >> 1)) {
- if (info->z_delay != NULL)
- free(info->z_delay, M_DEVBUF);
+ free(info->z_delay, M_DEVBUF);
info->z_delay = malloc(i, M_DEVBUF, M_NOWAIT | M_ZERO);
if (info->z_delay == NULL)
return (ENOMEM);
@@ -1517,10 +1510,8 @@ z_resampler_init(struct pcm_feeder *f)
ret = z_resampler_setup(f);
if (ret != 0) {
- if (info->z_pcoeff != NULL)
- free(info->z_pcoeff, M_DEVBUF);
- if (info->z_delay != NULL)
- free(info->z_delay, M_DEVBUF);
+ free(info->z_pcoeff, M_DEVBUF);
+ free(info->z_delay, M_DEVBUF);
free(info, M_DEVBUF);
f->data = NULL;
}
@@ -1534,13 +1525,9 @@ z_resampler_free(struct pcm_feeder *f)
struct z_info *info;
info = f->data;
- if (info != NULL) {
- if (info->z_pcoeff != NULL)
- free(info->z_pcoeff, M_DEVBUF);
- if (info->z_delay != NULL)
- free(info->z_delay, M_DEVBUF);
- free(info, M_DEVBUF);
- }
+ free(info->z_pcoeff, M_DEVBUF);
+ free(info->z_delay, M_DEVBUF);
+ free(info, M_DEVBUF);
f->data = NULL;
diff --git a/sys/dev/sound/pcm/feeder_volume.c b/sys/dev/sound/pcm/feeder_volume.c
index 3e9e3484fba8..fc4ed1bbb0a5 100644
--- a/sys/dev/sound/pcm/feeder_volume.c
+++ b/sys/dev/sound/pcm/feeder_volume.c
@@ -193,8 +193,7 @@ feed_volume_free(struct pcm_feeder *f)
struct feed_volume_info *info;
info = f->data;
- if (info != NULL)
- free(info, M_DEVBUF);
+ free(info, M_DEVBUF);
f->data = NULL;
diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c
index 65c1327ee0f2..86fb5228a990 100644
--- a/sys/dev/sound/usb/uaudio.c
+++ b/sys/dev/sound/usb/uaudio.c
@@ -2704,10 +2704,8 @@ error:
int
uaudio_chan_free(struct uaudio_chan *ch)
{
- if (ch->buf != NULL) {
- free(ch->buf, M_DEVBUF);
- ch->buf = NULL;
- }
+ free(ch->buf, M_DEVBUF);
+ ch->buf = NULL;
usbd_transfer_unsetup(ch->xfer, UAUDIO_NCHANBUFS + 1);
ch->num_alt = 0;