1. 04 10月, 2017 2 次提交
    • L
      gpio: Alter semantics of *raw* operations to actually be raw · 02e47980
      Linus Walleij 提交于
      Currently calls to:
      gpiod_direction_output_raw()
      gpiod_set_raw_value()
      gpiod_set_raw_array_value()
      gpiod_set_raw_value_cansleep()
      gpiod_set_raw_array_value_cansleep()
      
      Respect that we do not want to invert the value written, but will
      still apply special open drain/open source semantics if the line has
      an open drain/open source flag.
      
      It also forbids us from driving an output marked as an interrupt
      line.
      
      This does not fit with the function name and expected semantics. In
      the w1 host driver (for example) we need to handle a line as open drain
      but sometimes force it to pull up, which means we should be able to
      use the gpiod_set_raw_value() for this, but it currently does not
      work.
      
      There are also use cases where users actually want to drive a line
      used by an interrupt. This is what they should be expected to use
      the *raw* accessors for.
      
      I have looked over the current users of this API and they do not seem
      to be using the *raw* accessors with open drain or open source so let's
      augment this behaviour before we have users expecting the inconsistent
      semantic.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      02e47980
    • L
      gpio: Get rid of _prefix and __prefixes · fac9d885
      Linus Walleij 提交于
      The arbitrarily marking of a function with _ or __ is taking to mean
      "perform some inner core of the caller" or something like that. At other
      times, this syntax has a totally different meaning.
      
      I don't like this since it is unambious and unhelpful to people reading
      the code, so replace it with _commit() suffixes.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      fac9d885
  2. 31 8月, 2017 1 次提交
  3. 23 8月, 2017 1 次提交
  4. 14 8月, 2017 4 次提交
    • T
      gpio: Cleanup kerneldoc · 950d55f5
      Thierry Reding 提交于
      Some kerneldoc has become stale or wasn't quite correct from the outset.
      Fix up the most serious issues to silence warnings when building the
      documentation.
      Signed-off-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      950d55f5
    • R
      gpio: Convert to using %pOF instead of full_name · 7eb6ce2f
      Rob Herring 提交于
      Now that we have a custom printf format specifier, convert users of
      full_name to use %pOF instead. This is preparation to remove storing
      of the full path string for each node.
      Signed-off-by: NRob Herring <robh@kernel.org>
      Cc: Tien Hock Loh <thloh@altera.com>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Alexandre Courbot <gnurou@gmail.com>
      Cc: Brian Norris <computersforpeace@gmail.com>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: bcm-kernel-feedback-list@broadcom.com
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: "Sören Brinkmann" <soren.brinkmann@xilinx.com>
      Cc: linux-gpio@vger.kernel.org
      Cc: linux-arm-kernel@lists.infradead.org
      Acked-by: NGregory Fong <gregory.0xf0@gmail.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      7eb6ce2f
    • G
      gpiolib: allow gpio irqchip to map irqs dynamically · dc749a09
      Grygorii Strashko 提交于
      Now IRQ mappings are always created for all (allowed) GPIOs in gpiochip in
      gpiochip_irqchip_add_key() which goes against the idea of SPARSE_IRQ and,
      as result, leads to:
       - increasing of memory consumption for IRQ descriptors most of which will
      never ever be used (espessially on platform with a high number of GPIOs).
      (sizeof(struct irq_desc) == 256 on my tested platforms)
       - imposibility to use GPIO irqchip APIs by gpio drivers when HW implements
      GPIO IRQ functionality as IRQ crossbar/router which has only limited
      number of IRQ outputs (example from [1], all GPIOs can be mapped on only 8
      IRQs).
      
      Hence, remove static IRQ mapping code from gpiochip_irqchip_add_key() and
      instead replace irq_find_mapping() with irq_create_mapping() in
      gpiochip_to_irq(). Also add additional gpiochip_irqchip_irq_valid() calls
      in gpiochip_to_irq() and gpiochip_irq_map().
      
      After this change gpio2irq mapping will happen the following way when GPIO
      irqchip APIs are used by gpio driver:
       - IRQ mappings will be created statically if driver passes first_irq>0
      vlaue in gpiochip_irqchip_add_key().
       - IRQ mappings will be created dynamically from gpio_to_irq() or
      of_irq_get().
      
      Tested on am335x-evm and dra72-evm-revc.
      - dra72-evm-revc: number of created irq mappings decreased from 402 -> 135
        Mem savings 267*256 = 68352 (66kB)
      - am335x-evm: number of created irq mappings decreased from 188 -> 63
        Mem savings 125*256 = 32000 (31kB)
      
      [1] https://lkml.org/lkml/2017/6/15/428Signed-off-by: NGrygorii Strashko <grygorii.strashko@ti.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      dc749a09
    • T
      gpiolib: request the gpio before querying its direction · 108d23e3
      Timur Tabi 提交于
      Before querying a GPIO to determine its direction, the GPIO should be
      formally requested.  This allows the GPIO driver to block access to
      unavailable GPIOs, which makes it easier for some drivers to support
      sparse GPIO maps.
      Signed-off-by: NTimur Tabi <timur@codeaurora.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      108d23e3
  5. 01 8月, 2017 1 次提交
  6. 29 6月, 2017 1 次提交
  7. 31 5月, 2017 1 次提交
  8. 29 5月, 2017 4 次提交
  9. 22 5月, 2017 1 次提交
  10. 13 4月, 2017 1 次提交
  11. 07 4月, 2017 1 次提交
    • L
      gpio: core: Decouple open drain/source flag with active low/high · 4c0facdd
      Laxman Dewangan 提交于
      Currently, the GPIO interface is said to Open Drain if it is Single
      Ended and active LOW. Similarly, it is said as Open Source if it is
      Single Ended and active HIGH.
      
      The active HIGH/LOW is used in the interface for setting the pin
      state to HIGH or LOW when enabling/disabling the interface.
      
      In Open Drain interface, pin is set to HIGH by putting pin in
      high impedance and LOW by driving to the LOW.
      
      In Open Source interface, pin is set to HIGH by driving pin to
      HIGH and set to LOW by putting pin in high impedance.
      
      With above, the Open Drain/Source is unrelated to the active LOW/HIGH
      in interface. There is interface where the enable/disable of interface
      is ether active LOW or HIGH but it is Open Drain type.
      
      Hence decouple the Open Drain with Single Ended + Active LOW and
      Open Source with Single Ended + Active HIGH.
      
      Adding different flag for the Open Drain/Open Source which is valid
      only when Single ended flag is enabled.
      Signed-off-by: NLaxman Dewangan <ldewangan@nvidia.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      4c0facdd
  12. 21 3月, 2017 1 次提交
  13. 17 3月, 2017 1 次提交
  14. 14 3月, 2017 1 次提交
  15. 05 2月, 2017 1 次提交
  16. 31 1月, 2017 1 次提交
  17. 26 1月, 2017 3 次提交
  18. 19 1月, 2017 1 次提交
  19. 11 1月, 2017 2 次提交
  20. 30 12月, 2016 1 次提交
  21. 07 12月, 2016 1 次提交
    • L
      gpio: chardev: Return error for seek operations · f4e81c52
      Lars-Peter Clausen 提交于
      The GPIO chardev is used for management tasks (allocating line and event
      handles) and does neither support read() nor write() operations. Hence it
      does not make much sense to allow seek operations.
      
      Currently the chardev uses noop_llseek() for its seek implementation. This
      function does not move the pointer and simply returns the current position
      (always 0 for the GPIO chardev). noop_llseek() is primarily meant for
      devices that can not support seek, but where there might be a user that
      depends on the seek() operation succeeding. For newly added devices that
      can not support seek operations it is recommended to use no_llseek(), which
      will return an error. For more information see commit 6038f373
      ("llseek: automatically add .llseek fop").
      
      Unfortunately this was overlooked when the GPIO chardev ABI was introduced.
      But it is highly unlikely that since then userspace applications have
      appeared that rely on being able to perform non-failing seek operations on
      a GPIO chardev file descriptor. So it should be safe to change from
      noop_llseel() to no_seek(). Also use nonseekable_open() in the chardev
      open() callback to clear the FMODE_SEEK, FMODE_PREAD and FMODE_PWRITE flags
      from the file. Neither of these should be set on a file that does not
      support seek operations.
      
      Cc: stable@vger.kernel.org
      Fixes: 3c702e99 ("gpio: add a userspace chardev ABI for GPIOs")
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      f4e81c52
  22. 25 11月, 2016 1 次提交
    • L
      gpio: simplify adding threaded interrupts · d245b3f9
      Linus Walleij 提交于
      This tries to simplify the use of CONFIG_GPIOLIB_IRQCHIP when
      using threaded interrupts: add a new call
      gpiochip_irqchip_add_nested() to indicate that we're dealing
      with a nested rather than a chained irqchip, then create a
      separate gpiochip_set_nested_irqchip() to mirror
      the gpiochip_set_chained_irqchip() call to connect the
      parent and child interrupts.
      
      In the nested case gpiochip_set_nested_irqchip() does nothing
      more than call irq_set_parent() on each valid child interrupt,
      which has little semantic effect in the kernel, but this is
      probably still formally correct.
      
      Update all drivers using nested interrupts to use
      gpiochip_irqchip_add_nested() so we can now see clearly
      which these users are.
      
      The DLN2 driver can drop its specific hack with
      .irq_not_threaded as we now recognize whether a chip is
      threaded or not from its use of gpiochip_irqchip_add_nested()
      signature rather than from inspecting .can_sleep.
      
      We rename the .irq_parent to .irq_chained_parent since this
      parent IRQ is only really kept around for the chained
      interrupt handlers.
      
      Cc: Lars Poeschel <poeschel@lemonage.de>
      Cc: Octavian Purdila <octavian.purdila@intel.com>
      Cc: Daniel Baluta <daniel.baluta@intel.com>
      Cc: Bin Gao <bin.gao@linux.intel.com>
      Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
      Cc: Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com>
      Cc: Semen Protsenko <semen.protsenko@globallogic.com>
      Cc: Alexander Stein <alexander.stein@systec-electronic.com>
      Cc: Phil Reid <preid@electromag.com.au>
      Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      d245b3f9
  23. 15 11月, 2016 3 次提交
    • L
      gpio: tag line labels used for interrupts · 3940c34a
      Linus Walleij 提交于
      When a GPIO line is marked as used for an interrupt, it is
      helpful to set the label to "interrupt" so we know what is
      going on when inspecting the lines.
      
      If a GPIO is already properly named by gpiod_get*() we don't
      need to do this. It only happens when a line is used from
      the irqchip side of a GPIO driver without communicating
      with the GPIO side, such as when gpiochip is used as interrupt
      provider in the device tree.
      
      If the line is still marked as used by "interrupt" when we
      unmark it as used by an interrupt, also remove this label
      from the descriptor.
      
      Also shape up the code around unmarking IRQ lines.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      3940c34a
    • L
      gpio: clamp values on gpio[d]_direction_output() · ad17731d
      Linus Walleij 提交于
      I saw weird values != [0,1] being passed down to drivers
      in their .set_direction_output() callbacks. Go over the
      gpiolib and make sure to hammer it to [0,1] before hitting
      the driver to avoid undesired side effects.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      ad17731d
    • L
      gpio: do not double-check direction on sleeping chips · 60f8339e
      Linus Walleij 提交于
      When locking a GPIO line as IRQ, we go to lengths to
      double-check that the line is really set as input before
      marking it as used for IRQ. This is not good on GPIO chips
      that can sleep, because this function is called in IRQ-safe
      context. Just skip this if it can't be checked quickly.
      
      Currently this happens on sleeping expanders such as STMPE
      or TC3589x:
      
      BUG: scheduling while atomic: swapper/1/0x00000002
      Modules linked in:
      CPU: 0 PID: 1 Comm: swapper Not tainted 4.9.0-rc1+ #38
      Hardware name: Nomadik STn8815
      [<c000f2e0>] (unwind_backtrace) from [<c000d244>] (show_stack+0x10/0x14)
      [<c000d244>] (show_stack) from [<c0037b78>] (__schedule_bug+0x54/0x80)
      [<c0037b78>] (__schedule_bug) from [<c042df14>] (__schedule+0x3a0/0x460)
      [<c042df14>] (__schedule) from [<c042e028>] (schedule+0x54/0xb8)
      (...)
      
      This patch fixes that problem and relies on the direction
      read from the chip when it was added.
      
      Cc: stable@vger.kernel.org
      Fixes: 9c10280d ("gpio: flush direction status in gpiochip_lock_as_irq()")
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      60f8339e
  24. 01 11月, 2016 1 次提交
    • L
      gpio: GPIO_GET_LINE{HANDLE,EVENT}_IOCTL: Fix file descriptor leak · 953b956a
      Lars-Peter Clausen 提交于
      When allocating a new line handle or event a file is allocated that it is
      associated to. The file is attached to a file descriptor of the current
      process and the file descriptor is returned to userspace using
      copy_to_user(). If this copy operation fails the line handle or event
      allocation is aborted, all acquired resources are freed and an error is
      returned.
      
      But the file struct is not freed and left attached to the userspace
      application and even though the file descriptor number was not copied it is
      trivial to guess. If a userspace application performs a IOCTL on such a
      left over file descriptor it will trigger a use-after-free and if the file
      descriptor is closed (latest when the application exits) a double-free is
      triggered.
      
      anon_inode_getfd() performs 3 tasks, allocate a file struct, allocate a
      file descriptor for the current process and install the file struct in the
      file descriptor. As soon as the file struct is installed in the file
      descriptor it is accessible by userspace (even if the IOCTL itself hasn't
      completed yet), this means uninstalling the fd on the error path is not an
      option, since userspace might already got a reference to the file.
      
      Instead anon_inode_getfd() needs to be broken into its individual steps.
      The allocation of the file struct and file descriptor is done first, then
      the copy_to_user() is executed and only if it succeeds the file is
      installed.
      
      Since the file struct is reference counted it can not be just freed, but
      its reference needs to be dropped, which will also call the release()
      callback, which will free the state attached to the file. So in this case
      the normal error cleanup path should not be taken.
      
      Cc: stable@vger.kernel.org
      Fixes: d932cd49 ("gpio: free handles in fringe cases")
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      953b956a
  25. 21 10月, 2016 4 次提交
    • L
      gpio: GPIO_GET_LINEEVENT_IOCTL: Reject invalid line and event flags · ac7dbb99
      Lars-Peter Clausen 提交于
      The GPIO_GET_LINEEVENT_IOCTL currently ignores unknown or undefined
      linehandle and lineevent flags. From a backwards and forwards compatibility
      viewpoint it is highly desirable to reject unknown flags though.
      
      On one hand an application that is using newer flags and is running on
      an older kernel has no way to detect if the new flags were handled
      correctly if they are silently discarded.
      
      On the other hand an application that (accidentally) passes undefined flags
      will run fine on an older kernel, but may break on a newer kernel when
      these flags get defined.
      
      Ensure that requests that have undefined flags set are rejected with an
      error, rather than silently discarding the undefined flags.
      
      Cc: stable@vger.kernel.org
      Fixes: 61f922db ("gpio: userspace ABI for reading GPIO line events")
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      ac7dbb99
    • L
      gpio: GPIO_GET_LINEHANDLE_IOCTL: Reject invalid line flags · e3e847c7
      Lars-Peter Clausen 提交于
      The GPIO_GET_LINEHANDLE_IOCTL currently ignores unknown or undefined
      linehandle flags. From a backwards and forwards compatibility viewpoint it
      is highly desirable to reject unknown flags though.
      
      On one hand an application that is using newer flags and is running on
      an older kernel has no way to detect if the new flags were handled
      correctly if they are silently discarded.
      
      On the other hand an application that (accidentally) passes undefined flags
      will run fine on an older kernel, but may break on a newer kernel when
      these flags get defined.
      
      Ensure that requests that have undefined flags set are rejected with an
      error, rather than silently discarding the undefined flags.
      
      Cc: stable@vger.kernel.org
      Fixes: d7c51b47 ("gpio: userspace ABI for reading/writing GPIO lines")
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      e3e847c7
    • L
      gpio: GPIOHANDLE_GET_LINE_VALUES_IOCTL: Fix information leak · 3eded5d8
      Lars-Peter Clausen 提交于
      The GPIOHANDLE_GET_LINE_VALUES_IOCTL handler allocates a gpiohandle_data
      struct on the stack and then passes it to copy_to_user(). But depending on
      the number of requested line handles the struct is only partially
      initialized.
      
      This exposes the previous, potentially sensitive, stack content to the
      issuing userspace application. To avoid this make sure that the struct is
      fully initialized.
      
      Cc: stable@vger.kernel.org
      Fixes: d7c51b47 ("gpio: userspace ABI for reading/writing GPIO lines")
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      3eded5d8
    • L
      gpio: GPIO_GET_LINEEVENT_IOCTL: Validate line offset · b8b0e3d3
      Lars-Peter Clausen 提交于
      The line offset that is used as an index into the descs array is provided
      by userspace and might go beyond the bounds of the array. If that happens
      undefined behavior will occur.
      
      Make sure that the offset is within the bounds of the desc array and reject
      any requests that specify a value outside of it.
      
      Cc: stable@vger.kernel.org
      Fixes: 61f922db ("gpio: userspace ABI for reading GPIO line events")
      Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      b8b0e3d3