git: c597c5579232 - main - sound: Use nitems() where possible

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Mon, 06 May 2024 18:36:39 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=c597c557923288eff527594619a692a44ade909a

commit c597c557923288eff527594619a692a44ade909a
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-05-06 18:32:35 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-06 18:35:55 +0000

    sound: Use nitems() where possible
    
    No functional change intended.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    markj, emaste
    Differential Revision:  https://reviews.freebsd.org/D45014
---
 sys/dev/sound/pci/atiixp.c        |  4 ++--
 sys/dev/sound/pci/hda/hdaa.c      | 11 +++++++----
 sys/dev/sound/pci/ich.c           |  4 ++--
 sys/dev/sound/pci/maestro3.c      |  4 ++--
 sys/dev/sound/pcm/dsp.c           |  4 ++--
 sys/dev/sound/pcm/feeder_format.c | 15 ++++++---------
 sys/dev/sound/pcm/feeder_matrix.c |  4 ++--
 sys/dev/sound/pcm/feeder_volume.c |  2 +-
 sys/dev/sound/pcm/mixer.c         |  4 ++--
 sys/dev/sound/pcm/sound.c         |  5 +++--
 10 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/sys/dev/sound/pci/atiixp.c b/sys/dev/sound/pci/atiixp.c
index dcbf041f9605..eeb28bb08276 100644
--- a/sys/dev/sound/pci/atiixp.c
+++ b/sys/dev/sound/pci/atiixp.c
@@ -1168,12 +1168,12 @@ atiixp_release_resource(struct atiixp_info *sc)
 static int
 atiixp_pci_probe(device_t dev)
 {
-	int i;
+	size_t i;
 	uint16_t devid, vendor;
 
 	vendor = pci_get_vendor(dev);
 	devid = pci_get_device(dev);
-	for (i = 0; i < sizeof(atiixp_hw) / sizeof(atiixp_hw[0]); i++) {
+	for (i = 0; i < nitems(atiixp_hw); i++) {
 		if (vendor == atiixp_hw[i].vendor &&
 		    devid == atiixp_hw[i].devid) {
 			device_set_desc(dev, atiixp_hw[i].desc);
diff --git a/sys/dev/sound/pci/hda/hdaa.c b/sys/dev/sound/pci/hda/hdaa.c
index dcd10cb36510..e8d9ee12fffc 100644
--- a/sys/dev/sound/pci/hda/hdaa.c
+++ b/sys/dev/sound/pci/hda/hdaa.c
@@ -267,7 +267,8 @@ hdaa_channels_handler(struct hdaa_audio_as *as)
 	struct hdaa_chan *ch = &devinfo->chans[as->chans[0]];
 	struct hdaa_widget *w;
 	uint8_t *eld;
-	int i, total, sub, assume, channels;
+	int total, sub, assume, channels;
+	size_t i;
 	uint16_t cpins, upins, tpins;
 
 	cpins = upins = 0;
@@ -347,7 +348,7 @@ hdaa_channels_handler(struct hdaa_audio_as *as)
 			printf("\n");
 		);
 		/* Look for maximal fitting matrix. */
-		for (i = 0; i < sizeof(matrixes) / sizeof(struct matrix); i++) {
+		for (i = 0; i < nitems(matrixes); i++) {
 			if (as->pinset != 0 && matrixes[i].analog == 0)
 				continue;
 			if ((matrixes[i].m.mask & ~channels) == 0) {
@@ -1252,7 +1253,8 @@ hdaa_sysctl_config(SYSCTL_HANDLER_ARGS)
 static void
 hdaa_config_fetch(const char *str, uint32_t *on, uint32_t *off)
 {
-	int i = 0, j, k, len, inv;
+	size_t k;
+	int i = 0, j, len, inv;
 
 	for (;;) {
 		while (str[i] != '\0' &&
@@ -1292,7 +1294,8 @@ static int
 hdaa_sysctl_quirks(SYSCTL_HANDLER_ARGS)
 {
 	char buf[256];
-	int error, n = 0, i;
+	int error, n = 0;
+	size_t i;
 	uint32_t quirks, quirks_off;
 
 	quirks = *(uint32_t *)oidp->oid_arg1;
diff --git a/sys/dev/sound/pci/ich.c b/sys/dev/sound/pci/ich.c
index fbde0accfd28..910a371c6653 100644
--- a/sys/dev/sound/pci/ich.c
+++ b/sys/dev/sound/pci/ich.c
@@ -860,12 +860,12 @@ ich_init(struct sc_info *sc)
 static int
 ich_pci_probe(device_t dev)
 {
-	int i;
+	size_t i;
 	uint16_t devid, vendor;
 
 	vendor = pci_get_vendor(dev);
 	devid = pci_get_device(dev);
-	for (i = 0; i < sizeof(ich_devs)/sizeof(ich_devs[0]); i++) {
+	for (i = 0; i < nitems(ich_devs); i++) {
 		if (vendor == ich_devs[i].vendor &&
 				devid == ich_devs[i].devid) {
 			device_set_desc(dev, ich_devs[i].name);
diff --git a/sys/dev/sound/pci/maestro3.c b/sys/dev/sound/pci/maestro3.c
index 6dd54a66f683..4d6dca310eea 100644
--- a/sys/dev/sound/pci/maestro3.c
+++ b/sys/dev/sound/pci/maestro3.c
@@ -488,7 +488,7 @@ m3_pchan_init(kobj_t kobj, void *devinfo, struct snd_dbuf *b, struct pcm_channel
 			DMAC_BLOCKF_SELECTOR);
 
 	/* set an armload of static initializers */
-	for(i = 0 ; i < (sizeof(pv) / sizeof(pv[0])) ; i++) {
+	for(i = 0 ; i < nitems(pv); i++) {
 		m3_wr_assp_data(sc, ch->dac_data + pv[i].addr, pv[i].val);
 	}
 
@@ -862,7 +862,7 @@ m3_rchan_init(kobj_t kobj, void *devinfo, struct snd_dbuf *b, struct pcm_channel
 			DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
 
 	/* set an armload of static initializers */
-	for(i = 0 ; i < (sizeof(rv) / sizeof(rv[0])) ; i++) {
+	for(i = 0 ; i < nitems(rv); i++) {
 		m3_wr_assp_data(sc, ch->adc_data + rv[i].addr, rv[i].val);
 	}
 
diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
index 6c3d76e27b6b..fe816db54697 100644
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -1966,7 +1966,7 @@ dsp_clone(void *arg, struct ucred *cred, char *name, int namelen,
     struct cdev **dev)
 {
 	struct snddev_info *d;
-	int i;
+	size_t i;
 
 	if (*dev != NULL)
 		return;
@@ -2017,7 +2017,7 @@ SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);
 char *
 dsp_unit2name(char *buf, size_t len, struct pcm_channel *ch)
 {
-	int i;
+	size_t i;
 
 	KASSERT(buf != NULL && len != 0,
 	    ("bogus buf=%p len=%ju", buf, (uintmax_t)len));
diff --git a/sys/dev/sound/pcm/feeder_format.c b/sys/dev/sound/pcm/feeder_format.c
index 1e18e3e07450..3bdd808df0ee 100644
--- a/sys/dev/sound/pcm/feeder_format.c
+++ b/sys/dev/sound/pcm/feeder_format.c
@@ -115,16 +115,13 @@ static const struct {
 	}
 };
 
-#define FEEDFORMAT_TAB_SIZE						\
-	((int32_t)(sizeof(feed_format_ops) / sizeof(feed_format_ops[0])))
-
 static int
 feed_format_init(struct pcm_feeder *f)
 {
 	struct feed_format_info *info;
 	intpcm_read_t *rd_op;
 	intpcm_write_t *wr_op;
-	int i;
+	size_t i;
 
 	if (f->desc->in == f->desc->out ||
 	    AFMT_CHANNEL(f->desc->in) != AFMT_CHANNEL(f->desc->out))
@@ -133,7 +130,7 @@ feed_format_init(struct pcm_feeder *f)
 	rd_op = NULL;
 	wr_op = NULL;
 
-	for (i = 0; i < FEEDFORMAT_TAB_SIZE &&
+	for (i = 0; i < nitems(feed_format_ops) &&
 	    (rd_op == NULL || wr_op == NULL); i++) {
 		if (rd_op == NULL &&
 		    AFMT_ENCODING(f->desc->in) == feed_format_ops[i].format)
@@ -276,9 +273,9 @@ FEEDER_DECLARE(feeder_format, NULL);
 intpcm_read_t *
 feeder_format_read_op(uint32_t format)
 {
-	int i;
+	size_t i;
 
-	for (i = 0; i < FEEDFORMAT_TAB_SIZE; i++) {
+	for (i = 0; i < nitems(feed_format_ops); i++) {
 		if (AFMT_ENCODING(format) == feed_format_ops[i].format)
 			return (feed_format_ops[i].read);
 	}
@@ -289,9 +286,9 @@ feeder_format_read_op(uint32_t format)
 intpcm_write_t *
 feeder_format_write_op(uint32_t format)
 {
-	int i;
+	size_t i;
 
-	for (i = 0; i < FEEDFORMAT_TAB_SIZE; i++) {
+	for (i = 0; i < nitems(feed_format_ops); i++) {
 		if (AFMT_ENCODING(format) == feed_format_ops[i].format)
 			return (feed_format_ops[i].write);
 	}
diff --git a/sys/dev/sound/pcm/feeder_matrix.c b/sys/dev/sound/pcm/feeder_matrix.c
index f5f02e2bf4f5..97cf86585636 100644
--- a/sys/dev/sound/pcm/feeder_matrix.c
+++ b/sys/dev/sound/pcm/feeder_matrix.c
@@ -230,7 +230,7 @@ feed_matrix_reset(struct feed_matrix_info *info)
 {
 	uint32_t i, j;
 
-	for (i = 0; i < (sizeof(info->matrix) / sizeof(info->matrix[0])); i++) {
+	for (i = 0; i < nitems(info->matrix); i++) {
 		for (j = 0;
 		    j < (sizeof(info->matrix[i].chn) /
 		    sizeof(info->matrix[i].chn[0])); j++) {
@@ -679,7 +679,7 @@ feeder_matrix_compare(struct pcmchan_matrix *m_in, struct pcmchan_matrix *m_out)
 	    m_in->mask != m_out->mask)
 		return (1);
 
-	for (i = 0; i < (sizeof(m_in->map) / sizeof(m_in->map[0])); i++) {
+	for (i = 0; i < nitems(m_in->map); i++) {
 		if (m_in->map[i].type != m_out->map[i].type)
 			return (1);
 		if (m_in->map[i].type == SND_CHN_T_MAX)
diff --git a/sys/dev/sound/pcm/feeder_volume.c b/sys/dev/sound/pcm/feeder_volume.c
index 452d8788a5a5..7e600c131afe 100644
--- a/sys/dev/sound/pcm/feeder_volume.c
+++ b/sys/dev/sound/pcm/feeder_volume.c
@@ -337,7 +337,7 @@ feeder_volume_apply_matrix(struct pcm_feeder *f, struct pcmchan_matrix *m)
 
 	info = f->data;
 
-	for (i = 0; i < (sizeof(info->matrix) / sizeof(info->matrix[0])); i++) {
+	for (i = 0; i < nitems(info->matrix); i++) {
 		if (i < m->channels)
 			info->matrix[i] = m->map[i].type;
 		else
diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index 3e197b120c9d..4e67a0227506 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -650,7 +650,7 @@ mixer_obj_create(device_t dev, kobj_class_t cls, void *devinfo,
     int type, const char *desc)
 {
 	struct snd_mixer *m;
-	int i;
+	size_t i;
 
 	KASSERT(dev != NULL && cls != NULL && devinfo != NULL,
 	    ("%s(): NULL data dev=%p cls=%p devinfo=%p",
@@ -671,7 +671,7 @@ mixer_obj_create(device_t dev, kobj_class_t cls, void *devinfo,
 	m->devinfo = devinfo;
 	m->busy = 0;
 	m->dev = dev;
-	for (i = 0; i < (sizeof(m->parent) / sizeof(m->parent[0])); i++) {
+	for (i = 0; i < nitems(m->parent); i++) {
 		m->parent[i] = SOUND_MIXER_NONE;
 		m->child[i] = 0;
 		m->realdev[i] = i;
diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index d2acfc403e8c..afa19f9f0624 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -880,7 +880,8 @@ sound_oss_sysinfo(oss_sysinfo *si)
 
 	struct snddev_info *d;
 	struct pcm_channel *c;
-	int i, j, ncards;
+	int j, ncards;
+	size_t i;
 
 	ncards = 0;
 
@@ -958,7 +959,7 @@ sound_oss_sysinfo(oss_sysinfo *si)
 	 * Si->filler is a reserved array, but according to docs each
 	 * element should be set to -1.
 	 */
-	for (i = 0; i < sizeof(si->filler)/sizeof(si->filler[0]); i++)
+	for (i = 0; i < nitems(si->filler); i++)
 		si->filler[i] = -1;
 }