From owner-svn-src-all@freebsd.org Sun Oct 1 11:17:31 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D6D68E1464F; Sun, 1 Oct 2017 11:17:31 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B011A82346; Sun, 1 Oct 2017 11:17:31 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v91BHU7R000764; Sun, 1 Oct 2017 11:17:30 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v91BHUkB000763; Sun, 1 Oct 2017 11:17:30 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201710011117.v91BHUkB000763@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 1 Oct 2017 11:17:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324156 - head/sys/dev/smbus X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/dev/smbus X-SVN-Commit-Revision: 324156 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Oct 2017 11:17:32 -0000 Author: kib Date: Sun Oct 1 11:17:30 2017 New Revision: 324156 URL: https://svnweb.freebsd.org/changeset/base/324156 Log: Improve smb(4) devfs interactions. Use make_dev_s(9) to create device, since the device ioctl interface needs to access si_drv1 to get softc pointer. Remove the common but not functional attempt to prevent parallel accesses by file descriptors by blocking more than one open. Either threads in one process, or forked siblings, or file descriptors passed over unix domain sockets all allow to execute parallel requests once one fd is opened. Since ioctl handler uses smbus_request_bus() to take the bus ownership, the correct mechanism establishes exclusive access already. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Modified: head/sys/dev/smbus/smb.c Modified: head/sys/dev/smbus/smb.c ============================================================================== --- head/sys/dev/smbus/smb.c Sun Oct 1 09:48:31 2017 (r324155) +++ head/sys/dev/smbus/smb.c Sun Oct 1 11:17:30 2017 (r324156) @@ -47,9 +47,7 @@ struct smb_softc { device_t sc_dev; - int sc_count; /* >0 if device opened */ struct cdev *sc_devnode; - struct mtx sc_lock; }; static void smb_identify(driver_t *driver, device_t parent); @@ -78,15 +76,11 @@ static driver_t smb_driver = { sizeof(struct smb_softc), }; -static d_open_t smbopen; -static d_close_t smbclose; static d_ioctl_t smbioctl; static struct cdevsw smb_cdevsw = { .d_version = D_VERSION, .d_flags = D_TRACKCLOSE, - .d_open = smbopen, - .d_close = smbclose, .d_ioctl = smbioctl, .d_name = "smb", }; @@ -112,59 +106,31 @@ smb_probe(device_t dev) static int smb_attach(device_t dev) { - struct smb_softc *sc = device_get_softc(dev); - int unit; - - unit = device_get_unit(dev); + struct smb_softc *sc; + struct make_dev_args mda; + int error; + + sc = device_get_softc(dev); sc->sc_dev = dev; - sc->sc_devnode = make_dev(&smb_cdevsw, unit, UID_ROOT, GID_WHEEL, - 0600, "smb%d", unit); - sc->sc_devnode->si_drv1 = sc; - mtx_init(&sc->sc_lock, device_get_nameunit(dev), NULL, MTX_DEF); - - return (0); + make_dev_args_init(&mda); + mda.mda_devsw = &smb_cdevsw; + mda.mda_unit = device_get_unit(dev); + mda.mda_uid = UID_ROOT; + mda.mda_gid = GID_WHEEL; + mda.mda_mode = 0600; + mda.mda_si_drv1 = sc; + error = make_dev_s(&mda, &sc->sc_devnode, "smb%d", mda.mda_unit); + return (error); } static int smb_detach(device_t dev) { - struct smb_softc *sc = (struct smb_softc *)device_get_softc(dev); + struct smb_softc *sc; - if (sc->sc_devnode) - destroy_dev(sc->sc_devnode); - mtx_destroy(&sc->sc_lock); - - return (0); -} - -static int -smbopen(struct cdev *dev, int flags, int fmt, struct thread *td) -{ - struct smb_softc *sc = dev->si_drv1; - - mtx_lock(&sc->sc_lock); - if (sc->sc_count != 0) { - mtx_unlock(&sc->sc_lock); - return (EBUSY); - } - - sc->sc_count++; - mtx_unlock(&sc->sc_lock); - - return (0); -} - -static int -smbclose(struct cdev *dev, int flags, int fmt, struct thread *td) -{ - struct smb_softc *sc = dev->si_drv1; - - mtx_lock(&sc->sc_lock); - KASSERT(sc->sc_count == 1, ("device not busy")); - sc->sc_count--; - mtx_unlock(&sc->sc_lock); - + sc = device_get_softc(dev); + destroy_dev(sc->sc_devnode); return (0); }