From owner-svn-src-all@freebsd.org Thu Apr 7 19:17:48 2016 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 85B26B0834E; Thu, 7 Apr 2016 19:17:48 +0000 (UTC) (envelope-from ian@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 5D2121179; Thu, 7 Apr 2016 19:17:48 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u37JHlb2092611; Thu, 7 Apr 2016 19:17:47 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u37JHlLV092610; Thu, 7 Apr 2016 19:17:47 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201604071917.u37JHlLV092610@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Thu, 7 Apr 2016 19:17:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297683 - head/sys/arm/freescale/imx X-SVN-Group: head 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.21 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: Thu, 07 Apr 2016 19:17:48 -0000 Author: ian Date: Thu Apr 7 19:17:47 2016 New Revision: 297683 URL: https://svnweb.freebsd.org/changeset/base/297683 Log: Code cleanup: stop searching for a pin in the array and just use the pin number directly as an index. We create the array ourselves and nothing can change the order of items in it, it's a simple 1:1 mapping. Modified: head/sys/arm/freescale/imx/imx_gpio.c Modified: head/sys/arm/freescale/imx/imx_gpio.c ============================================================================== --- head/sys/arm/freescale/imx/imx_gpio.c Thu Apr 7 18:19:09 2016 (r297682) +++ head/sys/arm/freescale/imx/imx_gpio.c Thu Apr 7 19:17:47 2016 (r297683) @@ -497,19 +497,14 @@ static int imx51_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); mtx_lock_spin(&sc->sc_mtx); - *caps = sc->gpio_pins[i].gp_caps; + *caps = sc->gpio_pins[pin].gp_caps; mtx_unlock_spin(&sc->sc_mtx); return (0); @@ -519,19 +514,14 @@ static int imx51_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); mtx_lock_spin(&sc->sc_mtx); - *flags = sc->gpio_pins[i].gp_flags; + *flags = sc->gpio_pins[pin].gp_flags; mtx_unlock_spin(&sc->sc_mtx); return (0); @@ -541,19 +531,13 @@ static int imx51_gpio_pin_getname(device_t dev, uint32_t pin, char *name) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); mtx_lock_spin(&sc->sc_mtx); - memcpy(name, sc->gpio_pins[i].gp_name, GPIOMAXNAME); + memcpy(name, sc->gpio_pins[pin].gp_name, GPIOMAXNAME); mtx_unlock_spin(&sc->sc_mtx); return (0); @@ -563,18 +547,13 @@ static int imx51_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); - imx51_gpio_pin_configure(sc, &sc->gpio_pins[i], flags); + imx51_gpio_pin_configure(sc, &sc->gpio_pins[pin], flags); return (0); } @@ -583,22 +562,17 @@ static int imx51_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); mtx_lock_spin(&sc->sc_mtx); if (value) - SET4(sc, IMX_GPIO_DR_REG, (1U << i)); + SET4(sc, IMX_GPIO_DR_REG, (1U << pin)); else - CLEAR4(sc, IMX_GPIO_DR_REG, (1U << i)); + CLEAR4(sc, IMX_GPIO_DR_REG, (1U << pin)); mtx_unlock_spin(&sc->sc_mtx); return (0); @@ -608,19 +582,14 @@ static int imx51_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); mtx_lock_spin(&sc->sc_mtx); - *val = (READ4(sc, IMX_GPIO_DR_REG) >> i) & 1; + *val = (READ4(sc, IMX_GPIO_DR_REG) >> pin) & 1; mtx_unlock_spin(&sc->sc_mtx); return (0); @@ -630,20 +599,15 @@ static int imx51_gpio_pin_toggle(device_t dev, uint32_t pin) { struct imx51_gpio_softc *sc; - int i; sc = device_get_softc(dev); - for (i = 0; i < sc->gpio_npins; i++) { - if (sc->gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->gpio_npins) + if (pin >= sc->gpio_npins) return (EINVAL); mtx_lock_spin(&sc->sc_mtx); WRITE4(sc, IMX_GPIO_DR_REG, - (READ4(sc, IMX_GPIO_DR_REG) ^ (1U << i))); + (READ4(sc, IMX_GPIO_DR_REG) ^ (1U << pin))); mtx_unlock_spin(&sc->sc_mtx); return (0);