android_kernel_motorola_sm6375/drivers/pinctrl
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Evgenii Shatokhin 788d9e9a41 pinctrl: mcp23s08: Fix sleeping in atomic context due to regmap locking
commit a37eecb705f33726f1fb7cd2a67e514a15dfe693 upstream.

If a device uses MCP23xxx IO expander to receive IRQs, the following
bug can happen:

  BUG: sleeping function called from invalid context
    at kernel/locking/mutex.c:283
  in_atomic(): 1, irqs_disabled(): 1, non_block: 0, ...
  preempt_count: 1, expected: 0
  ...
  Call Trace:
  ...
  __might_resched+0x104/0x10e
  __might_sleep+0x3e/0x62
  mutex_lock+0x20/0x4c
  regmap_lock_mutex+0x10/0x18
  regmap_update_bits_base+0x2c/0x66
  mcp23s08_irq_set_type+0x1ae/0x1d6
  __irq_set_trigger+0x56/0x172
  __setup_irq+0x1e6/0x646
  request_threaded_irq+0xb6/0x160
  ...

We observed the problem while experimenting with a touchscreen driver which
used MCP23017 IO expander (I2C).

The regmap in the pinctrl-mcp23s08 driver uses a mutex for protection from
concurrent accesses, which is the default for regmaps without .fast_io,
.disable_locking, etc.

mcp23s08_irq_set_type() calls regmap_update_bits_base(), and the latter
locks the mutex.

However, __setup_irq() locks desc->lock spinlock before calling these
functions. As a result, the system tries to lock the mutex whole holding
the spinlock.

It seems, the internal regmap locks are not needed in this driver at all.
mcp->lock seems to protect the regmap from concurrent accesses already,
except, probably, in mcp_pinconf_get/set.

mcp23s08_irq_set_type() and mcp23s08_irq_mask/unmask() are called under
chip_bus_lock(), which calls mcp23s08_irq_bus_lock(). The latter takes
mcp->lock and enables regmap caching, so that the potentially slow I2C
accesses are deferred until chip_bus_unlock().

The accesses to the regmap from mcp23s08_probe_one() do not need additional
locking.

In all remaining places where the regmap is accessed, except
mcp_pinconf_get/set(), the driver already takes mcp->lock.

This patch adds locking in mcp_pinconf_get/set() and disables internal
locking in the regmap config. Among other things, it fixes the sleeping
in atomic context described above.

Fixes: 8f38910ba4 ("pinctrl: mcp23s08: switch to regmap caching")
Cc: stable@vger.kernel.org
Signed-off-by: Evgenii Shatokhin <e.shatokhin@yadro.com>
Link: https://lore.kernel.org/20241209074659.1442898-1-e.shatokhin@yadro.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-01-09 13:23:37 +01:00
..
actions
aspeed
bcm
berlin
cirrus pinctrl: lochnagar: Don't build on MIPS 2024-01-25 14:34:19 -08:00
freescale pinctrl: freescale: mxs: Fix refcount of child 2024-08-19 05:33:34 +02:00
intel pinctrl: cherryview: Return correct value if pin in push-pull mode 2023-07-27 08:37:16 +02:00
mediatek pinctrl: mediatek: paris: Fix PIN_CONFIG_INPUT_SCHMITT_ENABLE readback 2024-05-17 11:43:56 +02:00
meson pinctrl: meson-axg: add missing GPIOA_18 gpio group 2023-06-14 10:59:58 +02:00
mvebu pinctrl: mvebu: Fix devinit_dove_pinctrl_probe function 2024-11-08 16:20:32 +01:00
nomadik
nuvoton
pxa
qcom pinctrl: qcom-pmic-gpio: add support for PM8937 2024-12-14 19:44:54 +01:00
samsung
sh-pfc
sirf
spear
sprd
stm32
sunxi
tegra
ti pinctrl: ti: ti-iodelay: fix possible memory leak when pinctrl_enable() fails 2024-08-19 05:33:34 +02:00
uniphier
vt8500
zte
core.c pinctrl: core: fix possible memory leak when pinctrl_enable() fails 2024-08-19 05:33:34 +02:00
core.h
devicetree.c pinctrl: devicetree: fix refcount leak in pinctrl_dt_to_map() 2024-05-17 11:43:48 +02:00
devicetree.h
Kconfig
Makefile
pinconf-generic.c
pinconf.c
pinconf.h
pinctrl-amd.c pinctrl: amd: Don't show Invalid config param errors 2023-09-23 10:59:37 +02:00
pinctrl-amd.h pinctrl: amd: Detect internal GPIO0 debounce handling 2023-07-27 08:37:34 +02:00
pinctrl-artpec6.c
pinctrl-as3722.c
pinctrl-at91-pio4.c pinctrl: at91-pio4: use dedicated lock class for IRQ 2024-01-08 11:29:45 +01:00
pinctrl-at91.c pinctrl: at91: make it work with current gpiolib 2024-11-08 16:20:25 +01:00
pinctrl-at91.h
pinctrl-axp209.c
pinctrl-bm1880.c
pinctrl-coh901.c
pinctrl-coh901.h
pinctrl-da850-pupd.c
pinctrl-digicolor.c
pinctrl-falcon.c
pinctrl-gemini.c
pinctrl-ingenic.c
pinctrl-lantiq.c
pinctrl-lantiq.h
pinctrl-lpc18xx.c
pinctrl-max77620.c
pinctrl-mcp23s08.c pinctrl: mcp23s08: Fix sleeping in atomic context due to regmap locking 2025-01-09 13:23:37 +01:00
pinctrl-ocelot.c pinctrl: ocelot: Fix alt mode for ocelot 2023-04-05 11:16:44 +02:00
pinctrl-oxnas.c
pinctrl-palmas.c
pinctrl-pic32.c
pinctrl-pic32.h
pinctrl-pistachio.c
pinctrl-rk805.c
pinctrl-rockchip.c pinctrl: rockchip: fix pinmux reset in rockchip_pmx_set 2024-07-05 09:08:26 +02:00
pinctrl-rza1.c
pinctrl-rza2.c pinctrl: renesas: rza2: Add lock around pinctrl_generic{{add,remove}_group,{add,remove}_function} 2023-08-30 16:27:28 +02:00
pinctrl-rzn1.c
pinctrl-single.c pinctrl: single: fix missing error code in pcs_probe() 2024-11-08 16:20:31 +01:00
pinctrl-st.c
pinctrl-stmfx.c
pinctrl-sx150x.c
pinctrl-tb10x.c
pinctrl-u300.c
pinctrl-utils.c
pinctrl-utils.h
pinctrl-xway.c
pinctrl-zynq.c
pinmux.c
pinmux.h