Skip to content

Commit 4d83da2

Browse files
committed
Introduce findchrmajor() and use where appropriate.
1 parent 9be48ff commit 4d83da2

File tree

18 files changed

+38
-89
lines changed

18 files changed

+38
-89
lines changed

sys/arch/amd64/amd64/wscons_machdep.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,9 @@ wscnprobe(struct consdev *cp)
8282
{
8383
int maj;
8484

85-
/* locate the major number */
86-
for (maj = 0; maj < nchrdev; maj++) {
87-
if (cdevsw[maj].d_open == wsdisplayopen)
88-
break;
89-
}
90-
91-
if (maj == nchrdev) {
92-
/* we are not in cdevsw[], give up */
85+
maj = findchrmajor(wsdisplayopen);
86+
if (maj == -1)
9387
panic("wsdisplay is not in cdevsw[]");
94-
}
9588

9689
cp->cn_dev = makedev(maj, 0);
9790
cp->cn_pri = CN_MIDPRI;

sys/dev/audio.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,7 @@ audiodetach(struct device *self, int flags)
516516
audio_free_ring(sc, &sc->sc_pr);
517517
audio_free_ring(sc, &sc->sc_rr);
518518

519-
/* locate the major number */
520-
for (maj = 0; maj < nchrdev; maj++)
521-
if (cdevsw[maj].d_open == audioopen)
522-
break;
519+
maj = findchrmajor(audioopen);
523520

524521
/* Nuke the vnodes for any open instances (calls close). */
525522
mn = self->dv_unit;

sys/dev/gpio/gpio.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ gpio_detach(struct device *self, int flags)
110110
{
111111
int maj, mn;
112112

113-
/* Locate the major number */
114-
for (maj = 0; maj < nchrdev; maj++)
115-
if (cdevsw[maj].d_open == gpioopen)
116-
break;
113+
maj = findchrmajor(gpioopen);
117114

118115
/* Nuke the vnodes for any open instances (calls close) */
119116
mn = self->dv_unit;

sys/dev/ic/com.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ com_detach(struct device *self, int flags)
201201

202202
sc->sc_swflags |= COM_SW_DEAD;
203203

204-
/* Locate the major number. */
205-
for (maj = 0; maj < nchrdev; maj++)
206-
if (cdevsw[maj].d_open == comopen)
207-
break;
204+
maj = findchrmajor(comopen);
208205

209206
/* Nuke the vnodes for any open instances. */
210207
mn = self->dv_unit;
@@ -1422,10 +1419,7 @@ comcnprobe(struct consdev *cp)
14221419
if (!found)
14231420
return;
14241421

1425-
/* Locate the major number. */
1426-
for (commajor = 0; commajor < nchrdev; commajor++)
1427-
if (cdevsw[commajor].d_open == comopen)
1428-
break;
1422+
commajor = findchrmajor(comopen);
14291423

14301424
/* Initialize required fields. */
14311425
cp->cn_dev = makedev(commajor, comconsunit);
@@ -1807,12 +1801,9 @@ com_attach_subr(struct com_softc *sc)
18071801
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
18081802
int maj;
18091803

1810-
/* locate the major number */
1811-
for (maj = 0; maj < nchrdev; maj++)
1812-
if (cdevsw[maj].d_open == comopen)
1813-
break;
1804+
maj = findchrmajor(comopen);
18141805

1815-
if (maj < nchrdev && cn_tab->cn_dev == NODEV)
1806+
if (maj != -1 && cn_tab->cn_dev == NODEV)
18161807
cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
18171808

18181809
printf("%s: console\n", sc->sc_dev.dv_xname);

sys/dev/pci/cz.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,12 +872,8 @@ cztty_findmajor(void)
872872
{
873873
int maj;
874874

875-
for (maj = 0; maj < nchrdev; maj++) {
876-
if (cdevsw[maj].d_open == czttyopen)
877-
break;
878-
}
879-
880-
return (maj == nchrdev) ? 0 : maj;
875+
maj = findchrmajor(czttyopen);
876+
return (maj == -1) ? 0 : maj;
881877
}
882878

883879
/*

sys/dev/radio.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,7 @@ radiodetach(struct device *self, int flags)
176176
/*struct radio_softc *sc = (struct radio_softc *)self;*/
177177
int maj, mn;
178178

179-
/* locate the major number */
180-
for (maj = 0; maj < nchrdev; maj++)
181-
if (cdevsw[maj].d_open == radioopen)
182-
break;
179+
maj = findchrmajor(radioopen);
183180

184181
/* Nuke the vnodes for any open instances (calls close). */
185182
mn = self->dv_unit;

sys/dev/usb/ucom.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,7 @@ ucom_detach(struct device *self, int flags)
255255
}
256256
splx(s);
257257

258-
/* locate the major number */
259-
for (maj = 0; maj < nchrdev; maj++)
260-
if (cdevsw[maj].d_open == ucomopen)
261-
break;
258+
maj = findchrmajor(ucomopen);
262259

263260
/* Nuke the vnodes for any open instances. */
264261
mn = self->dv_unit;

sys/dev/usb/ugen.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,7 @@ ugen_detach(struct device *self, int flags)
765765
}
766766
splx(s);
767767

768-
/* locate the major number */
769-
for (maj = 0; maj < nchrdev; maj++)
770-
if (cdevsw[maj].d_open == ugenopen)
771-
break;
768+
maj = findchrmajor(ugenopen);
772769

773770
/* Nuke the vnodes for any open instances (calls close). */
774771
mn = self->dv_unit * USB_MAX_ENDPOINTS;

sys/dev/usb/uhid.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ uhid_detach(struct device *self, int flags)
165165
splx(s);
166166
}
167167

168-
/* locate the major number */
169-
for (maj = 0; maj < nchrdev; maj++)
170-
if (cdevsw[maj].d_open == uhidopen)
171-
break;
168+
maj = findchrmajor(uhidopen);
172169

173170
/* Nuke the vnodes for any open instances (calls close). */
174171
mn = self->dv_unit;

sys/dev/usb/ulpt.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,7 @@ ulpt_detach(struct device *self, int flags)
378378
}
379379
splx(s);
380380

381-
/* locate the major number */
382-
for (maj = 0; maj < nchrdev; maj++)
383-
if (cdevsw[maj].d_open == ulptopen)
384-
break;
381+
maj = findchrmajor(ulptopen);
385382

386383
/* Nuke the vnodes for any open instances (calls close). */
387384
mn = self->dv_unit;

0 commit comments

Comments
 (0)