diff options
author | loos <loos@FreeBSD.org> | 2017-01-08 20:41:32 +0000 |
---|---|---|
committer | Luiz Souza <luiz@netgate.com> | 2017-06-22 10:09:51 -0500 |
commit | a34bc01133cda92afb46582218390669ce15547b (patch) | |
tree | 9c69402722d4f54a6142d73d4d17305882d8b380 | |
parent | 981956f70fd72dfecf42adf4377e2acace4cfdd2 (diff) | |
download | FreeBSD-src-a34bc01133cda92afb46582218390669ce15547b.zip FreeBSD-src-a34bc01133cda92afb46582218390669ce15547b.tar.gz |
Convert gpioc to use the make_dev_s(9) KPI. This fix a possible race where
si_drv1 can be accessed before it gets set.
This is inspired on r311700.
MFC after: 3 days
(cherry picked from commit bc99dd22606c6c602e681adfff2b42db0158e7d6)
-rw-r--r-- | sys/dev/gpio/gpioc.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/sys/dev/gpio/gpioc.c b/sys/dev/gpio/gpioc.c index e68c174..2a6895a 100644 --- a/sys/dev/gpio/gpioc.c +++ b/sys/dev/gpio/gpioc.c @@ -78,18 +78,25 @@ gpioc_probe(device_t dev) static int gpioc_attach(device_t dev) { - struct gpioc_softc *sc = device_get_softc(dev); + int err; + struct gpioc_softc *sc; + struct make_dev_args devargs; + sc = device_get_softc(dev); sc->sc_dev = dev; sc->sc_pdev = device_get_parent(dev); sc->sc_unit = device_get_unit(dev); - sc->sc_ctl_dev = make_dev(&gpioc_cdevsw, sc->sc_unit, - UID_ROOT, GID_WHEEL, 0600, "gpioc%d", sc->sc_unit); - if (!sc->sc_ctl_dev) { + make_dev_args_init(&devargs); + devargs.mda_devsw = &gpioc_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_ctl_dev, "gpioc%d", sc->sc_unit); + if (err != 0) { printf("Failed to create gpioc%d", sc->sc_unit); return (ENXIO); } - sc->sc_ctl_dev->si_drv1 = sc; return (0); } |