Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Jan 2017 20:41:32 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r311701 - head/sys/dev/gpio
Message-ID:  <201701082041.v08KfW1J069019@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: loos
Date: Sun Jan  8 20:41:32 2017
New Revision: 311701
URL: https://svnweb.freebsd.org/changeset/base/311701

Log:
  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

Modified:
  head/sys/dev/gpio/gpioc.c

Modified: head/sys/dev/gpio/gpioc.c
==============================================================================
--- head/sys/dev/gpio/gpioc.c	Sun Jan  8 20:37:41 2017	(r311700)
+++ head/sys/dev/gpio/gpioc.c	Sun Jan  8 20:41:32 2017	(r311701)
@@ -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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701082041.v08KfW1J069019>