From a7ae860ec9d7e200e782810ac1853d6cb08c1a84 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Wed, 23 Oct 2019 18:02:14 +0200
Subject: [PATCH 7/7] world/kernel: Use the {set,clr}bit() and is{set,clr}()
 macros.

---
 sbin/dump/dump.h                    |  9 +++------
 sbin/restore/restore.h              |  6 ++----
 sys/bus/u4b/audio/uaudio.c          | 24 ++++++++++--------------
 sys/bus/u4b/controller/ehci.c       |  2 +-
 sys/bus/u4b/controller/ohci.c       |  2 +-
 sys/bus/u4b/controller/xhci.c       |  2 +-
 sys/bus/u4b/net/if_axe.c            |  2 +-
 sys/bus/u4b/net/if_axge.c           |  2 +-
 sys/bus/u4b/net/if_mos.c            |  2 +-
 sys/bus/u4b/net/if_udav.c           |  2 +-
 sys/bus/u4b/template/usb_template.c |  4 ++--
 11 files changed, 24 insertions(+), 33 deletions(-)

diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h
index 4d0b14aeab..c41e44a328 100644
--- a/sbin/dump/dump.h
+++ b/sbin/dump/dump.h
@@ -46,12 +46,9 @@ char	*dumpinomap;	/* map of files to be dumped */
 /*
  * Map manipulation macros.
  */
-#define	SETINO(ino, map) \
-	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
-#define	CLRINO(ino, map) \
-	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
-#define	TSTINO(ino, map) \
-	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
+#define	SETINO(ino, map)	setbit(map, (u_int)((ino) - 1))
+#define	CLRINO(ino, map)	clrbit(map, (u_int)((ino) - 1))
+#define	TSTINO(ino, map)	isset(map, (u_int)((ino) - 1))
 
 /*
  *	All calculations done in 0.1" units!
diff --git a/sbin/restore/restore.h b/sbin/restore/restore.h
index 5063be1e43..d586d91246 100644
--- a/sbin/restore/restore.h
+++ b/sbin/restore/restore.h
@@ -126,10 +126,8 @@ typedef struct rstdirdesc RST_DIR;
 /*
  * Useful macros
  */
-#define TSTINO(ino, map) \
-	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
-#define	SETINO(ino, map) \
-	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
+#define	TSTINO(ino, map)	isset(map, (u_int)((ino) - 1))
+#define	SETINO(ino, map)	setbit(map, (u_int)((ino) - 1))
 
 #define dprintf		if (dflag) fprintf
 #define vprintf		if (vflag) fprintf
diff --git a/sys/bus/u4b/audio/uaudio.c b/sys/bus/u4b/audio/uaudio.c
index 17cbcdabd8..0a7ff00074 100644
--- a/sys/bus/u4b/audio/uaudio.c
+++ b/sys/bus/u4b/audio/uaudio.c
@@ -1293,13 +1293,11 @@ uaudio_configure_msg_sub(struct uaudio_softc *sc,
 
 		for (x = 0; x != 256; x++) {
 			if (dir == PCMDIR_PLAY) {
-				if (!(sc->sc_mixer_clocks.bit_output[x / 8] &
-				    (1 << (x % 8)))) {
+				if (isclr(sc->sc_mixer_clocks.bit_output, x)) {
 					continue;
 				}
 			} else {
-				if (!(sc->sc_mixer_clocks.bit_input[x / 8] &
-				    (1 << (x % 8)))) {
+				if (isclr(sc->sc_mixer_clocks.bit_input, x)) {
 					continue;
 				}
 			}
@@ -1784,13 +1782,11 @@ uaudio_chan_fill_info_sub(struct uaudio_softc *sc, struct usb_device *udev,
 
 			for (x = 0; x != 256; x++) {
 				if (ep_dir == UE_DIR_OUT) {
-					if (!(sc->sc_mixer_clocks.bit_output[x / 8] &
-					    (1 << (x % 8)))) {
+					if (isclr(sc->sc_mixer_clocks.bit_output, x)) {
 						continue;
 					}
 				} else {
-					if (!(sc->sc_mixer_clocks.bit_input[x / 8] &
-					    (1 << (x % 8)))) {
+					if (isclr(sc->sc_mixer_clocks.bit_input, x)) {
 						continue;
 					}
 				}
@@ -4477,7 +4473,7 @@ uaudio_mixer_get_input(const struct uaudio_terminal_node *iot, uint8_t i)
 
 	n = iot->usr.id_max;
 	do {
-		if (iot->usr.bit_input[n / 8] & (1 << (n % 8))) {
+		if (isset(iot->usr.bit_input, n)) {
 			if (!i--)
 				return (root + n);
 		}
@@ -4494,7 +4490,7 @@ uaudio_mixer_get_output(const struct uaudio_terminal_node *iot, uint8_t i)
 
 	n = iot->usr.id_max;
 	do {
-		if (iot->usr.bit_output[n / 8] & (1 << (n % 8))) {
+		if (isset(iot->usr.bit_output, n)) {
 			if (!i--)
 				return (root + n);
 		}
@@ -4847,7 +4843,7 @@ uaudio_mixer_find_outputs_sub(struct uaudio_terminal_node *root, uint8_t id,
 			 * if "j" has "id" on the input, then "id" have "j" on
 			 * the output, because they are connected:
 			 */
-			if ((root + j)->usr.bit_input[id / 8] & (1 << (id % 8))) {
+			if (isset((root + j)->usr.bit_input, id)) {
 				iot->usr.bit_output[j / 8] |= (1 << (j % 8));
 			}
 		}
@@ -5167,10 +5163,10 @@ uaudio_mixer_write_cfg_callback(struct usb_xfer *xfer, usb_error_t error)
 
 				sc->sc_mixer_chan++;
 
-				update = ((mc->update[chan / 8] & (1 << (chan % 8))) &&
-				    (mc->wValue[chan] != -1));
+				update = isset(mc->update, chan) &&
+					  (mc->wValue[chan] != -1);
 
-				mc->update[chan / 8] &= ~(1 << (chan % 8));
+				clrbit(mc->update, chan);
 
 				if (update) {
 
diff --git a/sys/bus/u4b/controller/ehci.c b/sys/bus/u4b/controller/ehci.c
index b072c95a10..ea27466ae2 100644
--- a/sys/bus/u4b/controller/ehci.c
+++ b/sys/bus/u4b/controller/ehci.c
@@ -2066,7 +2066,7 @@ ehci_root_intr(ehci_softc_t *sc)
 	for (i = 1; i < m; i++) {
 		/* pick out CHANGE bits from the status register */
 		if (EOREAD4(sc, EHCI_PORTSC(i)) & EHCI_PS_CLEAR) {
-			sc->sc_hub_idata[i / 8] |= 1 << (i % 8);
+			setbit(sc->sc_hub_idata, i);
 			DPRINTF("port %d changed\n", i);
 		}
 	}
diff --git a/sys/bus/u4b/controller/ohci.c b/sys/bus/u4b/controller/ohci.c
index 17a3f31043..4eb38af2a2 100644
--- a/sys/bus/u4b/controller/ohci.c
+++ b/sys/bus/u4b/controller/ohci.c
@@ -1611,7 +1611,7 @@ ohci_root_intr(ohci_softc_t *sc)
 	for (i = 1; i < m; i++) {
 		/* pick out CHANGE bits from the status register */
 		if (OREAD4(sc, OHCI_RH_PORT_STATUS(i)) >> 16) {
-			sc->sc_hub_idata[i / 8] |= 1 << (i % 8);
+			setbit(sc->sc_hub_idata, i);
 			DPRINTF("port %d changed\n", i);
 		}
 	}
diff --git a/sys/bus/u4b/controller/xhci.c b/sys/bus/u4b/controller/xhci.c
index f2d08330ab..c15a64ce4b 100644
--- a/sys/bus/u4b/controller/xhci.c
+++ b/sys/bus/u4b/controller/xhci.c
@@ -3026,7 +3026,7 @@ xhci_root_intr(struct xhci_softc *sc)
 		    XHCI_PS_OCC | XHCI_PS_WRC |
 		    XHCI_PS_PRC | XHCI_PS_PLC |
 		    XHCI_PS_CEC)) {
-			sc->sc_hub_idata[i / 8] |= 1 << (i % 8);
+			setbit(sc->sc_hub_idata, i);
 			DPRINTF("port %d changed\n", i);
 		}
 	}
diff --git a/sys/bus/u4b/net/if_axe.c b/sys/bus/u4b/net/if_axe.c
index 271f786059..ae6548808f 100644
--- a/sys/bus/u4b/net/if_axe.c
+++ b/sys/bus/u4b/net/if_axe.c
@@ -508,7 +508,7 @@ axe_setmulti(struct usb_ether *ue)
 			continue;
 		h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
 		    ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
-		hashtbl[h / 8] |= 1 << (h % 8);
+		setbit(hashtbl, h);
 	}
 
 	axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl);
diff --git a/sys/bus/u4b/net/if_axge.c b/sys/bus/u4b/net/if_axge.c
index 715a7a37d9..51ba654b09 100644
--- a/sys/bus/u4b/net/if_axge.c
+++ b/sys/bus/u4b/net/if_axge.c
@@ -759,7 +759,7 @@ axge_setmulti(struct usb_ether *ue)
 			continue;
 		h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
 		    ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
-		hashtbl[h / 8] |= 1 << (h % 8);
+		setbit(hashtbl, h);
 	}
 
 	axge_write_mem(sc, AXGE_ACCESS_MAC, 8, AXGE_MFA, (void *)&hashtbl, 8);
diff --git a/sys/bus/u4b/net/if_mos.c b/sys/bus/u4b/net/if_mos.c
index 9b35405831..b37f458481 100644
--- a/sys/bus/u4b/net/if_mos.c
+++ b/sys/bus/u4b/net/if_mos.c
@@ -608,7 +608,7 @@ mos_setmulti(struct usb_ether *ue)
 		}
 		h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
 		    ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
-		hashtbl[h / 8] |= 1 << (h % 8);
+		setbit(hashtbl, h);
 	}
 
 	/* now program new ones */
diff --git a/sys/bus/u4b/net/if_udav.c b/sys/bus/u4b/net/if_udav.c
index 6aaa668a9e..21153d511f 100644
--- a/sys/bus/u4b/net/if_udav.c
+++ b/sys/bus/u4b/net/if_udav.c
@@ -521,7 +521,7 @@ udav_setmulti(struct usb_ether *ue)
 			continue;
 		h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
 		    ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
-		hashtbl[h / 8] |= 1 << (h % 8);
+		setbit(hashtbl, h);
 	}
 
 	/* disable all multicast */
diff --git a/sys/bus/u4b/template/usb_template.c b/sys/bus/u4b/template/usb_template.c
index 3b0040c525..3f68c8731a 100644
--- a/sys/bus/u4b/template/usb_template.c
+++ b/sys/bus/u4b/template/usb_template.c
@@ -593,14 +593,14 @@ usb_hw_ep_find_match(struct usb_hw_ep_scratch *ues,
 		}
 		/* check if IN-endpoint is reserved */
 		if (dir_in || pf->is_simplex) {
-			if (ues->bmInAlloc[n / 8] & (1 << (n % 8))) {
+			if (isset(ues->bmInAlloc, n)) {
 				/* mismatch */
 				continue;
 			}
 		}
 		/* check if OUT-endpoint is reserved */
 		if (dir_out || pf->is_simplex) {
-			if (ues->bmOutAlloc[n / 8] & (1 << (n % 8))) {
+			if (isset(ues->bmOutAlloc, n)) {
 				/* mismatch */
 				continue;
 			}
-- 
2.23.0

