Commit graph

5966 commits

Author SHA1 Message Date
Kent Gibson
83092341e1 gpio: cdev: fix missed label sanitizing in debounce_setup()
When adding sanitization of the label, the path through
edge_detector_setup() that leads to debounce_setup() was overlooked.
A request taking this path does not allocate a new label and the
request label is freed twice when the request is released, resulting
in memory corruption.

Add label sanitization to debounce_setup().

Cc: stable@vger.kernel.org
Fixes: b34490879b ("gpio: cdev: sanitize the label before requesting the interrupt")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
[Bartosz: rebased on top of the fix for empty GPIO labels]
Co-developed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-04-04 18:57:08 +02:00
Bartosz Golaszewski
b3b9596459 gpio: cdev: check for NULL labels when sanitizing them for irqs
We need to take into account that a line's consumer label may be NULL
and not try to kstrdup() it in that case but rather pass the NULL
pointer up the stack to the interrupt request function.

To that end: let make_irq_label() return NULL as a valid return value
and use ERR_PTR() instead to signal an allocation failure to callers.

Cc: stable@vger.kernel.org
Fixes: b34490879b ("gpio: cdev: sanitize the label before requesting the interrupt")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/lkml/20240402093534.212283-1-naresh.kamboju@linaro.org/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
2024-04-04 16:57:52 +02:00
Hans de Goede
e8acd2d209 gpiolib: Fix triggering "kobject: 'gpiochipX' is not initialized, yet" kobject_get() errors
When a gpiochip gets added by loading a module, then another driver may
be waiting for that gpiochip to load on the deferred-probe list.

If the deferred-probe for the consumer of gpiochip then triggers between
the gpiodev_add_to_list_unlocked() calls which makes gpio_device_find()
see the chip and the gpiochip_setup_dev() later then gpio_device_find()
does a kobject_get() on an uninitialized kobject since the kobject is
initialized by gpiochip_setup_dev() calling device_initialize():

 arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring
 arizona spi-10WM5102:00: cannot find GPIO chip arizona, deferring
 ------------[ cut here ]------------
 kobject: 'gpiochip5' (00000000241466f2): is not initialized, yet kobject_get() is being called.
 WARNING: CPU: 3 PID: 42 at lib/kobject.c:640 kobject_get+0x43/0x70
 Call Trace:
  kobject_get
  gpio_device_find
  gpiod_find_and_request
  gpiod_get
  snd_byt_wm5102_mc_probe

Not only is the device not initialized yet, but when the gpio-device is
added to the list things like the irqchip also have not been initialized
yet.

So gpio_device_find() should really ignore the gpio-device until
gpiochip_add_data_with_key() is fully done. Add a device_is_registered()
check to gpio_device_find() to ignore gpio-devices on the list which are
not yet fully initialized.

Fixes: aab5c6f200 ("gpio: set device type for GPIO chips")
Suggested-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
[Bartosz: fix a typo in commit message]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-04-03 13:04:32 +02:00
Andy Shevchenko
5c887b65bb gpiolib: Fix debug messaging in gpiod_find_and_request()
When consolidating GPIO lookups in ACPI code, the debug messaging
had been reworked that the user may see

  [   13.401147] (NULL device *): using ACPI '\_SB.LEDS.led-0' for '(null)' GPIO lookup
  [   13.401378] gpio gpiochip0: Persistence not supported for GPIO 40
  [   13.401402] gpio-40 (?): no flags found for (null)

instead of

  [   14.182962] gpio gpiochip0: Persistence not supported for GPIO 40
  [   14.182994] gpio-40 (?): no flags found for gpios

The '(null)' parts are less informative and likely scare the users.
Replace them by '(default)' which can point out to the default connection
IDs, such as 'gpios'.

While at it, amend other places where con_id is used in the messages.

Reported-by: Ferry Toth <ftoth@exalondelft.nl>
Fixes: 8eb1f71e7a ("gpiolib: consolidate GPIO lookups")
Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Tested-by: Ferry Toth <ftoth@exalondelft.nl>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-26 12:50:50 +01:00
Bartosz Golaszewski
b34490879b gpio: cdev: sanitize the label before requesting the interrupt
When an interrupt is requested, a procfs directory is created under
"/proc/irq/<irqnum>/<label>" where <label> is the string passed to one of
the request_irq() variants.

What follows is that the string must not contain the "/" character or
the procfs mkdir operation will fail. We don't have such constraints for
GPIO consumer labels which are used verbatim as interrupt labels for
GPIO irqs. We must therefore sanitize the consumer string before
requesting the interrupt.

Let's replace all "/" with ":".

Cc: stable@vger.kernel.org
Reported-by: Stefan Wahren <wahrenst@gmx.net>
Closes: https://lore.kernel.org/linux-gpio/39fe95cb-aa83-4b8b-8cab-63947a726754@gmx.net/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
2024-03-26 12:43:35 +01:00
Linus Torvalds
a3df5d5422 Pin control changes for the v6.9 kernel cycle:
No core changes this time around.
 
 New drivers:
 
 - New driver for Renesas R8A779H0 also known as R-Car V4M.
 
 - New driver for the Awinic AW9523/B I2C GPIO expander.
   I found this living out-of-tree in OpenWrt as an upstream
   attempt had stalled on the finishing line, so I picked it
   up and finished the job.
 
 Improvements:
 
 - The Nomadik pin control driver was for years re-used out of
   tree for the ST STA chips, and now the IP was re-used in a
   MIPS automotive SoC called MobilEyeq5, so it has been split
   in pin control and GPIO drivers so the latter can be reused
   by MobilEyeq5. (Along with a long list of cleanups.)
 
 - A lot of overall cleanup and tidying up.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEElDRnuGcz/wPCXQWMQRCzN7AZXXMFAmXyJa8ACgkQQRCzN7AZ
 XXMQQw//aq+HJt4vtX4s9v+g/aYBDoasxOgryz96/yq+CqTBBiYh0ib7MJvy/rFs
 bBufH4DEvlpjzgsvaN14L6H+3hFDXKeN6VnAs3DPeBkda4bTS3VOpqNzSoOTeqG9
 4a1jTe3SHche80SNW1YskTAMT0lG6WqC4RvipQ8K14DqIioX0AmgF7nJ1cddKaTK
 tXCWkqKY3TW2Z4edi9ZJLL6vRSQ9tJP9AugjkPX3F91yqwGHb8PV7Ggb1EXzC/X0
 SW7F7Ke0lIvCYidDUpr04TOKdPTmzl2j6zoZfGU1WbypxG0LVhTKAMVk2DL2/v7T
 E8NNimVtGJtqxDfCVSbLc6jRgdYaLRa4dLhMCRWmevfEqFfrA79XFY6BS084T3oP
 619RqbOtxc21AzlJjy2Kp7v3YpmXi6pX5E23L/d8U+0poEiM5qPqdYZaTbGNcGsV
 Yg4xCtxtBfPUdE3SqUCbHDzpWdSDGFsT3LSAUionvYyoW4iF8AXg8SBV1QpfzLM8
 KTWTmsWG/15lCZyf7tq83EJjjVgYhGL4SMnkE8fT+smiXm95Muj1tzUjgapspMiU
 VpnhwtKj1hQrButWlN7+HXKseMrJ8zQJszcP5e3QdWOm7vzZGP3nXpgWosqGCImq
 ThjtyOKvc4+/AqgbIojDCz2BfxD8a7OPOkYHkLGJ96fA5JscBoU=
 =Pt9Y
 -----END PGP SIGNATURE-----

Merge tag 'pinctrl-v6.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl

Pull pin control updates from Linus Walleij:
 "No core changes this time around.

  New drivers:

   - New driver for Renesas R8A779H0 also known as R-Car V4M.

   - New driver for the Awinic AW9523/B I2C GPIO expander. I found this
     living out-of-tree in OpenWrt as an upstream attempt had stalled on
     the finishing line, so I picked it up and finished the job.

  Improvements:

   - The Nomadik pin control driver was for years re-used out of tree
     for the ST STA chips, and now the IP was re-used in a MIPS
     automotive SoC called MobilEyeq5, so it has been split in pin
     control and GPIO drivers so the latter can be reused by MobilEyeq5.
     (Along with a long list of cleanups)

   - A lot of overall cleanup and tidying up"

* tag 'pinctrl-v6.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl: (87 commits)
  drivers/gpio/nomadik: move dummy nmk_gpio_dbg_show_one() to header
  gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip()
  dt-bindings: pinctrl: qcom: update compatible name for match with driver
  pinctrl: aw9523: Make the driver tristate
  pinctrl: nomadik: fix dereference of error pointer
  gpio: nomadik: Back out some managed resources
  pinctrl: aw9523: Add proper terminator
  pinctrl: core: comment that pinctrl_add_gpio_range() is deprecated
  pinctrl: pinmux: Suppress error message for -EPROBE_DEFER
  pinctrl: Add driver for Awinic AW9523/B I2C GPIO Expander
  dt-bindings: pinctrl: Add bindings for Awinic AW9523/AW9523B
  gpio: nomadik: Finish conversion to use firmware node APIs
  gpio: nomadik: fix Kconfig dependencies inbetween pinctrl & GPIO
  pinctrl: da9062: Add OF table
  dt-bindings: pinctrl: at91: add sam9x7
  pinctrl: ocelot: remove redundant assignment to variable ret
  gpio: nomadik: grab optional reset control and deassert it at probe
  gpio: nomadik: support mobileye,eyeq5-gpio
  gpio: nomadik: handle variadic GPIO count
  gpio: nomadik: support shared GPIO IRQs
  ...
2024-03-14 10:22:26 -07:00
Linus Torvalds
69afef4af4 gpio updates for v6.9
Serialization rework:
 - use SRCU to serialize access to the global GPIO device list, to GPIO device
   structs themselves and to GPIO descriptors
 - make the GPIO subsystem resilient to the GPIO providers being unbound while
   the API calls are in progress
 - don't dereference the SRCU-protected chip pointer if the information we need
   can be obtained from the GPIO device structure
 - move some of the information contained in struct gpio_chip to struct
   gpio_device to further reduce the need to dereference the former
 - pass the GPIO device struct instead of the GPIO chip to sysfs callback to,
   again, reduce the need for accessing the latter
 - get GPIO descriptors from the GPIO device, not from the chip for the same
   reason
 - allow for mostly lockless operation of the GPIO driver API: assure
   consistency with SRCU and atomic operations
 - remove the global GPIO spinlock
 - remove the character device RW semaphore
 
 Core GPIOLIB:
 - constify pointers in GPIO API where applicable
 - unify the GPIO counting APIs for ACPI and OF
 - provide a macro for iterating over all GPIOs, not only the ones that are
   requested
 - remove leftover typedefs
 - pass the consumer device to GPIO core in devm_fwnode_gpiod_get_index() for
   improved logging
 - constify the GPIO bus type
 - don't warn about removing GPIO chips with descriptors still held by users as
   we can now handle this situation gracefully
 - remove unused logging helpers
 - unexport functions that are only used internally in the GPIO subsystem
 - set the device type (assign the relevant struct device_type) for GPIO devices
 
 New drivers:
 - add the ChromeOS EC GPIO driver
 
 Driver improvements:
 - allow building gpio-vf610 with COMPILE_TEST as well as disabling it in
   menuconfig (before it was always built for i.MX cofigs)
 - count the number of EICs using the device properties instead of hard-coding
   it in gpio-eic-sprd
 - improve the device naming, extend the debugfs output and add lockdep asserts
   to gpio-sim
 
 DT bindings:
 - document the 'label' property for gpio-pca9570
 - convert aspeed,ast2400-gpio bindings to DT schema
 - disallow unevaluated properties for gpio-mvebu
 - document a new model in renesas,rcar-gpio
 
 Documentation:
 - improve the character device kerneldocs in user-space headers
 - add proper documentation for the character device uAPI (both v1 and v2)
 - move the sysfs and gpio-mockup docs into the "obsolete" section
 - improve naming consistency for GPIO terms
 - clarify the line values description for sysfs
 - minor docs improvements
 - improve the driver API contract for setting GPIO direction
 - mark unsafe APIs as deprecated in kerneldocs and suggest replacements
 
 Other:
 - remove an obsolete test from selftests
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEFp3rbAvDxGAT0sefEacuoBRx13IFAmXu1ecACgkQEacuoBRx
 13JR7w//R3TswZ1uC9qkRjat9eA2KZUaI2QChlS7V/yXVcDHynuTlO/ZQmnnMdYL
 ch7T2cjPcW0OCt0UhcjamUmYtWaxe1e5GU3E42EosWUsojEzgGs0iNKe0R4SHYzv
 whlkFqO8+8IctYhiMpAU1PzP9N4YBqypwgCrTqHIrYuhz3MbPQxtCMkr7g0LTo8u
 Z3K0D3Y0LuwISWNYYhA20Bwemn1fEHXJ9f3pTeNaGh2dGZek9k9xd0zWcCxwhaYD
 CBTBiZXf57TUTJ2u+JG+au1ghEmmvBPlMpza+fazypbcvsiQxdGvv5QH1bTwyt4B
 woGq+biLLvlwfJ8BT7+09uni7gUyNL3wWkixlx/8Slkyti4xWqgZQ3WnhwN8yS4Y
 DbkTtzH/PIsjr1dZw6rnGoXi80lBEaok7LeI0QhybopTXQI+CnIbE/RBhzly8Mf8
 1cAVFjrF2gPuaTuheakRBw4LOhegf4a485fadJVEUeEpeF7/p9rDQWAbgohYUnCE
 gHPwkTOJuOZp+BlsTOyspnqxWnDVMtCnmi+q1o7JvEgXqAtzU7+1gz/wDpfsHgHQ
 oze6V2JvD2R3JkHmdqcIzq5yNwk1rOguOY3saNiwSk95JY+A8vhAe/gVykklKDXX
 oX/DPwlVd/0OR+0HCQ3r0pXK8BSRQ9qm/nUZNnLB+Rts9K1peIU=
 =LX+L
 -----END PGP SIGNATURE-----

Merge tag 'gpio-updates-for-v6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio updates from Bartosz Golaszewski:
 "The biggest feature is the locking overhaul. Up until now the
  synchronization in the GPIO subsystem was broken. There was a single
  spinlock "protecting" multiple data structures but doing it wrong (as
  evidenced by several places where it would be released when a sleeping
  function was called and then reacquired without checking the protected
  state).

  We tried to use an RW semaphore before but the main issue with GPIO is
  that we have drivers implementing the interfaces in both sleeping and
  non-sleeping ways as well as user-facing interfaces that can be called
  both from process as well as atomic contexts. Both ends converge in
  the same code paths that can use neither spinlocks nor mutexes. The
  only reasonable way out is to use SRCU and go mostly lockless. To that
  end: we add several SRCU structs in relevant places and use them to
  assure consistency between API calls together with atomic reads and
  writes of GPIO descriptor flags where it makes sense.

  This code has spent several weeks in next and has received several
  fixes in the first week or two after which it stabilized nicely. The
  GPIO subsystem is now resilient to providers being suddenly unbound.
  We managed to also remove the existing character device RW semaphore
  and the obsolete global spinlock.

  Other than the locking rework we have one new driver (for Chromebook
  EC), much appreciated documentation improvements from Kent and the
  regular driver improvements, DT-bindings updates and GPIOLIB core
  tweaks.

  Serialization rework:
   - use SRCU to serialize access to the global GPIO device list, to
     GPIO device structs themselves and to GPIO descriptors
   - make the GPIO subsystem resilient to the GPIO providers being
     unbound while the API calls are in progress
   - don't dereference the SRCU-protected chip pointer if the
     information we need can be obtained from the GPIO device structure
   - move some of the information contained in struct gpio_chip to
     struct gpio_device to further reduce the need to dereference the
     former
   - pass the GPIO device struct instead of the GPIO chip to sysfs
     callback to, again, reduce the need for accessing the latter
   - get GPIO descriptors from the GPIO device, not from the chip for
     the same reason
   - allow for mostly lockless operation of the GPIO driver API: assure
     consistency with SRCU and atomic operations
   - remove the global GPIO spinlock
   - remove the character device RW semaphore

  Core GPIOLIB:
   - constify pointers in GPIO API where applicable
   - unify the GPIO counting APIs for ACPI and OF
   - provide a macro for iterating over all GPIOs, not only the ones
     that are requested
   - remove leftover typedefs
   - pass the consumer device to GPIO core in
     devm_fwnode_gpiod_get_index() for improved logging
   - constify the GPIO bus type
   - don't warn about removing GPIO chips with descriptors still held by
     users as we can now handle this situation gracefully
   - remove unused logging helpers
   - unexport functions that are only used internally in the GPIO
     subsystem
   - set the device type (assign the relevant struct device_type) for
     GPIO devices

  New drivers:
   - add the ChromeOS EC GPIO driver

  Driver improvements:
   - allow building gpio-vf610 with COMPILE_TEST as well as disabling it
     in menuconfig (before it was always built for i.MX cofigs)
   - count the number of EICs using the device properties instead of
     hard-coding it in gpio-eic-sprd
   - improve the device naming, extend the debugfs output and add
     lockdep asserts to gpio-sim

  DT bindings:
   - document the 'label' property for gpio-pca9570
   - convert aspeed,ast2400-gpio bindings to DT schema
   - disallow unevaluated properties for gpio-mvebu
   - document a new model in renesas,rcar-gpio

  Documentation:
   - improve the character device kerneldocs in user-space headers
   - add proper documentation for the character device uAPI (both v1 and v2)
   - move the sysfs and gpio-mockup docs into the "obsolete" section
   - improve naming consistency for GPIO terms
   - clarify the line values description for sysfs
   - minor docs improvements
   - improve the driver API contract for setting GPIO direction
   - mark unsafe APIs as deprecated in kerneldocs and suggest
     replacements

  Other:
   - remove an obsolete test from selftests"

* tag 'gpio-updates-for-v6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (79 commits)
  gpio: sysfs: repair export returning -EPERM on 1st attempt
  selftest: gpio: remove obsolete gpio-mockup test
  gpiolib: Deduplicate cleanup for-loop in gpiochip_add_data_with_key()
  dt-bindings: gpio: aspeed,ast2400-gpio: Convert to DT schema
  gpio: acpi: Make acpi_gpio_count() take firmware node as a parameter
  gpio: of: Make of_gpio_get_count() take firmware node as a parameter
  gpiolib: Pass consumer device through to core in devm_fwnode_gpiod_get_index()
  gpio: sim: use for_each_hwgpio()
  gpio: provide for_each_hwgpio()
  gpio: don't warn about removing GPIO chips with active users anymore
  gpio: sim: delimit the fwnode name with a ":" when generating labels
  gpio: sim: add lockdep asserts
  gpio: Add ChromeOS EC GPIO driver
  gpio: constify of_phandle_args in of_find_gpio_device_by_xlate()
  gpio: fix memory leak in gpiod_request_commit()
  gpio: constify opaque pointer "data" in gpio_device_find()
  gpio: cdev: fix a NULL-pointer dereference with DEBUG enabled
  gpio: uapi: clarify default_values being logical
  gpio: sysfs: fix inverted pointer logic
  gpio: don't let lockdep complain about inherently dangerous RCU usage
  ...
2024-03-13 11:14:55 -07:00
Linus Torvalds
aeb152910a pwm: Changes for v6.9-rc1
This contains the usual amount of driver and device tree changes.
 Additionally there is a big rework of how pwm lowlevel drivers are
 registered to prepare adding character device support.
 
 Thanks to Dharma Balasubiramani, Dong Aisheng, Duje Mihanović, Jerome
 Brunet, Raag Jadav and Rafał Miłecki for their contributions. And sorry
 for those who still need some patience because I didn't manage to empty
 my review queue.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmXuyf4ACgkQj4D7WH0S
 /k4Yugf+P7gMPuCQJqWLvOyuHjKt4tI3aVsr+jbSiAfbPWaXAQKZunnZ9K17bOI2
 JQkDuAi76teNRiVtNEx1ZEdfKe9KgY/Npq8BTmvXxvBktCand8sfhyyRaXYo9FWI
 B5qKdp1WIg7ZDMoGQtLRayly4FAsbB0L50SjWmkVIXC2xXp6t6KxxgnOgTM58Oo9
 0yYYetF3EOmDQ4J234/muaLbM+1rjajKdw+SgS2mry2WV60SOqo+PQfuK42XjWip
 cLDkEgYogwx1MAbFgobtquA7Hvkdb2WyCirTDNZiGIBtmM89kH4Oa8e4IDR6FRqn
 w35hJv7sxVjiqBrSMD/lWpJeQ8gPYg==
 =6Ixv
 -----END PGP SIGNATURE-----

Merge tag 'pwm/for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux

Pull pwm updates from Uwe Kleine-König:
 "This contains the usual amount of driver and device tree changes.
  Additionally there is a big rework of how pwm lowlevel drivers are
  registered to prepare adding character device support.

  Thanks to Dharma Balasubiramani, Dong Aisheng, Duje Mihanović, Jerome
  Brunet, Raag Jadav and Rafał Miłecki for their contributions. And
  sorry for those who still need some patience because I didn't manage
  to empty my review queue"

* tag 'pwm/for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux: (185 commits)
  pwm: imx-tpm: fix probe crash due to access registers without clock
  pwm: meson: generalize 4 inputs clock on meson8 pwm type
  dt-bindings: pwm: amlogic: Add a new binding for meson8 pwm types
  dt-bindings: pwm: amlogic: fix s4 bindings
  pwm: dwc: simplify error handling
  pwm: dwc: Add 16 channel support for Intel Elkhart Lake
  pwm: dwc: drop redundant error check
  staging: greybus: pwm: Make use of devm_pwmchip_alloc() function
  staging: greybus: pwm: Rework how the number of PWM lines is determined
  staging: greybus: pwm: Drop unused gb_connection_set_data()
  staging: greybus: pwm: Rely on pwm framework to pass a valid hwpwm
  staging: greybus: pwm: Make use of pwmchip_parent() accessor
  staging: greybus: pwm: Change prototype of helpers to prepare further changes
  leds: qcom-lpg: Make use of devm_pwmchip_alloc() function
  drm/bridge: ti-sn65dsi86: Make use of devm_pwmchip_alloc() function
  drm/bridge: ti-sn65dsi86: Make use of pwmchip_parent() accessor
  gpio: mvebu: Make use of devm_pwmchip_alloc() function
  pwm: xilinx: Make use of devm_pwmchip_alloc() function
  pwm: xilinx: Prepare removing pwm_chip from driver data
  pwm: vt8500: Make use of devm_pwmchip_alloc() function
  ...
2024-03-13 10:51:39 -07:00
Max Kellermann
fa63587f94 drivers/gpio/nomadik: move dummy nmk_gpio_dbg_show_one() to header
When `CONFIG_DEBUG_FS` is disabled, nmk_gpio_dbg_show_one() is an
empty dummy function; this however triggers a `-Wmissing-prototypes`
warning and later a linker error because the function is also used by
drivers/pinctrl/nomadik/pinctrl-nomadik.c, therefore it needs to be
non-static.

To allow both sources to access this dummy function, this patch moves
it to the header, adding the `#ifdef CONFIG_DEBUG_FS` there as well.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Link: https://lore.kernel.org/r/20240311133223.3429428-1-max.kellermann@ionos.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-03-12 12:53:35 +01:00
Dan Carpenter
289b950b8e gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip()
Using BUG_ON() is discouraged and also the check wasn't done early
enough to prevent an out of bounds access.  Check earlier and return
an error instead of calling BUG().

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/ae643df0-3a3e-4270-8dbf-be390ee4b478@moroto.mountain
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-03-12 12:53:33 +01:00
Alexander Sverdlin
8636f19c2d gpio: sysfs: repair export returning -EPERM on 1st attempt
It would make sense to return -EPERM if the bit was already set (already
used), not if it was cleared. Before this fix pins can only be exported on
the 2nd attempt:

$ echo 522 > /sys/class/gpio/export
sh: write error: Operation not permitted
$ echo 522 > /sys/class/gpio/export

Fixes: 35b545332b ("gpio: remove gpio_lock")
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-08 10:32:00 +01:00
Linus Walleij
5545d5013c gpio: nomadik: Back out some managed resources
Several commits introduce managed resources (devm_*) into the
nmk_gpio_populate_chip() function.

This isn't always working because when called from the Nomadik pin
control driver we just want to populate some states for the device as
the same states are used by the pin control driver.

Some managed resources such as devm_kzalloc() etc will work, as the
passed in platform device will be used for lifecycle management,
but in some cases where we used the looked-up platform device
for the GPIO block, this will cause problems for the combined
pin control and GPIO driver, because it adds managed resources
to the GPIO device before it is probed, which is something that
the device core will not accept, and all of the GPIO blocks will
refuse to probe:

platform 8012e000.gpio: Resources present before probing
platform 8012e080.gpio: Resources present before probing
(...)

Fix this by not tying any managed resources to the looked-up
gpio_pdev/gpio_dev device, let's just live with the fact that
these need imperative resource management for now.

Drop in some notes and use a local *dev variable to clarify the
code.

Cc: Théo Lebrun <theo.lebrun@bootlin.com>
Fixes: 12410e9590 ("gpio: nomadik: use devm_platform_ioremap_resource() helper")
Link: https://lore.kernel.org/r/20240305-fix-nomadik-gpio-v2-1-e5d1fbdc3f5c@linaro.org
[Fixed some last minut print formatting]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-03-06 20:45:20 +01:00
Andy Shevchenko
8ae438f5ff gpiolib: Deduplicate cleanup for-loop in gpiochip_add_data_with_key()
There is no need to repeat for-loop twice in the error path in
gpiochip_add_data_with_key(). Deduplicate it. While at it,
rename loop variable to be more specific and avoid ambguity.

It also properly unwinds the SRCU, i.e. in reversed order of allocating.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-05 19:24:58 +01:00
Bartosz Golaszewski
e9c717bee8 Linux 6.8-rc7
-----BEGIN PGP SIGNATURE-----
 
 iQFSBAABCAA8FiEEq68RxlopcLEwq+PEeb4+QwBBGIYFAmXk5XweHHRvcnZhbGRz
 QGxpbnV4LWZvdW5kYXRpb24ub3JnAAoJEHm+PkMAQRiGV7UH/3I5Dt0YoqFYPnTx
 yE06EJVFupqd7nDTDtduynRuMWscOmxZyYdGz8erz1fdzcFDJvlvhYwGviIRleCb
 SH89noxq7vNRsQv1QzQAe8PA3AfgGlMDtDlC/lfQyk56oCtMw3QcfwA7j/+mwCrK
 rIBi1gMlkbEzE1Tj9qAnpmJv4uyyKEvKdMwWtNy6wQWsBN2PZJXyp9LXaaqRGoPF
 B40lJHAXL7R1OpHrhIvUyC6N7BssP0ychVqNO+r4F3kPBOiqfdR1a5LoVHjsGNU3
 qC7lBaUGxBetxHRzYSq0coHDkVSlQ3DlmoMMFWt3jK/Cu1KrFoT2GKtsHHrmOc4V
 5TPEl/o=
 =0vJs
 -----END PGP SIGNATURE-----

Merge tag 'v6.8-rc7' into gpio/for-next

Linux 6.8-rc7
2024-03-05 19:24:34 +01:00
Andy Shevchenko
caddc92c57 gpio: nomadik: Finish conversion to use firmware node APIs
Previously driver got a few updates in order to replace OF APIs by
respective firmware node, however it was not finished to the logical
end, e.g., some APIs that has been used are still require OF node
to be passed. Finish that job by converting leftovers to use firmware
node APIs.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20240302173401.217830-1-andy.shevchenko@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-03-03 09:43:10 +01:00
Théo Lebrun
b824f841a4 gpio: nomadik: fix Kconfig dependencies inbetween pinctrl & GPIO
PINCTRL_NOMADIK cannot select GPIO_NOMADIK without first selecting
GPIOLIB on which GPIO_NOMADIK depends. GPIO_NOMADIK depends on OF_GPIO,
it is a direct dependency.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202403010917.pnDhdS1Y-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202403011102.v8w2zPOU-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202403011329.1VnABMRz-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202403011546.Hpt8sBTa-lkp@intel.com/
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240301-mbly-gpio-kconfig-fix-v1-1-2785cebd475d@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-03-01 14:30:28 +01:00
Bartosz Golaszewski
ec5c54a9d3 gpio: fix resource unwinding order in error path
Hogs are added *after* ACPI so should be removed *before* in error path.

Fixes: a411e81e61 ("gpiolib: add hogs support for machine code")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2024-03-01 09:33:30 +01:00
Andy Shevchenko
8122c7c625 gpio: acpi: Make acpi_gpio_count() take firmware node as a parameter
Make acpi_gpio_count() take firmware node as a parameter in order
to be aligned with other functions and decouple from unused device
pointer. The latter helps to create a common fwnode_gpio_count()
in the future.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-01 09:08:34 +01:00
Andy Shevchenko
adcad5364a gpio: of: Make of_gpio_get_count() take firmware node as a parameter
Make of_gpio_get_count() take firmware node as a parameter in order
to be aligned with other functions and decouple from unused device
pointer. The latter helps to create a common fwnode_gpio_count()
in the future.

While at it, rename to be of_gpio_count() to be aligned with the others.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-01 09:07:21 +01:00
Andy Shevchenko
e4aec4daa8 gpiolib: Fix the error path order in gpiochip_add_data_with_key()
After shuffling the code, error path wasn't updated correctly.
Fix it here.

Fixes: 2f4133bb5f ("gpiolib: No need to call gpiochip_remove_pin_ranges() twice")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-01 08:36:53 +01:00
Arturas Moskvinas
530b1dbd97 gpio: 74x164: Enable output pins after registers are reset
Chip outputs are enabled[1] before actual reset is performed[2] which might
cause pin output value to flip flop if previous pin value was set to 1.
Fix that behavior by making sure chip is fully reset before all outputs are
enabled.

Flip-flop can be noticed when module is removed and inserted again and one of
the pins was changed to 1 before removal. 100 microsecond flipping is
noticeable on oscilloscope (100khz SPI bus).

For a properly reset chip - output is enabled around 100 microseconds (on 100khz
SPI bus) later during probing process hence should be irrelevant behavioral
change.

Fixes: 7ebc194d0f (gpio: 74x164: Introduce 'enable-gpios' property)
Link: https://elixir.bootlin.com/linux/v6.7.4/source/drivers/gpio/gpio-74x164.c#L130 [1]
Link: https://elixir.bootlin.com/linux/v6.7.4/source/drivers/gpio/gpio-74x164.c#L150 [2]
Signed-off-by: Arturas Moskvinas <arturas.moskvinas@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-01 08:23:08 +01:00
Théo Lebrun
6ad679cfae gpio: nomadik: grab optional reset control and deassert it at probe
Fetch a reference to the optional shared reset control and deassert it
if it exists.

Optional because not all platforms that use this driver have a reset
attached to the reset block. Shared because some platforms that use the
reset (at least Mobileye EyeQ5) share the reset across banks.

Do not keep a reference to the reset control as it is not needed
afterwards; the driver does not handle suspend, does not use runtime
PM, does not register a remove callback and does not support unbinding
from sysfs (made explicit with suppress_bind_attrs).

The operation is done in nmk_gpio_populate_chip(). This function is
called by either gpio-nomadik or pinctrl-nomadik, whoever comes first.
This is here for historic reasons and could probably be removed now; it
seems gpio-ranges enforces the ordering to be pinctrl-first. It is not
the topic of the present patch however.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-25-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:38:31 +01:00
Théo Lebrun
3c30cc26df gpio: nomadik: support mobileye,eyeq5-gpio
We create a custom compatible for the STA2X11 IP block as integrated
into the Mobileye EyeQ5 platform. Its wake and alternate functions have
been disabled, we want to avoid touching those registers.

We both do: (1) early return in functions that do not support the
platform, but with warnings, and (2) avoid calling those functions in
the first place.

We ensure that pinctrl-nomadik is not used with this STA2X11 variant.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-24-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:36:55 +01:00
Théo Lebrun
50bc2a4953 gpio: nomadik: handle variadic GPIO count
Read the "ngpios" property to determine the number of GPIOs for a bank.
If not available, fallback to NMK_GPIO_PER_CHIP ie 32 ie the current
behavior.

The IP block always supports 32 GPIOs, but platforms can expose a lesser
amount. The Mobileye EyeQ5 is in this case; one bank is 29 GPIOs and
the other is 23.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-23-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:36:20 +01:00
Théo Lebrun
8d74c3dc8f gpio: nomadik: support shared GPIO IRQs
Support a single IRQs used by multiple GPIO banks. Change the IRQ
handler type from a chained handler (as used by gpiolib
for ->parent_handler) to a threaded IRQ.

Use the generic_handle_domain_irq_safe() helper. The non-safe version
must be called in a no-IRQ context.

The Mobileye EyeQ5 platform uses this GPIO controller and share an IRQ
for its two banks.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-22-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:35:37 +01:00
Théo Lebrun
98c031faa6 gpio: nomadik: change driver name from gpio to nomadik-gpio
This GPIO driver is historically related to the Nomadik platform. It
however can be used by others as it implements the ST STA2X11 IP block.
Pick a less ambiguous name for it.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-21-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:35:20 +01:00
Théo Lebrun
eac86aaed7 gpio: nomadik: make clock optional
Not all platforms using this platform driver expose a clock for this
GPIO controller. Turn devm_clk_get() into devm_clk_get_optional() to
avoid failing when no clocks are provided.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-20-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:33:16 +01:00
Théo Lebrun
75d270fda6 gpio: nomadik: request dynamic ID allocation
Move away from statically allocated GPIO IDs. Switch to dynamic ID
allocation. Static IDs are deprecated because they cause issues when
multiple GPIO controllers are to be found on the same platform.

Add a bit of complexity to do pin number -> GPIO chip + offset.
Previously, bank number and offsets were retrieved using division and
remainder (bank size being constant 32). Now, to get the pin number
matching a bank base, we must know the sum of ngpios of previous banks.
This is done in find_nmk_gpio_from_pin() which also exposes the offset
inside the bank.

Also remove the assumption that bank sizes are constant. Instead of
using NMK_GPIO_PER_CHIP as bank size, use nmk_gpio_chips[i]->ngpio.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-19-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:32:39 +01:00
Théo Lebrun
2f8875ddd1 gpio: nomadik: use devres version of clk_get*()
Replace call to clk_get() by call to devm_clk_get(). Allow automatic
cleanup of the clock in case of probe error.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-18-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:31:27 +01:00
Théo Lebrun
12410e9590 gpio: nomadik: use devm_platform_ioremap_resource() helper
Replace calls to platform_get_resource() then devm_ioremap_resource() by
a single call to devm_platform_ioremap_resource().

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-17-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:30:53 +01:00
Théo Lebrun
be0552e1f4 gpio: nomadik: replace of_property_read_*() by device_property_read_*()
Avoid OF APIs in the GPIO subsystem. Here, replace
of_property_read_{u32,bool}() call by device_property_read_{u32,bool}().

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-16-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:30:15 +01:00
Théo Lebrun
0b95fcd1f4 gpio: nomadik: replace of_find_*() by bus_find_device_by_of_node()
Avoid OF APIs in the GPIO subsystem. Here, replace
of_find_device_by_node() call by bus_find_device_by_of_node().

The new helper returns a struct device pointer. Store it in a new local
variable and use it down the road.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-15-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:29:36 +01:00
Théo Lebrun
9b82653dee gpio: nomadik: add #include <linux/slab.h>
Add linux/slab.h header include for GFP flags.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-14-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:28:59 +01:00
Théo Lebrun
966942ae49 gpio: nomadik: extract GPIO platform driver from drivers/pinctrl/nomadik/
Previously, drivers/pinctrl/nomadik/pinctrl-nomadik.c registered two
platform drivers: pinctrl & GPIO. Move the GPIO aspect to the
drivers/gpio/ folder, as would be expected.

Both drivers are intertwined for a reason; pinctrl requires access to
GPIO registers for pinmuxing, pull-disable, disabling interrupts while
setting the muxing and wakeup control. Information sharing is done
through a shared array containing GPIO chips and a few helper
functions. That shared array is not touched from gpio-nomadik when
CONFIG_PINCTRL_NOMADIK is not defined.

Make no change to the code that moved into gpio-nomadik; there should be
no behavior change following. A few functions are shared and header
comments are added. Checkpatch warnings are addressed. NUM_BANKS is
renamed to NMK_MAX_BANKS.

It is supported to compile gpio-nomadik without pinctrl-nomadik. The
opposite is not true.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-6-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-29 10:22:33 +01:00
Stephen Boyd
0d776cfd5e gpiolib: Pass consumer device through to core in devm_fwnode_gpiod_get_index()
This devm API takes a consumer device as an argument to setup the devm
action, but throws it away when calling further into gpiolib. This leads
to odd debug messages like this:

 (NULL device *): using DT '/gpio-keys/switch-pen-insert' for '(null)' GPIO lookup

Let's pass the consumer device down, by directly calling what
fwnode_gpiod_get_index() calls but pass the device used for devm. This
changes the message to look like this instead:

 gpio-keys gpio-keys: using DT '/gpio-keys/switch-pen-insert' for '(null)' GPIO lookup

Note that callers of fwnode_gpiod_get_index() will still see the NULL
device pointer debug message, but there's not much we can do about that
because the API doesn't take a struct device.

Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Fixes: 8eb1f71e7a ("gpiolib: consolidate GPIO lookups")
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-27 14:17:38 +01:00
Bartosz Golaszewski
ebb03f692f gpio: sim: use for_each_hwgpio()
Display debugfs information about all simulated GPIOs, not only the
requested ones.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-26 16:43:51 +01:00
Bartosz Golaszewski
5d60c1e61f gpio: don't warn about removing GPIO chips with active users anymore
With SRCU we can now correctly handle the situation when a GPIO provider
is removed while having users still holding references to GPIO
descriptors. Remove all warnings emitted in this situation.

Suggested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Herve Codina <herve.codina@bootlin.com>
2024-02-26 16:43:51 +01:00
Bartosz Golaszewski
840a97e2fb gpio: sim: delimit the fwnode name with a ":" when generating labels
Typically, whenever a human-readable name is created for objects using
a software node, its name is delimited with ":" as dashes are often used
in other parts of the name. Make gpio-sim use the same pattern. This
results in better looking default names:

  gpio-sim.0:node0
  gpio-sim.0:node1
  gpio-sim.1:node0

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
2024-02-26 16:43:51 +01:00
Bartosz Golaszewski
11498d9900 gpio: sim: add lockdep asserts
We have three functions in gpio-sim that are called with the device lock
already held. We use the "_unlocked" suffix in their names to indicate
that. This has proven to be confusing though as the naming convention in
the kernel varies between using "_locked" or "_unlocked" for this
purpose. Naming convention also doesn't enforce anything. Let's remove
the suffix and add lockdep annotation at the top of these functions.

This makes it clear the function requires a lock to be held (and which
one specifically!) as well as results in a warning if it's not the case.
The only place where the information is lost is the place where the
function is called but the caller doesn't care about that information
anyway.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-26 16:43:51 +01:00
Stephen Boyd
f837fe1bff gpio: Add ChromeOS EC GPIO driver
The ChromeOS embedded controller (EC) supports setting the state of
GPIOs when the system is unlocked, and getting the state of GPIOs in all
cases. The GPIOs are on the EC itself, so the EC acts similar to a GPIO
expander. Add a driver to get and set the GPIOs on the EC through the
host command interface.

Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-26 14:37:50 +01:00
Uwe Kleine-König
7ae57b104d gpio: mvebu: Make use of devm_pwmchip_alloc() function
This prepares the pwm sub-driver to further changes of the pwm core
outlined in the commit introducing devm_pwmchip_alloc(). There is no
intended semantical change and the driver should behave as before.

Acked-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/2edc3adbb2c40b76b3b3dac82de82f3036bec1d5.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
2024-02-22 14:39:28 +01:00
Emil Renner Berthing
ae366ba857 gpiolib: Handle no pin_ranges in gpiochip_generic_config()
Similar to gpiochip_generic_request() and gpiochip_generic_free() the
gpiochip_generic_config() function needs to handle the case where there
are no pinctrl pins mapped to the GPIOs, usually through the gpio-ranges
device tree property.

Commit f34fd6ee1b ("gpio: dwapb: Use generic request, free and
set_config") set the .set_config callback to gpiochip_generic_config()
in the dwapb GPIO driver so the GPIO API can set pinctrl configuration
for the corresponding pins. Most boards using the dwapb driver do not
set the gpio-ranges device tree property though, and in this case
gpiochip_generic_config() would return -EPROPE_DEFER rather than the
previous -ENOTSUPP return value. This in turn makes
gpio_set_config_with_argument_optional() fail and propagate the error to
any driver requesting GPIOs.

Fixes: 2956b5d94a ("pinctrl / gpio: Introduce .set_config() callback for GPIO chips")
Reported-by: Jisheng Zhang <jszhang@kernel.org>
Closes: https://lore.kernel.org/linux-gpio/ZdC_g3U4l0CJIWzh@xhacker/
Tested-by: Jisheng Zhang <jszhang@kernel.org>
Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-20 12:49:14 +01:00
Krzysztof Kozlowski
ee9d589567 gpio: constify of_phandle_args in of_find_gpio_device_by_xlate()
Pointer to the struct of_phandle_args can be made const after
gpio_device_find() arguments got constified.  This should be part of
commit 4a92857d6e ("gpio: constify opaque pointer "data" in
gpio_device_find()").

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-20 12:44:49 +01:00
Xiaolei Wang
24ba441d2b gpio: fix memory leak in gpiod_request_commit()
Since commit 1f2bcb8c8c ("gpio: protect the descriptor label with
SRCU"), desc_set_label() already allocates memory for the label, so there
is no need to allocate it again. If we do, we leak it.

unreferenced object 0xffff0000c3e4d0c0 (size 32):
  comm "kworker/u16:4", pid 60, jiffies 4294894555
  hex dump (first 32 bytes):
    72 65 67 75 6c 61 74 6f 72 2d 63 61 6e 32 2d 73  regulator-can2-s
    74 62 79 00 00 00 ff ff ff ff ff ff eb db ff ff  tby.............
  backtrace (crc 2c3a0350):
    [<00000000e93c5cf4>] kmemleak_alloc+0x34/0x40
    [<0000000097a2657f>] __kmalloc_node_track_caller+0x2c4/0x524
    [<000000000dd1c057>] kstrdup+0x4c/0x98
    [<00000000b513a96a>] kstrdup_const+0x34/0x40
    [<000000008a7f0feb>] gpiod_request_commit+0xdc/0x358
    [<00000000fc71ad64>] gpiod_request+0xd8/0x204
    [<00000000fa24b091>] gpiod_find_and_request+0x170/0x780
    [<0000000086ecf92d>] gpiod_get_index+0x70/0xe0
    [<000000004aef97f9>] gpiod_get_optional+0x18/0x30
    [<00000000312f1b25>] reg_fixed_voltage_probe+0x58c/0xad8
    [<00000000e6f47635>] platform_probe+0xc4/0x198
    [<00000000cf78fbdb>] really_probe+0x204/0x5a8
    [<00000000e28d05ec>] __driver_probe_device+0x158/0x2c4
    [<00000000e4fe452b>] driver_probe_device+0x60/0x18c
    [<00000000479fcf5d>] __device_attach_driver+0x168/0x208
    [<000000007d389f38>] bus_for_each_drv+0x104/0x190

Fixes: 1f2bcb8c8c ("gpio: protect the descriptor label with SRCU")
Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-19 08:46:23 +01:00
Krzysztof Kozlowski
4a92857d6e gpio: constify opaque pointer "data" in gpio_device_find()
The opaque pointer "data" in each match function used by
gpio_device_find() is a pointer to const, thus the same argument passed
to gpio_device_find() can adjusted similarly.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-17 20:02:22 +01:00
Bartosz Golaszewski
91510d5959 gpio: cdev: fix a NULL-pointer dereference with DEBUG enabled
We are actually passing the gc pointer to chip_dbg() so we have to
srcu_dereference() it.

Fixes: 8574b5b476 ("gpio: cdev: use correct pointer accessors with SRCU")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Closes: https://lore.kernel.org/lkml/179caa10-5f86-4707-8bb0-fe1b316326d6@samsung.com/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
2024-02-16 14:20:07 +01:00
Bartosz Golaszewski
be91c19e47 gpio: sysfs: fix inverted pointer logic
The logic is inverted, we want to return if the chip *IS* NULL.

Fixes: d83cee3d2b ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-gpio/15671341-0b29-40e0-b487-0a4cdc414d8e@moroto.mountain/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-15 08:40:40 +01:00
Bartosz Golaszewski
0d7fa0eda4 gpio: don't let lockdep complain about inherently dangerous RCU usage
There are two legacy, deprecated functions - gpiod_to_chip() and
gpio_device_get_chip() - that still have users in tree. They return the
address of the SRCU-protected chip outside of the read-only critical
sections. They are inherently dangerous and the users should convert to
safer alternatives. Let's explicitly silence lockdep warnings by using
rcu_dereference_check(ptr, 1). While at it: reuse
gpio_device_get_chip() in gpiod_to_chip().

Fixes: d83cee3d2b ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-15 08:39:29 +01:00
Bartosz Golaszewski
d82b9e0887 gpio: use srcu_dereference() with SRCU-protected pointers
Lockdep with CONFIG_PROVE_RCU enabled reports false positives about
suspicious rcu_dereference() usage. Let's silence it by using
srcu_dereference() which is the correct helper with SRCU.

Fixes: d83cee3d2b ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
2024-02-15 08:39:25 +01:00
Bartosz Golaszewski
8574b5b476 gpio: cdev: use correct pointer accessors with SRCU
We never dereference the chip pointer in character device code so we can
use the lighter rcu_access_pointer() helper. This also makes lockep
happier as it no longer complains about suspicious rcu_dereference()
usage.

Fixes: d83cee3d2b ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
2024-02-15 08:39:18 +01:00