From owner-dev-commits-src-all@freebsd.org Mon May 17 13:47:58 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 721926487F0; Mon, 17 May 2021 13:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FkL7217Vpz3C52; Mon, 17 May 2021 13:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 02E4E5216; Mon, 17 May 2021 13:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14HDlvel051626; Mon, 17 May 2021 13:47:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14HDlvhx051625; Mon, 17 May 2021 13:47:57 GMT (envelope-from git) Date: Mon, 17 May 2021 13:47:57 GMT Message-Id: <202105171347.14HDlvhx051625@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: b2ee069e8cf7 - main - Fix locking in qoriq_gpio MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b2ee069e8cf73ea91388dbbc9061af01109c774a Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 13:47:58 -0000 The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=b2ee069e8cf73ea91388dbbc9061af01109c774a commit b2ee069e8cf73ea91388dbbc9061af01109c774a Author: Justin Hibbits AuthorDate: 2021-05-17 13:22:30 +0000 Commit: Justin Hibbits CommitDate: 2021-05-17 13:46:45 +0000 Fix locking in qoriq_gpio qoriq_gpio_pin_setflags() locks the device mutex, as does qoriq_gpio_map_gpios(), causing a recursion on non-recursive lock. This was missed during testing for 16e549ebe. --- sys/dev/gpio/qoriq_gpio.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/sys/dev/gpio/qoriq_gpio.c b/sys/dev/gpio/qoriq_gpio.c index 82bd6cd9a72b..dc4813e07b8e 100644 --- a/sys/dev/gpio/qoriq_gpio.c +++ b/sys/dev/gpio/qoriq_gpio.c @@ -131,23 +131,15 @@ qoriq_gpio_pin_getname(device_t dev, uint32_t pin, char *name) return (0); } -/* Set flags for the pin. */ static int -qoriq_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) +qoriq_gpio_pin_configure(device_t dev, uint32_t pin, uint32_t flags) { - struct qoriq_gpio_softc *sc = device_get_softc(dev); + struct qoriq_gpio_softc *sc; uint32_t reg; - if (!VALID_PIN(pin)) - return (EINVAL); - - if ((flags & (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) == - (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) - return (EINVAL); + sc = device_get_softc(dev); - GPIO_LOCK(sc); if ((flags & sc->sc_pins[pin].gp_caps) != flags) { - GPIO_UNLOCK(sc); return (EINVAL); } @@ -168,6 +160,26 @@ qoriq_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) bus_write_4(sc->sc_mem, GPIO_GPODR, reg); } sc->sc_pins[pin].gp_flags = flags; + + return (0); +} + +/* Set flags for the pin. */ +static int +qoriq_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) +{ + struct qoriq_gpio_softc *sc = device_get_softc(dev); + uint32_t ret; + + if (!VALID_PIN(pin)) + return (EINVAL); + + if ((flags & (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) == + (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) + return (EINVAL); + + GPIO_LOCK(sc); + ret = qoriq_gpio_pin_configure(dev, pin, flags); GPIO_UNLOCK(sc); return (0); } @@ -356,7 +368,7 @@ qoriq_gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells, sc = device_get_softc(bus); GPIO_LOCK(sc); - err = qoriq_gpio_pin_setflags(bus, gpios[0], gpios[1]); + err = qoriq_gpio_pin_configure(bus, gpios[0], gpios[1]); GPIO_UNLOCK(sc); if (err == 0) {