git: a3468ea7bd7a - main - asmc: Use c99 initializers with for-loop counters to improve scoping

From: Abdelkader Boudih <seuros_at_FreeBSD.org>
Date: Mon, 09 Nov 2026 18:36:58 UTC
The branch main has been updated by seuros:

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

commit a3468ea7bd7a0b33b51a1a94ac2e39c0c231bd20
Author:     Abdelkader Boudih <seuros@FreeBSD.org>
AuthorDate: 2026-11-09 18:35:40 +0000
Commit:     Abdelkader Boudih <seuros@FreeBSD.org>
CommitDate: 2026-11-09 18:35:40 +0000

    asmc: Use c99 initializers with for-loop counters to improve scoping
    
    declared loop indices in the for statement
    Index types are unchanged.
    
    No functional change.
    
    MFC After: 1 Week
    Approved-by: ngie (co-mentor)
    
    Reviewed by:    ngie, imp
    Differential Revision:  https://reviews.freebsd.org/D61301
---
 sys/dev/asmc/asmc.c        | 11 +++--------
 sys/dev/asmc/asmc_debug.c  |  3 +--
 sys/dev/asmc/asmc_pio.c    | 10 ++++------
 sys/dev/asmc/asmc_sysctl.c |  8 ++------
 sys/dev/asmc/asmcmmio.c    |  3 +--
 5 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c
index 9db81e32b06d..b91a0315e65c 100644
--- a/sys/dev/asmc/asmc.c
+++ b/sys/dev/asmc/asmc.c
@@ -478,7 +478,6 @@ asmc_sms_init(device_t dev)
 {
 	struct asmc_softc *sc = device_get_softc(dev);
 	uint8_t buf[2];
-	int i;
 
 	/*
 	 * We are ready to receive interrupts from the SMS.
@@ -528,7 +527,7 @@ asmc_sms_init(device_t dev)
 	 * Retry SMS initialization 1000 times
 	 * (takes approx. 2 seconds in worst case)
 	 */
-	for (i = 0; i < 1000; i++) {
+	for (int i = 0; i < 1000; i++) {
 		if (asmc_key_read(dev, ASMC_KEY_SMS, buf, 2) == 0 &&
 		    (buf[0] == ASMC_SMS_INIT1 && buf[1] == ASMC_SMS_INIT2)) {
 			sc->sc_sms_intr_works = 1;
@@ -638,9 +637,7 @@ static const struct {
 static bool
 asmc_sensor_convert(const char *type, const uint8_t *buf, int *millivalue)
 {
-	int i;
-
-	for (i = 0; asmc_sensor_types[i].divisor != 0; i++) {
+	for (int i = 0; asmc_sensor_types[i].divisor != 0; i++) {
 		if (strncmp(type, asmc_sensor_types[i].type, 4) != 0)
 			continue;
 		if (asmc_sensor_types[i].divisor == 1)
@@ -656,9 +653,7 @@ asmc_sensor_convert(const char *type, const uint8_t *buf, int *millivalue)
 static bool
 asmc_sensor_type_supported(const char *type)
 {
-	int i;
-
-	for (i = 0; asmc_sensor_types[i].divisor != 0; i++)
+	for (int i = 0; asmc_sensor_types[i].divisor != 0; i++)
 		if (strncmp(type, asmc_sensor_types[i].type, 4) == 0)
 			return (true);
 	return (false);
diff --git a/sys/dev/asmc/asmc_debug.c b/sys/dev/asmc/asmc_debug.c
index e0d2ef28b972..2826ed5cbfca 100644
--- a/sys/dev/asmc/asmc_debug.c
+++ b/sys/dev/asmc/asmc_debug.c
@@ -65,7 +65,6 @@ void
 asmc_dumpall(device_t dev)
 {
 	struct asmc_softc *sc = device_get_softc(dev);
-	int i;
 
 	if (sc->sc_nkeys == 0) {
 		device_printf(dev, "asmc_dumpall: key count not available\n");
@@ -73,7 +72,7 @@ asmc_dumpall(device_t dev)
 	}
 
 	device_printf(dev, "asmc_dumpall: dumping %d keys\n", sc->sc_nkeys);
-	for (i = 0; i < sc->sc_nkeys; i++)
+	for (int i = 0; i < sc->sc_nkeys; i++)
 		asmc_key_dump(dev, i);
 }
 
diff --git a/sys/dev/asmc/asmc_pio.c b/sys/dev/asmc/asmc_pio.c
index 75ff8dbd3522..12847d4979ba 100644
--- a/sys/dev/asmc/asmc_pio.c
+++ b/sys/dev/asmc/asmc_pio.c
@@ -39,11 +39,10 @@ static int
 asmc_wait_ack(device_t dev, uint8_t val, int amount)
 {
 	struct asmc_softc *sc = device_get_softc(dev);
-	u_int i;
 
 	val = val & ASMC_STATUS_MASK;
 
-	for (i = 0; i < amount; i++) {
+	for (u_int i = 0; i < amount; i++) {
 		if ((ASMC_CMDPORT_READ(sc) & ASMC_STATUS_MASK) == val)
 			return (0);
 		DELAY(10);
@@ -82,10 +81,9 @@ asmc_wait(device_t dev, uint8_t val)
 static int
 asmc_command(device_t dev, uint8_t command)
 {
-	int i;
 	struct asmc_softc *sc = device_get_softc(dev);
 
-	for (i = 0; i < 10; i++) {
+	for (int i = 0; i < 10; i++) {
 		ASMC_CMDPORT_WRITE(sc, command);
 		if (asmc_wait_ack(dev, 0x0c, 100) == 0) {
 			return (0);
@@ -285,7 +283,7 @@ int
 asmc_pio_key_write(device_t dev, const char *key, uint8_t *buf, uint8_t len)
 {
 	struct asmc_softc *sc = device_get_softc(dev);
-	int i, error = -1, try = 0;
+	int error = -1, try = 0;
 
 	mtx_lock_spin(&sc->sc_mtx);
 
@@ -303,7 +301,7 @@ begin:
 	ASMC_DATAPORT_WRITE(sc, len);
 
 	ASMC_DPRINTF(("data port: buffer\n"));
-	for (i = 0; i < len; i++) {
+	for (int i = 0; i < len; i++) {
 		if (asmc_wait(dev, ASMC_STATUS_AWAIT_DATA))
 			goto out;
 		ASMC_DATAPORT_WRITE(sc, buf[i]);
diff --git a/sys/dev/asmc/asmc_sysctl.c b/sys/dev/asmc/asmc_sysctl.c
index f0e8fa9ce832..38ef894a978f 100644
--- a/sys/dev/asmc/asmc_sysctl.c
+++ b/sys/dev/asmc/asmc_sysctl.c
@@ -310,9 +310,7 @@ static const struct {
 static const char *
 asmc_temp_desc(const char *key)
 {
-	unsigned int i;
-
-	for (i = 0; i < nitems(asmc_temp_descs); i++) {
+	for (unsigned int i = 0; i < nitems(asmc_temp_descs); i++) {
 		if (strcmp(asmc_temp_descs[i].key, key) == 0)
 			return (asmc_temp_descs[i].desc);
 	}
@@ -1022,9 +1020,7 @@ asmc_sil_sysctl(SYSCTL_HANDLER_ARGS)
 static const char *
 asmc_cause_str(int8_t cause, bool is_sleep)
 {
-	size_t i;
-
-	for (i = 0; i < nitems(asmc_cause_table); i++) {
+	for (size_t i = 0; i < nitems(asmc_cause_table); i++) {
 		if (asmc_cause_table[i].code != cause)
 			continue;
 		if (is_sleep && asmc_cause_table[i].sleep_desc != NULL)
diff --git a/sys/dev/asmc/asmcmmio.c b/sys/dev/asmc/asmcmmio.c
index 012f7614931b..a083fa42e439 100644
--- a/sys/dev/asmc/asmcmmio.c
+++ b/sys/dev/asmc/asmcmmio.c
@@ -36,11 +36,10 @@ static int
 asmc_mmio_wait(device_t dev)
 {
 	struct asmc_softc *sc = device_get_softc(dev);
-	int i;
 	uint8_t status;
 	int delay_us = 10;
 
-	for (i = 0; i < ASMC_MMIO_MAX_WAIT; i++) {
+	for (int i = 0; i < ASMC_MMIO_MAX_WAIT; i++) {
 		status = bus_read_1(sc->sc_iomem, ASMC_MMIO_STATUS);
 		if (status & ASMC_MMIO_STATUS_READY)
 			return (0);