[PATCH 3/3] pinctrl: single: Reject bit-per-mux without a usable function mask
From: A. Sverdlin
Date: Thu Nov 19 2026 - 18:28:40 EST
From: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
With "pinctrl-single,bit-per-mux", the number of bits per pin is derived
from "pinctrl-single,function-mask" as fls(fmask). Neither the binding nor
pcs_probe() requires the mask to be present with bit-per-mux, or to fit
the register width:
- If the mask is missing or zero, bits_per_pin stays 0. Probe succeeds,
but parsing the first pin group divides by zero in
pcs_parse_bits_in_pinctrl_entry() and pcs_get_pin_by_offset(), and so
does reading the debugfs "pins" file via pcs_pin_shift_reg_get().
- If the mask is wider than the register, width / bits_per_pin is 0.
pcs_parse_bits_in_pinctrl_entry() then allocates zero-sized vals and
pins arrays and writes through the returned ZERO_SIZE_PTR, and
pcs_pin_shift_reg_get() takes a remainder modulo zero.
Both configurations pass dt-validate against the current binding.
Reject them in pcs_probe().
The patch was inspired by a sibling fix
("pinctrl: single: Reject invalid register width in pcs_probe()").
Link: https://lore.kernel.org/all/20261119205013.2563811-10-lee@xxxxxxxxxx/
Fixes: 4e7e8017a80e ("pinctrl: pinctrl-single: enhance to configure multiple pins of different modules")
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
---
drivers/pinctrl/pinctrl-single.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index f5f0b95dc4282..ba5782b6b63d0 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1860,6 +1860,14 @@ static int pcs_probe(struct platform_device *pdev)
pcs->bits_per_mux = of_property_read_bool(np,
"pinctrl-single,bit-per-mux");
+ if (pcs->bits_per_mux &&
+ (!pcs->fmask || fls(pcs->fmask) > pcs->width)) {
+ dev_err(pcs->dev, "invalid function mask 0x%x for bit-per-mux\n",
+ pcs->fmask);
+
+ return -EINVAL;
+ }
+
ret = pcs_quirk_missing_pinctrl_cells(pcs, np,
pcs->bits_per_mux ? 2 : 1);
if (ret) {
--
2.56.1