kernel_samsung_a53x/drivers/pinctrl
Evgenii Shatokhin bc815d14c5 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: 8f38910ba4f6 ("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-15 16:29:56 +01:00
..
actions Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
aspeed pinctrl: pinctrl-aspeed-g6: Fix register offset for pinconf of GPIOR-T 2024-11-19 11:32:41 +01:00
bcm Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
berlin Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cirrus pinctrl: lochnagar: Don't build on MIPS 2024-11-18 12:12:11 +01:00
freescale pinctrl: freescale: fix COMPILE_TEST error with PINCTRL_IMX_SCU 2024-12-17 13:24:31 +01:00
intel Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mediatek pinctrl: mediatek: paris: Rework support for PIN_CONFIG_{INPUT,OUTPUT}_ENABLE 2024-11-19 11:32:41 +01:00
meson pinctrl/meson: fix typo in PDM's pin name 2024-11-19 11:32:41 +01:00
mvebu Revert "pinctrl: mvebu: Use devm_platform_get_and_ioremap_resource()" 2024-11-24 00:23:21 +01:00
nomadik Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nuvoton Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pxa Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qcom pinctrl: qcom-pmic-gpio: add support for PM8937 2024-12-17 13:24:32 +01:00
renesas pinctrl: renesas: checker: Limit cfg reg enum checks to provided IDs 2024-11-19 09:23:14 +01:00
samsung Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sirf Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
spear Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sprd Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stm32 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sunxi Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tegra Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ti pinctrl: ti: ti-iodelay: fix possible memory leak when pinctrl_enable() fails 2024-11-23 23:20:11 +01:00
uniphier Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
visconti Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vt8500 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
zte Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
core.c pinctrl: core: fix possible memory leak when pinctrl_enable() fails 2024-11-23 23:20:11 +01:00
core.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
devicetree.c pinctrl: devicetree: fix refcount leak in pinctrl_dt_to_map() 2024-11-19 11:32:42 +01:00
devicetree.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinconf-generic.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinconf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinconf.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-amd.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-amd.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-artpec6.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-as3722.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-at91-pio4.c pinctrl: at91-pio4: use dedicated lock class for IRQ 2024-11-18 12:11:59 +01:00
pinctrl-at91.c Revert "pinctrl: at91: make it work with current gpiolib" 2024-11-24 00:23:33 +01:00
pinctrl-at91.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-axp209.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-bm1880.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-coh901.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-coh901.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-da850-pupd.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-da9062.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-digicolor.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-equilibrium.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-equilibrium.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-falcon.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-gemini.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-ingenic.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-lantiq.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-lantiq.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-lpc18xx.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-max77620.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-mcp23s08.c pinctrl: mcp23s08: Fix sleeping in atomic context due to regmap locking 2025-01-15 16:29:56 +01:00
pinctrl-mcp23s08.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-mcp23s08_i2c.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-mcp23s08_spi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-ocelot.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-oxnas.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-palmas.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-pic32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-pic32.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-pistachio.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-rk805.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-rockchip.c Revert "pinctrl: rockchip: correct RK3328 iomux width flag for GPIO2-B pins" 2024-11-24 00:23:50 +01:00
pinctrl-rockchip.h pinctrl: rockchip: use dedicated pinctrl type for RK3328 2024-11-19 14:19:31 +01:00
pinctrl-samsung-s2mpm07.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-samsung-s2mps26.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-samsung-s2mpu13.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-samsung-s2mpu14.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-single.c Revert "pinctrl: single: fix potential NULL dereference in pcs_get_function()" 2024-11-24 00:23:50 +01:00
pinctrl-st.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-stmfx.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-sx150x.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-tb10x.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-u300.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-utils.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-utils.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-xway.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinctrl-zynq.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinmux.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pinmux.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00