From 5ff8fca6052cd72049ea8ddc53ba5c053a6990aa Mon Sep 17 00:00:00 2001 From: loos Date: Sun, 8 Jan 2017 20:37:41 +0000 Subject: [PATCH] Convert etherswitch to use the make_dev_s(9) KPI. This fix a possible race where si_drv1 can be accessed before it gets set. MFC after: 3 days Suggested by: kib Sponsored by: Rubicon Communications, LLC (Netgate) --- sys/dev/etherswitch/etherswitch.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sys/dev/etherswitch/etherswitch.c b/sys/dev/etherswitch/etherswitch.c index 0c35002d22f5..ee9b71086bed 100644 --- a/sys/dev/etherswitch/etherswitch.c +++ b/sys/dev/etherswitch/etherswitch.c @@ -99,17 +99,24 @@ etherswitch_probe(device_t dev) static int etherswitch_attach(device_t dev) { - struct etherswitch_softc *sc = (struct etherswitch_softc *)device_get_softc(dev); + int err; + struct etherswitch_softc *sc; + struct make_dev_args devargs; + sc = device_get_softc(dev); sc->sc_dev = dev; - sc->sc_devnode = make_dev(ðerswitch_cdevsw, device_get_unit(dev), - UID_ROOT, GID_WHEEL, - 0600, "etherswitch%d", device_get_unit(dev)); - if (sc->sc_devnode == NULL) { + make_dev_args_init(&devargs); + devargs.mda_devsw = ðerswitch_cdevsw; + devargs.mda_uid = UID_ROOT; + devargs.mda_gid = GID_WHEEL; + devargs.mda_mode = 0600; + devargs.mda_si_drv1 = sc; + err = make_dev_s(&devargs, &sc->sc_devnode, "etherswitch%d", + device_get_unit(dev)); + if (err != 0) { device_printf(dev, "failed to create character device\n"); return (ENXIO); } - sc->sc_devnode->si_drv1 = sc; return (0); }