pinctrl: Fix out-of-bounds accesses, divide-by-zero, and error handling
Subsystems (13)
cover pinctrl: Fix out-of-bounds accesses, divide-by-zero, and error handling
These issues were reported by Sashiko.
Lee Jones (10):
pinctrl: sunxi: Fix out-of-bounds irq_bank index when first bank has
no IRQs
pinctrl: tegra186: Fix out-of-bounds register bank index for AON drive
groups
pinctrl: ingenic: Fix element type of x1600_sfc_funcs array
pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs
pinctrl: realtek: Prevent out-of-bounds access in
rtd_pinctrl_find_config()
pinctrl: realtek: Fix bit shift when configuring RTD_HIGH_VIL
pinctrl: realtek: Initialise omitted offset fields to NA in config
macros
pinctrl: mediatek: Clean up partially initialised hw->eint on error
pinctrl: mediatek: Prevent divide-by-zero for pins with fixed drive
strength
pinctrl: qcom: Check qcom_scm_io_readl() return value in
msm_gpio_irq_set_type()
drivers/pinctrl/mediatek/pinctrl-mt7981.c | 2 +- .../pinctrl/mediatek/pinctrl-mtk-common-v2.c | 24 ++++- drivers/pinctrl/pinctrl-ingenic.c | 2 +- drivers/pinctrl/qcom/pinctrl-msm.c | 10 +- drivers/pinctrl/realtek/pinctrl-rtd.c | 5 +- drivers/pinctrl/realtek/pinctrl-rtd.h | 5 + drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 11 +- drivers/pinctrl/tegra/pinctrl-tegra186.c | 102 +++++++++--------- 8 files changed, 93 insertions(+), 68 deletions(-)
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH 1/10 pinctrl: sunxi: Fix out-of-bounds irq_bank index when first bank has no IRQs
In prepare_function_table(), irq_bank and last_bank are initialised to 0 and last_bank is updated on every bank regardless of whether it supports interrupts. On SoCs where bank 0 (PA) has no pins or does not support interrupts (such as Allwinner A523 and A733), the first IRQ-capable bank has bank > 0, which causes irq_bank to be incremented to 1 instead of starting at 0. As a result, the final IRQ bank receives irq_bank equal to desc->irq_banks and writes out-of-bounds past pctl->irq_array during sunxi_pinctrl_build_state().
Initialise irq_bank and last_bank to -1 and only update last_bank when processing an IRQ-capable bank so that irq_bank always starts at 0 and increments sequentially across IRQ-capable banks.
--- drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +5 -6
@@ -208,8 +208,8 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,* Assign the function's memory and fill in GPIOs, IRQ and a sentinel. * The extra functions will be filled in later. */ - irq_bank =0 ; - last_bank =0 ; + irq_bank =-1 ; + last_bank =-1 ;for (i =0 ; i < npins; i++) {struct sunxi_desc_pin *pin = &pins[i];int bank = (pin->pin.number - pin_base) /PINS_PER_BANK ;
@@ -222,17 +222,16 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode, func[1 ].muxval =1 ;if (irq_mux) { -if (bank > last_bank) +if (bank > last_bank) { irq_bank++; + last_bank = bank; + } func[lastfunc].muxval = irq_mux; func[lastfunc].irqbank = irq_bank; func[lastfunc].irqnum = pin->pin.number %PINS_PER_BANK ; func[lastfunc].name ="irq" ; } -if (bank > last_bank) - last_bank = bank; - pin->functions = func;/* Skip over the other needed functions and the sentinel. */
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH 01/10] pinctrl: sunxi: Fix out-of-bounds irq_bank index when first bank has no IRQs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] pinctrl: sunxi: off-by-one IRQ bank mapping in prepare_function_table() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pinctrl: sunxi: off-by-one IRQ bank mapping in prepare_function_table() --
commit c76ce1661381ff598e234c433e51d5307fae79a4
Author: Lee Jones <[email protected]>
pinctrl: sunxi: Fix out-of-bounds irq_bank index when first bank has no IRQs
This commit initializes irq_bank and last_bank to -1 in prepare_function_table() and only updates last_bank on IRQ-capable banks so that irq_bank starts at 0 even when bank 0 (PA) has no pins or interrupts.
Quoted 22 lines
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +3
-3@@ -208,8 +208,8 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,* Assign the function's memory and fill in GPIOs, IRQ and a sentinel. * The extra functions will be filled in later. */ - irq_bank =0 ; - last_bank =0 ; + irq_bank =-1 ; + last_bank =-1 ;for (i =0 ; i < npins; i++) {struct sunxi_desc_pin *pin = &pins[i];int bank = (pin->pin.number - pin_base) /PINS_PER_BANK ;@@ -222,17 +222,16 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode, func[1 ].muxval =1 ;if (irq_mux) { -if (bank > last_bank) +if (bank > last_bank) { irq_bank++;
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c static int prepare_function_table(struct device *dev, struct device_node *pnode, · line 234
Quoted 10 lines
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +2
-2+ last_bank = bank; + } func[lastfunc].muxval = irq_mux; func[lastfunc].irqbank = irq_bank; func[lastfunc].irqnum = pin->pin.number %PINS_PER_BANK ; func[lastfunc].name ="irq" ; } -if (bank > last_bank) - last_bank = bank;
[Severity: High]
Won't assigning irqbank starting at 0 for Port B shift the hardware IRQ register offsets and GIC interrupt mappings off by one bank on Allwinner A523 and A733?
On Allwinner A523 and A733, Port A (bank 0) has 0 pins, while Ports B through K (banks 1 through 10) implement pins and interrupts. With this change, sunxi_pinctrl_dt_table_init() -> prepare_function_table() assigns func[lastfunc].irqbank = 0..9 to Ports B..K instead of 1..10.
However, as described in commits 11f25ac56372 ("dt-bindings: pinctrl:
sun55i-a523: increase IRQ banks number") and 6b81aa0c8a4f ("arm64: dts:
allwinner: a523: Add missing GPIO interrupt"), the hardware IRQ register layout and Device Tree interrupt numbering on A523 and A733 start at index 0 for the unimplemented Port A (RAZ/WI), with Ports B..K occupying hardware and DT indices 1..10.
On Allwinner A523, drivers/pinctrl/sunxi/pinctrl-sun55i-a523.c defines an identity bank map starting at 0:
static const unsigned int a523_irq_bank_map[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };When Ports B..K are given irqbank 0..9 without updating a523_pinctrl_data, sunxi_irq_base_reg() maps Port B (irqbank 0) via a523_irq_bank_map[0] = 0 to Port A's unimplemented IRQ registers at offset 0x200 instead of Port B's at 0x220, Port C (irqbank 1) to Port B's registers at 0x220, and so on through Port K (irqbank 9) accessing Port J's registers at 0x320, leaving Port K's registers at 0x340 unused.
Furthermore, arch/arm64/boot/dts/allwinner/sun55i-a523.dtsi and Documentation/devicetree/bindings/pinctrl/allwinner,sun55i-a523-pinctrl.yaml specify 11 GIC interrupts starting with Port A (GIC_SPI 67) at index 0, Port B (GIC_SPI 69) at index 1, through Port K (GIC_SPI 140) at index 10:
interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>,
...
<GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 140 IRQ_TYPE_LEVEL_HIGH>;Because sunxi_pinctrl_init_with_flags() populates
pctl->irq[i] = platform_get_irq(pdev, i) for i = 0 .. desc->irq_banks - 1, assigning irqbank 0..9 to Ports B..K pairs Port B with Port A's GIC_SPI 67 (pctl->irq[0]), Port C with Port B's GIC_SPI 69 (pctl->irq[1]), through Port K with Port J's GIC_SPI 85 (pctl->irq[9]), while index 10 (GIC_SPI 140 for Port K) is never requested.
Similarly, on Allwinner A733, drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c uses SUNXI_PINCTRL_NCAT3_REG_LAYOUT with no irq_bank_map:
static struct sunxi_pinctrl_desc a733_pinctrl_data = {
.irq_banks = 10,
.irq_read_needs_mux = true,
.io_bias_cfg_variant = BIAS_VOLTAGE_PIO_POW_MODE_SEL,
};In drivers/pinctrl/sunxi/pinctrl-sunxi.h, sunxi_irq_base_reg() computes the register offset directly from bank without calling sunxi_irq_hw_bank_num():
static inline u32 sunxi_irq_base_reg(const struct sunxi_pinctrl *pctl, u16 bank)
{
if (pctl->flags & SUNXI_PINCTRL_NCAT3_REG_LAYOUT)
return pctl->bank_offset + bank * pctl->bank_mem_size +
A733_IRQ_REGS_OFFSET;
return IRQ_REGS_OFFSET +
sunxi_irq_hw_bank_num(pctl->desc, bank) * IRQ_MEM_SIZE;
}Because pctl->bank_offset (0x80) is Port A's register base (IRQ-A at 0x0c0 for bank 0) and Port B's IRQ registers are at bank 1 (0x140), assigning irqbank 0..9 to Ports B..K shifts all A733 IRQ register accesses down by one bank to 0x0c0..0x540 (Ports A..J) instead of 0x140..0x5c0 (Ports B..K).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 01/10] pinctrl: sunxi: Fix out-of-bounds irq_bank index when first bank has no IRQs
In reply to Lee JonesHi Lee,
Quoted 9 lines · Lee Jones
In
prepare_function_table(),irq_bankandlast_bankare initialised to 0 andlast_bankis updated on every bank regardless of whether it supports interrupts. On SoCs where bank 0 (PA) has no pins or does not support interrupts (such as Allwinner A523 and A733), the first IRQ-capable bank has bank > 0, which causesirq_bankto be incremented to 1 instead of starting at 0. As a result, the final IRQ bank receivesirq_bankequal todesc->irq_banksand writes out-of-bounds pastpctl->irq_arrayduringsunxi_pinctrl_build_state().
Quoted 3 lines
Initialise
irq_bankandlast_bankto -1 and only updatelast_bankwhen processing an IRQ-capable bank so thatirq_bankalways starts at 0 and increments sequentially across IRQ-capable banks.
Can we please hold back this patch for now? There are more issues around the IRQ bank usage on recent Allwinner SoCs, patches for which [1] are on the list. They should solve the out-of-bounds access, I think, though we might want to add explicit checks, maybe.
But taking just this patch here would torpedo the efforts in fixing the correctness issues that we see.
Cheers,
Andre
[1]
https://lore.kernel.org/linux-gpio/[email protected]/
Quoted 45 lines
Fixes f5e2cd34b12f ("pinctrl: sunxi: allow reading mux values from DT")Signed-off-by Lee Jones <[email protected]>--- drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c +5
-6@@ -208,8 +208,8 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode,* Assign the function's memory and fill in GPIOs, IRQ and a sentinel. * The extra functions will be filled in later. */ - irq_bank =0 ; - last_bank =0 ; + irq_bank =-1 ; + last_bank =-1 ;for (i =0 ; i < npins; i++) {struct sunxi_desc_pin *pin = &pins[i];int bank = (pin->pin.number - pin_base) /PINS_PER_BANK ;@@ -222,17 +222,16 @@ static int prepare_function_table(struct device *dev, struct device_node *pnode, func[1 ].muxval =1 ;if (irq_mux) { -if (bank > last_bank) +if (bank > last_bank) { irq_bank++; + last_bank = bank; + } func[lastfunc].muxval = irq_mux; func[lastfunc].irqbank = irq_bank; func[lastfunc].irqnum = pin->pin.number %PINS_PER_BANK ; func[lastfunc].name ="irq" ; } -if (bank > last_bank) - last_bank = bank; - pin->functions = func;/* Skip over the other needed functions and the sentinel. */
Re: [PATCH 01/10] pinctrl: sunxi: Fix out-of-bounds irq_bank index when first bank has no IRQs
Quoted 16 lines · Andre Przywara
Hi Lee,
Quoted 9 lines · Lee Jones
In
prepare_function_table(),irq_bankandlast_bankare initialised to 0 andlast_bankis updated on every bank regardless of whether it supports interrupts. On SoCs where bank 0 (PA) has no pins or does not support interrupts (such as Allwinner A523 and A733), the first IRQ-capable bank has bank > 0, which causesirq_bankto be incremented to 1 instead of starting at 0. As a result, the final IRQ bank receivesirq_bankequal todesc->irq_banksand writes out-of-bounds pastpctl->irq_arrayduringsunxi_pinctrl_build_state().Quoted 3 lines
Initialise
irq_bankandlast_bankto -1 and only updatelast_bankwhen processing an IRQ-capable bank so thatirq_bankalways starts at 0 and increments sequentially across IRQ-capable banks.
Quoted 7 lines
Can we please hold back this patch for now? There are more issues around the IRQ bank usage on recent Allwinner SoCs, patches for which [1] are on the list. They should solve the out-of-bounds access, I think, though we might want to add explicit checks, maybe.
But taking just this patch here would torpedo the efforts in fixing the correctness issues that we see.
Sure, no problem.
Signature · 1 line
Lee Jones
PATCH 2/10 pinctrl: tegra186: Fix out-of-bounds register bank index for AON drive groups
In reply to Lee JonesThe Tegra186 AON pinmux controller has only a single register bank (nbanks = 1, indexed at 0), and all PINGROUP entries in tegra186_aon_groups accordingly specify bank 0. However, all 51 AON drive_* macro definitions pass drv_bank = 1 as the final argument to DRV_PINGROUP_ENTRY_Y, causing any drive configuration read or write on an AON drive group to index pmx->regs[1] out-of-bounds.
Update the AON drive_* macro definitions to use register bank 0.
--- drivers/pinctrl/tegra/pinctrl-tegra186.c | 102 +++++++++++------------ 1 file changed, 51 insertions(+), 51 deletions(-)
drivers/pinctrl/tegra/pinctrl-tegra186.c +51 -51
@@ -1585,57 +1585,57 @@ static const char * const tegra186_functions[] = {#define drive_qspi_comp DRV_PINGROUP_ENTRY_N(no_entry)/* AON drive pin groups */ -#define drive_touch_clk_pee2 DRV_PINGROUP_ENTRY_Y(0x2004, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_uart3_cts_pw5 DRV_PINGROUP_ENTRY_Y(0x200c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_uart3_rts_pw4 DRV_PINGROUP_ENTRY_Y(0x2014, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_uart3_rx_pw3 DRV_PINGROUP_ENTRY_Y(0x201c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_uart3_tx_pw2 DRV_PINGROUP_ENTRY_Y(0x2024, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gen8_i2c_sda_pw1 DRV_PINGROUP_ENTRY_Y(0x202c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gen8_i2c_scl_pw0 DRV_PINGROUP_ENTRY_Y(0x2034, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_uart7_rx_pw7 DRV_PINGROUP_ENTRY_Y(0x203c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_uart7_tx_pw6 DRV_PINGROUP_ENTRY_Y(0x2044, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen0_pv0 DRV_PINGROUP_ENTRY_Y(0x204c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen1_pv1 DRV_PINGROUP_ENTRY_Y(0x2054, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen2_pv2 DRV_PINGROUP_ENTRY_Y(0x205c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen3_pv3 DRV_PINGROUP_ENTRY_Y(0x2064, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen4_pv4 DRV_PINGROUP_ENTRY_Y(0x206c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen5_pv5 DRV_PINGROUP_ENTRY_Y(0x2074, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen6_pv6 DRV_PINGROUP_ENTRY_Y(0x207c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen7_pv7 DRV_PINGROUP_ENTRY_Y(0x2084, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen8_pee0 DRV_PINGROUP_ENTRY_Y(0x208c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sen9_pee1 DRV_PINGROUP_ENTRY_Y(0x2094, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_can_gpio7_paa7 DRV_PINGROUP_ENTRY_Y(0x3004, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can1_dout_pz0 DRV_PINGROUP_ENTRY_Y(0x300C, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can1_din_pz1 DRV_PINGROUP_ENTRY_Y(0x3014, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can0_dout_pz2 DRV_PINGROUP_ENTRY_Y(0x301c, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can0_din_pz3 DRV_PINGROUP_ENTRY_Y(0x3024, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio0_paa0 DRV_PINGROUP_ENTRY_Y(0x302c, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio1_paa1 DRV_PINGROUP_ENTRY_Y(0x3034, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio2_paa2 DRV_PINGROUP_ENTRY_Y(0x303c, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio3_paa3 DRV_PINGROUP_ENTRY_Y(0x3044, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio4_paa4 DRV_PINGROUP_ENTRY_Y(0x304c, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio5_paa5 DRV_PINGROUP_ENTRY_Y(0x3054, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_can_gpio6_paa6 DRV_PINGROUP_ENTRY_Y(0x305c, -1, -1, -1, -1, 28, 2, 30, 2, 1) -#define drive_gpio_sw1_pff1 DRV_PINGROUP_ENTRY_Y(0x1004, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sw2_pff2 DRV_PINGROUP_ENTRY_Y(0x100c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sw3_pff3 DRV_PINGROUP_ENTRY_Y(0x1014, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_sw4_pff4 DRV_PINGROUP_ENTRY_Y(0x101c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_shutdown DRV_PINGROUP_ENTRY_Y(0x1024, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_pmu_int DRV_PINGROUP_ENTRY_Y(0x102C, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_safe_state_ps3 DRV_PINGROUP_ENTRY_Y(0x1034, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_vcomp_alert_ps4 DRV_PINGROUP_ENTRY_Y(0x103c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_soc_pwr_req DRV_PINGROUP_ENTRY_Y(0x1044, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_batt_oc_ps2 DRV_PINGROUP_ENTRY_Y(0x104c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_clk_32k_in DRV_PINGROUP_ENTRY_Y(0x1054, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_power_on_pff0 DRV_PINGROUP_ENTRY_Y(0x105c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_pwr_i2c_scl_ps0 DRV_PINGROUP_ENTRY_Y(0x1064, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_pwr_i2c_sda_ps1 DRV_PINGROUP_ENTRY_Y(0x106c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_dis0_pu0 DRV_PINGROUP_ENTRY_Y(0x1084, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_dis1_pu1 DRV_PINGROUP_ENTRY_Y(0x108c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_dis2_pu2 DRV_PINGROUP_ENTRY_Y(0x1094, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_dis3_pu3 DRV_PINGROUP_ENTRY_Y(0x109c, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_dis4_pu4 DRV_PINGROUP_ENTRY_Y(0x10a4, 12, 5, 20, 5, -1, -1, -1, -1, 1) -#define drive_gpio_dis5_pu5 DRV_PINGROUP_ENTRY_Y(0x10ac, 12, 5, 20, 5, -1, -1, -1, -1, 1) +#define drive_touch_clk_pee2 DRV_PINGROUP_ENTRY_Y(0x2004, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_uart3_cts_pw5 DRV_PINGROUP_ENTRY_Y(0x200c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_uart3_rts_pw4 DRV_PINGROUP_ENTRY_Y(0x2014, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_uart3_rx_pw3 DRV_PINGROUP_ENTRY_Y(0x201c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_uart3_tx_pw2 DRV_PINGROUP_ENTRY_Y(0x2024, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gen8_i2c_sda_pw1 DRV_PINGROUP_ENTRY_Y(0x202c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gen8_i2c_scl_pw0 DRV_PINGROUP_ENTRY_Y(0x2034, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_uart7_rx_pw7 DRV_PINGROUP_ENTRY_Y(0x203c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_uart7_tx_pw6 DRV_PINGROUP_ENTRY_Y(0x2044, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen0_pv0 DRV_PINGROUP_ENTRY_Y(0x204c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen1_pv1 DRV_PINGROUP_ENTRY_Y(0x2054, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen2_pv2 DRV_PINGROUP_ENTRY_Y(0x205c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen3_pv3 DRV_PINGROUP_ENTRY_Y(0x2064, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen4_pv4 DRV_PINGROUP_ENTRY_Y(0x206c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen5_pv5 DRV_PINGROUP_ENTRY_Y(0x2074, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen6_pv6 DRV_PINGROUP_ENTRY_Y(0x207c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen7_pv7 DRV_PINGROUP_ENTRY_Y(0x2084, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen8_pee0 DRV_PINGROUP_ENTRY_Y(0x208c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sen9_pee1 DRV_PINGROUP_ENTRY_Y(0x2094, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_can_gpio7_paa7 DRV_PINGROUP_ENTRY_Y(0x3004, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can1_dout_pz0 DRV_PINGROUP_ENTRY_Y(0x300C, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can1_din_pz1 DRV_PINGROUP_ENTRY_Y(0x3014, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can0_dout_pz2 DRV_PINGROUP_ENTRY_Y(0x301c, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can0_din_pz3 DRV_PINGROUP_ENTRY_Y(0x3024, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio0_paa0 DRV_PINGROUP_ENTRY_Y(0x302c, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio1_paa1 DRV_PINGROUP_ENTRY_Y(0x3034, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio2_paa2 DRV_PINGROUP_ENTRY_Y(0x303c, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio3_paa3 DRV_PINGROUP_ENTRY_Y(0x3044, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio4_paa4 DRV_PINGROUP_ENTRY_Y(0x304c, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio5_paa5 DRV_PINGROUP_ENTRY_Y(0x3054, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_can_gpio6_paa6 DRV_PINGROUP_ENTRY_Y(0x305c, -1, -1, -1, -1, 28, 2, 30, 2, 0) +#define drive_gpio_sw1_pff1 DRV_PINGROUP_ENTRY_Y(0x1004, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sw2_pff2 DRV_PINGROUP_ENTRY_Y(0x100c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sw3_pff3 DRV_PINGROUP_ENTRY_Y(0x1014, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_sw4_pff4 DRV_PINGROUP_ENTRY_Y(0x101c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_shutdown DRV_PINGROUP_ENTRY_Y(0x1024, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_pmu_int DRV_PINGROUP_ENTRY_Y(0x102C, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_safe_state_ps3 DRV_PINGROUP_ENTRY_Y(0x1034, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_vcomp_alert_ps4 DRV_PINGROUP_ENTRY_Y(0x103c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_soc_pwr_req DRV_PINGROUP_ENTRY_Y(0x1044, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_batt_oc_ps2 DRV_PINGROUP_ENTRY_Y(0x104c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_clk_32k_in DRV_PINGROUP_ENTRY_Y(0x1054, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_power_on_pff0 DRV_PINGROUP_ENTRY_Y(0x105c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_pwr_i2c_scl_ps0 DRV_PINGROUP_ENTRY_Y(0x1064, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_pwr_i2c_sda_ps1 DRV_PINGROUP_ENTRY_Y(0x106c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_dis0_pu0 DRV_PINGROUP_ENTRY_Y(0x1084, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_dis1_pu1 DRV_PINGROUP_ENTRY_Y(0x108c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_dis2_pu2 DRV_PINGROUP_ENTRY_Y(0x1094, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_dis3_pu3 DRV_PINGROUP_ENTRY_Y(0x109c, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_dis4_pu4 DRV_PINGROUP_ENTRY_Y(0x10a4, 12, 5, 20, 5, -1, -1, -1, -1, 0) +#define drive_gpio_dis5_pu5 DRV_PINGROUP_ENTRY_Y(0x10ac, 12, 5, 20, 5, -1, -1, -1, -1, 0)#define PINGROUP (pg_name, f0, f1, f2, f3, r, bank, pupd, e_io_hv, e_lpbk, e_input, e_lpdr, e_pbias_buf, \ gpio_sfio_sel, e_od, schmitt_b, drvtype, epreemp, io_reset, rfu_in) \
Signature · 1 line
2.56.0.385.gac671c819a-goog
Re: [PATCH 02/10] pinctrl: tegra186: Fix out-of-bounds register bank index for AON drive groups
Quoted 9 lines · Lee Jones
The Tegra186 AON pinmux controller has only a single register bank (nbanks = 1, indexed at 0), and all PINGROUP entries in
tegra186_aon_groupsaccordingly specify bank 0. However, all 51 AON drive_* macro definitions passdrv_bank= 1 as the final argument toDRV_PINGROUP_ENTRY_Y, causing any drive configuration read or write on an AON drive group to index pmx->regs[1] out-of-bounds.Update the AON drive_* macro definitions to use register bank 0.
Quoted 7 lines
Fixes 542baf77f092 ("pinctrl: tegra: Add Tegra186 pinmux driver")Signed-off-by Lee Jones <[email protected]>--- drivers/pinctrl/tegra/pinctrl-tegra186.c | 102 +++++++++++------------ 1 file changed, 51 insertions(+), 51 deletions(-)
Yeah, looks correct. It looks like this wasn't tested at all since the time this was merged. I'll add this to the list of things that need to have a test added.
Re: [PATCH 02/10] pinctrl: tegra186: Fix out-of-bounds register bank index for AON drive groups
Quoted 18 lines · Thierry Reding
Quoted 9 lines · Lee Jones
The Tegra186 AON pinmux controller has only a single register bank (nbanks = 1, indexed at 0), and all PINGROUP entries in
tegra186_aon_groupsaccordingly specify bank 0. However, all 51 AON drive_* macro definitions passdrv_bank= 1 as the final argument toDRV_PINGROUP_ENTRY_Y, causing any drive configuration read or write on an AON drive group to index pmx->regs[1] out-of-bounds.Update the AON drive_* macro definitions to use register bank 0.
Quoted 7 lines
Fixes 542baf77f092 ("pinctrl: tegra: Add Tegra186 pinmux driver")Signed-off-by Lee Jones <[email protected]>--- drivers/pinctrl/tegra/pinctrl-tegra186.c | 102 +++++++++++------------ 1 file changed, 51 insertions(+), 51 deletions(-)
Quoted 5 lines
Yeah, looks correct. It looks like this wasn't tested at all since the time this was merged. I'll add this to the list of things that need to have a test added.
Reviewed-by Thierry Reding <[email protected]>
Super. Thanks bud.
Signature · 1 line
Lee Jones
PATCH 3/10 pinctrl: ingenic: Fix element type of x1600_sfc_funcs array
In reply to Lee Jonesingenic_pinmux_set_mux() treats grp->data as a u8 array of per-pin mux modes (u8 *pin_modes = grp->data), and every other *_funcs array in the Ingenic pinctrl driver is declared as u8[]. Because x1600_sfc_funcs[] was declared as int[], indexing pin_modes[0..6] reads the first seven bytes of the int array (0, 0, 0, 0, 0, 0, 0) instead of reading mode 2 for the seventh pin.
Change the element type of x1600_sfc_funcs[] from int to u8.
--- drivers/pinctrl/pinctrl-ingenic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-ingenic.c +1 -1
@@ -2456,7 +2456,7 @@ static int x1600_mac_pins[] = { 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, }; -static int x1600_sfc_funcs[] = {0 ,0 ,0 ,0 ,0 ,0 ,2 , }; +static u8 x1600_sfc_funcs[] = {0 ,0 ,0 ,0 ,0 ,0 ,2 , };static const struct group_desc x1600_groups[] = {INGENIC_PIN_GROUP ("uart0-data" , x1600_uart0_data,0 ),
Signature · 1 line
2.56.0.385.gac671c819a-goog
Re: [PATCH 03/10] pinctrl: ingenic: Fix element type of x1600_sfc_funcs array
Hi,
Quoted 24 lines
Am 03.11.2026 um 22:29 schrieb Lee Jones <[email protected]>:
ingenic_pinmux_set_mux()treatsgrp->dataas a u8 array of per-pin mux modes (u8*pin_modes=grp->data), and every other*_funcsarray in the Ingenic pinctrl driver is declared as u8[]. Because x1600_sfc_funcs[] was declared as int[], indexing pin_modes[0..6] reads the first seven bytes of the int array (0, 0, 0, 0, 0, 0, 0) instead of reading mode 2 for the seventh pin.Change the element type of x1600_sfc_funcs[] from int to u8.
Fixes 4da56f9c6f14 ("pinctrl: ingenic: add x1600 support")Signed-off-by Lee Jones <[email protected]>---
drivers/pinctrl/pinctrl-ingenic.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/pinctrl/pinctrl-ingenic.c +0
-0
drivers/pinctrl/pinctrl-ingenic.c static int x1600_mac_pins[] = { · line 2459
Quoted 5 lines
drivers/pinctrl/pinctrl-ingenic.c +1
-1@@ -2456,7 +2456,7 @@ static int x1600_mac_pins[] = { 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, }; -static int x1600_sfc_funcs[] = {0 ,0 ,0 ,0 ,0 ,0 ,2 , }; +static u8 x1600_sfc_funcs[] = {0 ,0 ,0 ,0 ,0 ,0 ,2 , };
Yes, that appears to be the correct fix. All other INGENIC_PIN_GROUP_FUNCS() use u8 arrays.
I can not test as our x1600 board does not use the SFC interface.
Quoted 5 lines
drivers/pinctrl/pinctrl-ingenic.c +0
-0static const struct group_desc x1600_groups[] = {INGENIC_PIN_GROUP ("uart0-data" , x1600_uart0_data,0 ),Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH 4/10 pinctrl: mediatek: mt7981: Add missing entries to mt7981_ant_sel_funcs
In reply to Lee Jonesmt7981_ant_sel_pins[] defines 14 pins (pins 14..25, 34, and 35), all of which select ANT_SEL at function mux mode 6, but mt7981_ant_sel_funcs[] only contains 12 entries. When mtk_pinmux_set_mux() iterates over grp->num_pins (14), it reads two int elements past the end of mt7981_ant_sel_funcs[].
Add the two missing mode 6 entries to mt7981_ant_sel_funcs[] so its length matches mt7981_ant_sel_pins[].
--- drivers/pinctrl/mediatek/pinctrl-mt7981.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/mediatek/pinctrl-mt7981.c +1 -1
@@ -800,7 +800,7 @@ static int mt7981_mt7531_int_funcs[] = { 1, };/* ANT_SEL */ static int mt7981_ant_sel_pins[] = {14 ,15 ,16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,34 ,35 }; -static int mt7981_ant_sel_funcs[] = {6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 }; +static int mt7981_ant_sel_funcs[] = {6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 ,6 };static const struct group_desc mt7981_groups[] = {/* @GPIO(0,1): WA_AICE(2) */
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH 5/10 pinctrl: realtek: Prevent out-of-bounds access in rtd_pinctrl_find_config()
In reply to Lee JonesSeveral Realtek SoC pin configuration tables (such as rtd1319d_iso_configs, rtd1619b_iso_configs, and the rtd1625 config tables) omit trailing pins that do not support pin configuration, making data->info->num_configs smaller than data->info->num_pins. Because rtd_pinctrl_find_config() indexes data->info->configs[pin] without checking data->info->num_configs, requesting pin configuration on a trailing pin reads out-of-bounds memory.
Check that pin is less than data->info->num_configs before indexing data->info->configs[].
--- drivers/pinctrl/realtek/pinctrl-rtd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pinctrl/realtek/pinctrl-rtd.c +3 -0
@@ -252,6 +252,9 @@ static const struct pinctrl_pin_descstatic const struct rtd_pin_config_desc *rtd_pinctrl_find_config (struct rtd_pinctrl *data,unsigned int pin) { +if (pin >= data->info->num_configs) +return NULL ; +if (data->info->configs[pin].name)return &data->info->configs[pin];
Signature · 1 line
2.56.0.385.gac671c819a-goog
RE: [PATCH 05/10] pinctrl: realtek: Prevent out-of-bounds access in rtd_pinctrl_find_config()
Quoted 10 lines
Several Realtek SoC pin configuration tables (such as
rtd1319d_iso_configs,rtd1619b_iso_configs, and the rtd1625 config tables) omit trailing pins that do not support pin configuration, makingdata->info->num_configssmaller thandata->info->num_pins. Becausertd_pinctrl_find_config()indexes data->info->configs[pin] without checkingdata->info->num_configs, requesting pin configuration on a trailing pin reads out-of-bounds memory.Check that pin is less than
data->info->num_configsbefore indexing data->info->configs[].
Quoted 6 lines
Fixes e99ce78030db ("pinctrl: realtek: Add common pinctrl driver for RealtekDHC RTD SoCs")
Closes:
https://sashiko.dev/#/bug/linux-60e13761-fd9e-4fd3-826a-47344f36d4faSigned-off-by Lee Jones <[email protected]>
Quoted 21 lines
--- drivers/pinctrl/realtek/pinctrl-rtd.c | 3 +++ 1 file changed, 3 insertions(+)drivers/pinctrl/realtek/pinctrl-rtd.c +0
-0@@ -252,6 +252,9 @@ static const struct pinctrl_pin_desc static const struct
rtd_pin_config_desc
*rtd_pinctrl_find_config(structrtd_pinctrl*data, unsigned int pin)
{drivers/pinctrl/realtek/pinctrl-rtd.c +3
-1+if (pin >= data->info->num_configs) +return NULL ; +if (data->info->configs[pin].name)return &data->info->configs[pin]; --2.56.0.385.gac671c819a-goog
Linus Walleij
maintainerRe: [PATCH 05/10] pinctrl: realtek: Prevent out-of-bounds access in rtd_pinctrl_find_config()
In reply to Lee JonesQuoted 7 lines · Lee Jones
Several Realtek SoC pin configuration tables (such as
rtd1319d_iso_configs,rtd1619b_iso_configs, and the rtd1625 config tables) omit trailing pins that do not support pin configuration, makingdata->info->num_configssmaller thandata->info->num_pins. Becausertd_pinctrl_find_config()indexes data->info->configs[pin] without checkingdata->info->num_configs, requesting pin configuration on a trailing pin reads out-of-bounds memory.
Quoted 7 lines
Check that pin is less than
data->info->num_configsbefore indexing data->info->configs[].Fixes e99ce78030db ("pinctrl: realtek: Add common pinctrl driver for Realtek DHC RTD SoCs")Signed-off-by Lee Jones <[email protected]>
This patch 5/10 applied for fixes.
Yours,
Linus Walleij
PATCH 6/10 pinctrl: realtek: Fix bit shift when configuring RTD_HIGH_VIL
In reply to Lee JonesIn rtd_pconf_parse_conf(), the RTD_HIGH_VIL case prepares mask as BIT(hvil_off) for regmap_update_bits(), but sets val = 1 without shifting it to hvil_off. Whenever hvil_off is non-zero, regmap_update_bits() masks val with BIT(hvil_off) and clears the high VIL bit instead of setting it.
Set val to BIT(hvil_off) so that the target bit is set as intended.
--- drivers/pinctrl/realtek/pinctrl-rtd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/realtek/pinctrl-rtd.c +1 -1
@@ -473,7 +473,7 @@ static int rtd_pconf_parse_conf(struct rtd_pinctrl *data, hvil_off = config_desc->base_bit + config_desc->hvil_offset; reg_off = config_desc->reg_offset; mask =BIT (hvil_off); - val =1 ; + val =BIT (hvil_off);break ;case RTD_DRIVE_STRENGTH_P :
Signature · 1 line
2.56.0.385.gac671c819a-goog
RE: [PATCH 06/10] pinctrl: realtek: Fix bit shift when configuring RTD_HIGH_VIL
Quoted 6 lines
In
rtd_pconf_parse_conf(), theRTD_HIGH_VILcase prepares mask asBIT(hvil_off)forregmap_update_bits(), but sets val = 1 without shifting it tohvil_off. Wheneverhvil_offis non-zero,regmap_update_bits()masks val withBIT(hvil_off)and clears the high VIL bit instead of setting it.
Quoted 8 lines
Set val to
BIT(hvil_off)so that the target bit is set as intended.Fixes dcc9334435b0 ("pinctrl: realtek: add support for slew rate, input voltageand high VIL")
Closes:
https://sashiko.dev/#/bug/linux-e7077311-3f30-4b77-844b-1447519d0c84Signed-off-by Lee Jones <[email protected]>
Quoted 22 lines
--- drivers/pinctrl/realtek/pinctrl-rtd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pinctrl/realtek/pinctrl-rtd.c +1
-1@@ -473,7 +473,7 @@ static int rtd_pconf_parse_conf(struct rtd_pinctrl *data, hvil_off = config_desc->base_bit + config_desc->hvil_offset; reg_off = config_desc->reg_offset; mask =BIT (hvil_off); - val =1 ; + val =BIT (hvil_off);break ;case
RTD_DRIVE_STRENGTH_P:
--
2.56.0.385.gac671c819a-goog
Linus Walleij
maintainerRe: [PATCH 06/10] pinctrl: realtek: Fix bit shift when configuring RTD_HIGH_VIL
In reply to Lee JonesQuoted 6 lines · Lee Jones
In
rtd_pconf_parse_conf(), theRTD_HIGH_VILcase prepares mask asBIT(hvil_off)forregmap_update_bits(), but sets val = 1 without shifting it tohvil_off. Wheneverhvil_offis non-zero,regmap_update_bits()masks val withBIT(hvil_off)and clears the high VIL bit instead of setting it.
Quoted 6 lines
Set val to
BIT(hvil_off)so that the target bit is set as intended.Fixes dcc9334435b0 ("pinctrl: realtek: add support for slew rate, input voltage and high VIL")Signed-off-by Lee Jones <[email protected]>
This patch 6/10 applied for fixes!
Yours,
Linus Walleij
PATCH 7/10 pinctrl: realtek: Initialise omitted offset fields to NA in config macros
In reply to Lee JonesThe Realtek pinctrl driver uses NA (0xffffffff) as the sentinel for unsupported pin configuration features. However, RTK_PIN_CONFIG omits input_volt_offset, slew_rate_offset, and hvil_offset, and RTK_PIN_CONFIG_V2 omits slew_rate_offset and hvil_offset. Because C99 designated initialisers zero-initialise omitted members, those fields default to 0 instead of NA, causing rtd_pconf_parse_conf() to treat unsupported features as valid at bit offset base_bit + 0 and corrupt adjacent register bits.
Explicitly initialise the omitted offset fields to NA in RTK_PIN_CONFIG and RTK_PIN_CONFIG_V2.
--- drivers/pinctrl/realtek/pinctrl-rtd.h | 5 +++++ 1 file changed, 5 insertions(+)
drivers/pinctrl/realtek/pinctrl-rtd.h +5 -0
@@ -96,6 +96,9 @@ struct rtd_pin_reg_list { .smt_offset = _smt_off, \ .power_offset = _pow_off, \ .curr_type = _curr_type, \ + .input_volt_offset = NA, \ + .slew_rate_offset = NA, \ + .hvil_offset = NA, \ } #define RTK_PIN_CONFIG_V2(_name, _reg_off, _base_bit, _pud_en_off, \
@@ -112,6 +115,8 @@ struct rtd_pin_reg_list { .power_offset = _pow_off, \ .input_volt_offset = _input_volt_off, \ .curr_type = _curr_type, \ + .slew_rate_offset = NA, \ + .hvil_offset = NA, \ } #define RTK_PIN_CONFIG_I2C(_name, _reg_off, _base_bit, _pud_en_off, \
Signature · 1 line
2.56.0.385.gac671c819a-goog
RE: [PATCH 07/10] pinctrl: realtek: Initialise omitted offset fields to NA in config macros
Quoted 8 lines
The Realtek pinctrl driver uses NA (
0xffffffff) as the sentinel for unsupported pin configuration features. However,RTK_PIN_CONFIGomitsinput_volt_offset,slew_rate_offset, andhvil_offset, andRTK_PIN_CONFIG_V2omitsslew_rate_offsetandhvil_offset. Because C99 designated initialisers zero-initialise omitted members, those fields default to 0 instead of NA, causingrtd_pconf_parse_conf()to treat unsupported features as valid at bit offsetbase_bit+ 0 and corrupt adjacent register bits.
Quoted 5 lines
Explicitly initialise the omitted offset fields to NA in
RTK_PIN_CONFIGandRTK_PIN_CONFIG_V2.Fixes dcc9334435b0 ("pinctrl: realtek: add support for slew rate, input voltageand high VIL")
This should be:
DHC RTD SoCs")
Quoted 5 lines
Fixes e309dbd523b8 ("pinctrl: realtek: add rtd1625 pinctrl driver")Closes:
https://sashiko.dev/#/bug/linux-fbd0bf54-6dba-4652-9418-270b11fb6d8bSigned-off-by Lee Jones <[email protected]>
Otherwise, looks good to me.
Thanks for the fixes.
Quoted 30 lines
--- drivers/pinctrl/realtek/pinctrl-rtd.h | 5 +++++ 1 file changed, 5 insertions(+)drivers/pinctrl/realtek/pinctrl-rtd.h +5
-1@@ -96,6 +96,9 @@ struct rtd_pin_reg_list { .smt_offset = _smt_off, \ .power_offset = _pow_off, \ .curr_type = _curr_type, \ + .input_volt_offset = NA, \ + .slew_rate_offset = NA, \ + .hvil_offset = NA, \ } #define RTK_PIN_CONFIG_V2(_name, _reg_off, _base_bit, _pud_en_off, \@@ -112,6 +115,8 @@ struct rtd_pin_reg_list { .power_offset = _pow_off, \ .input_volt_offset = _input_volt_off, \ .curr_type = _curr_type, \ + .slew_rate_offset = NA, \ + .hvil_offset = NA, \ } #define RTK_PIN_CONFIG_I2C(_name, _reg_off, _base_bit, _pud_en_off, \ --2.56.0.385.gac671c819a-goog
Linus Walleij
maintainerRe: [PATCH 07/10] pinctrl: realtek: Initialise omitted offset fields to NA in config macros
In reply to Lee JonesQuoted 9 lines · Lee Jones
The Realtek pinctrl driver uses NA (
0xffffffff) as the sentinel for unsupported pin configuration features. However,RTK_PIN_CONFIGomitsinput_volt_offset,slew_rate_offset, andhvil_offset, andRTK_PIN_CONFIG_V2omitsslew_rate_offsetandhvil_offset. Because C99 designated initialisers zero-initialise omitted members, those fields default to 0 instead of NA, causingrtd_pconf_parse_conf()to treat unsupported features as valid at bit offsetbase_bit+ 0 and corrupt adjacent register bits.
Quoted 8 lines
Explicitly initialise the omitted offset fields to NA in
RTK_PIN_CONFIGandRTK_PIN_CONFIG_V2.Fixes dcc9334435b0 ("pinctrl: realtek: add support for slew rate, input voltage and high VIL")Fixes e309dbd523b8 ("pinctrl: realtek: add rtd1625 pinctrl driver")Signed-off-by Lee Jones <[email protected]>
This patch 7/10 applied to the pinctrl tree for fixes.
Yours,
Linus Walleij
Yu-Chun Lin [林祐君]
maintainerRE: [PATCH 07/10] pinctrl: realtek: Initialise omitted offset fields to NA in config macros
Quoted 23 lines · Lee Jones
Quoted 13 lines
The Realtek pinctrl driver uses NA (
0xffffffff) as the sentinel for unsupported pin configuration features. However,RTK_PIN_CONFIGomitsinput_volt_offset,slew_rate_offset, andhvil_offset, andRTK_PIN_CONFIG_V2omitsslew_rate_offsetandhvil_offset. Because C99 designated initialisers zero-initialise omitted members, those fields default to 0 instead of NA, causingrtd_pconf_parse_conf()to treat unsupported features as valid at bit offsetbase_bit+ 0 and corrupt adjacent register bits.Explicitly initialise the omitted offset fields to NA in
RTK_PIN_CONFIGandRTK_PIN_CONFIG_V2.Quoted 7 lines
Fixes dcc9334435b0 ("pinctrl: realtek: add support for slew rate,input voltage and high VIL")
Fixes e309dbd523b8 ("pinctrl: realtek: add rtd1625 pinctrl driver")Closes:
https://sashiko.dev/#/bug/linux-fbd0bf54-6dba-4652-9418-270b11fb6d8bSigned-off-by Lee Jones <[email protected]>
Quoted 4 lines
This patch 7/10 applied to the pinctrl tree for fixes.
Yours,
Linus Walleij
Hi Linus,
Thanks for applying this patch. Just a quick heads-up on the merged commit [1]:
1. The first Fixes tag kept the original 'dcc9334435b0' instead of the corrected 'e99ce78030db' I suggested.
2. Branch: It was applied to 'for-next' instead of 'fixes'. Just checking if this was intended.
Best regards,
Yu-Chun
Linus Walleij
maintainerRe: [PATCH 07/10] pinctrl: realtek: Initialise omitted offset fields to NA in config macros
Quoted 4 lines · Yu-Chun Lin [林祐君]
Thanks for applying this patch. Just a quick heads-up on the merged commit [1]:
1. The first Fixes tag kept the original '
dcc9334435b0' instead of the corrected 'e99ce78030db' I suggested.
I went in and fixed it up.
Quoted 2 lines
2. Branch: It was applied to 'for-next' instead of 'fixes'. Just checking if this was intended.
Yes Lee reached out to me on IRC and asked that the paches be queued for-next as nonurgent fixes.
Yours,
Linus Walleij
PATCH 8/10 pinctrl: mediatek: Clean up partially initialised hw->eint on error
In reply to Lee JonesIn mtk_build_eint(), if of_property_count_strings() fails or hw->eint->nbase is non-positive, the function returns -EINVAL directly after allocating hw->eint without jumping to err_free_base. Because callers such as mtk_paris_pinctrl_probe() and mtk_moore_pinctrl_probe() log a warning and continue probing when mtk_build_eint() fails, leaving hw->eint non-NULL with hw->eint->hw unset causes subsequent GPIO or suspend/resume callbacks to dereference a NULL pointer inside mtk_eint_do_suspend() or mtk_gpio_to_irq().
Jump to err_free_base on both error paths so hw->eint is freed and reset to NULL.
--- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +8 -4
@@ -382,12 +382,16 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)return -ENOMEM ; count_reg_names =of_property_count_strings (np,"reg-names" ); -if (count_reg_names <0 ) -return -EINVAL ; +if (count_reg_names <0 ) { + ret = -EINVAL ; + goto err_free_base; + } hw->eint->nbase = count_reg_names - (int )hw->soc->nbase_names; -if (hw->eint->nbase <=0 ) -return -EINVAL ; +if (hw->eint->nbase <=0 ) { + ret = -EINVAL ; + goto err_free_base; + } hw->eint->base =devm_kmalloc_array (&pdev->dev, hw->eint->nbase,sizeof (*hw->eint->base),GFP_KERNEL | __GFP_ZERO);
Signature · 1 line
2.56.0.385.gac671c819a-goog
[email protected]
AI reviewRe: [PATCH 08/10] pinctrl: mediatek: Clean up partially initialised hw->eint on error
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] pinctrl: mediatek: NULL deref in mtk_eint_do_suspend() on EINT init error --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pinctrl: mediatek: NULL deref in mtk_eint_do_suspend() on EINT init error --
commit 8d040caade190db874ef6d84f338e06e2679ef73
Author: Lee Jones <[email protected]>
pinctrl: mediatek: Clean up partially initialised hw->eint on error
This commit updates mtk_build_eint() to jump to err_free_base when of_property_count_strings() fails or hw->eint->nbase is non-positive, freeing hw->eint and resetting it to NULL.
Quoted 12 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +2
-2@@ -382,12 +382,16 @@ int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)return -ENOMEM ; count_reg_names =of_property_count_strings (np,"reg-names" ); -if (count_reg_names <0 ) -return -EINVAL ; +if (count_reg_names <0 ) { + ret = -EINVAL ;
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev) · line 394
Quoted 10 lines
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +6
-2+ goto err_free_base; + } hw->eint->nbase = count_reg_names - (int )hw->soc->nbase_names; -if (hw->eint->nbase <=0 ) -return -EINVAL ; +if (hw->eint->nbase <=0 ) { + ret = -EINVAL ; + goto err_free_base; + }
[Severity: High]
The commit message notes that leaving hw->eint non-NULL on these error paths causes subsequent suspend/resume callbacks to dereference a NULL pointer inside mtk_eint_do_suspend(), and that resetting hw->eint to NULL avoids this.
However, when mtk_build_eint() fails during mtk_paris_pinctrl_probe(), the driver logs a warning and finishes probing with pctl->eint set to NULL. On system suspend or resume, mtk_paris_pinctrl_suspend() and mtk_paris_pinctrl_resume() pass pctl->eint directly to mtk_eint_do_suspend() and mtk_eint_do_resume():
drivers/pinctrl/mediatek/pinctrl-paris.c:
static int mtk_paris_pinctrl_suspend(struct device *device)
{
struct mtk_pinctrl *pctl = dev_get_drvdata(device);
return mtk_eint_do_suspend(pctl->eint);
}Neither those callers nor mtk_eint_do_suspend() and mtk_eint_do_resume() check whether eint is NULL before dereferencing it:
drivers/pinctrl/mediatek/mtk-eint.c:
int mtk_eint_do_suspend(struct mtk_eint *eint)
{
mtk_eint_chip_write_mask(eint, eint->wake_mask);
return 0;
}Previously on these two error paths, hw->eint remained non-NULL with hw->eint->nbase <= 0, so the loop in mtk_eint_chip_write_mask() over inst < eint->nbase did zero iterations. With hw->eint reset to NULL here (as well as on the existing error paths in mtk_build_eint()), won't suspending or resuming trigger a NULL pointer dereference in mtk_eint_do_suspend() and mtk_eint_do_resume() unless a NULL check is also added?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH 9/10 pinctrl: mediatek: Prevent divide-by-zero for pins with fixed drive strength
In reply to Lee Jonesmtk_drive[] only defines entries for DRV_GRP0 (1) through DRV_GRP4 (5), leaving mtk_drive[DRV_FIXED] (0) zero-initialised with min = 0, max = 0, step = 0, and scal = 0. If mtk_pinconf_drive_set() or mtk_pinconf_drive_set_rev1() is called with arg = 0 on a pin with drv_n == DRV_FIXED, the range check (0 >= 0 && 0 <= 0) succeeds and !(arg % tb->step) divides by zero. Similarly, mtk_pinconf_drive_get() and mtk_pinconf_drive_get_rev1() divide by tb->scal (0) if the pin has drive register fields defined.
Return -ENOTSUPP immediately when desc->drv_n == DRV_FIXED.
--- drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c +12 -0
@@ -1040,6 +1040,9 @@ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,const struct mtk_drive_desc *tb;int err = -ENOTSUPP ; +if (desc->drv_n ==DRV_FIXED ) +return -ENOTSUPP ; + tb = &mtk_drive[desc->drv_n];/* 4mA when (e8, e4) = (0, 0) * 8mA when (e8, e4) = (0, 1)
@@ -1069,6 +1072,9 @@ int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,const struct mtk_drive_desc *tb;int err, val1, val2; +if (desc->drv_n ==DRV_FIXED ) +return -ENOTSUPP ; + tb = &mtk_drive[desc->drv_n]; err =mtk_hw_get_value (hw, desc,PINCTRL_PIN_REG_E4 , &val1);
@@ -1095,6 +1101,9 @@ int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,const struct mtk_drive_desc *tb;int err = -ENOTSUPP ; +if (desc->drv_n ==DRV_FIXED ) +return -ENOTSUPP ; + tb = &mtk_drive[desc->drv_n];if ((arg >= tb->min && arg <= tb->max) && !(arg % tb->step)) {
@@ -1116,6 +1125,9 @@ int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,const struct mtk_drive_desc *tb;int err, val1; +if (desc->drv_n ==DRV_FIXED ) +return -ENOTSUPP ; + tb = &mtk_drive[desc->drv_n]; err =mtk_hw_get_value (hw, desc,PINCTRL_PIN_REG_DRV , &val1);
Signature · 1 line
2.56.0.385.gac671c819a-goog
PATCH 10/10 pinctrl: qcom: Check qcom_scm_io_readl() return value in msm_gpio_irq_set_type()
In reply to Lee JonesIn msm_gpio_irq_set_type(), when pctrl->intr_target_use_scm is set, the return value of qcom_scm_io_readl(addr, &val) is ignored. If the SCM read fails, val remains uninitialised and its stack contents are modified and written back to the hardware register via qcom_scm_io_writel().
Check the return value of qcom_scm_io_readl() before modifying and writing back val.
--- drivers/pinctrl/qcom/pinctrl-msm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/pinctrl/qcom/pinctrl-msm.c +6 -4
@@ -1105,11 +1105,13 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)u32 addr = pctrl->phys_base[0 ] + reg;int ret; -qcom_scm_io_readl (addr, &val); - val &= ~(intr_target_mask << g->intr_target_bit); - val |= g->intr_target_kpss_val << g->intr_target_bit; + ret =qcom_scm_io_readl (addr, &val); +if (!ret) { + val &= ~(intr_target_mask << g->intr_target_bit); + val |= g->intr_target_kpss_val << g->intr_target_bit; - ret =qcom_scm_io_writel (addr, val); + ret =qcom_scm_io_writel (addr, val); + }if (ret) dev_err(pctrl->dev, "Failed routing %lu interrupt to Apps proc",
Signature · 1 line
2.56.0.385.gac671c819a-goog
Re: [PATCH 10/10] pinctrl: qcom: Check qcom_scm_io_readl() return value in msm_gpio_irq_set_type()
Quoted 26 lines · Lee Jones
In
msm_gpio_irq_set_type(), whenpctrl->intr_target_use_scmis set, the return value ofqcom_scm_io_readl(addr, &val)is ignored. If the SCM read fails, val remains uninitialised and its stack contents are modified and written back to the hardware register viaqcom_scm_io_writel().Check the return value of
qcom_scm_io_readl()before modifying and writing back val.Fixes 13bec8d49bdf ("pinctrl: qcom: use scm_call to route GPIO irq to Apps")Signed-off-by Lee Jones <[email protected]>--- drivers/pinctrl/qcom/pinctrl-msm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/pinctrl/qcom/pinctrl-msm.c +0
-2@@ -1105,11 +1105,13 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)u32 addr = pctrl->phys_base[0 ] + reg;int ret; -qcom_scm_io_readl (addr, &val); - val &= ~(intr_target_mask << g->intr_target_bit);
drivers/pinctrl/qcom/pinctrl-msm.c static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type) · line 1115
Quoted 10 lines
drivers/pinctrl/qcom/pinctrl-msm.c +6
-2- val |= g->intr_target_kpss_val << g->intr_target_bit; + ret =qcom_scm_io_readl (addr, &val); +if (!ret) { + val &= ~(intr_target_mask << g->intr_target_bit); + val |= g->intr_target_kpss_val << g->intr_target_bit; - ret =qcom_scm_io_writel (addr, val); + ret =qcom_scm_io_writel (addr, val); + }if (ret)
Konrad
Re: [PATCH 10/10] pinctrl: qcom: Check qcom_scm_io_readl() return value in msm_gpio_irq_set_type()
In reply to Lee JonesQuoted 41 lines · Lee Jones
In
msm_gpio_irq_set_type(), whenpctrl->intr_target_use_scmis set, the return value ofqcom_scm_io_readl(addr, &val)is ignored. If the SCM read fails, val remains uninitialised and its stack contents are modified and written back to the hardware register viaqcom_scm_io_writel().Check the return value of
qcom_scm_io_readl()before modifying and writing back val.Fixes 13bec8d49bdf ("pinctrl: qcom: use scm_call to route GPIO irq to Apps")Signed-off-by Lee Jones <[email protected]>--- drivers/pinctrl/qcom/pinctrl-msm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/pinctrl/qcom/pinctrl-msm.c +6
-4@@ -1105,11 +1105,13 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)u32 addr = pctrl->phys_base[0 ] + reg;int ret; -qcom_scm_io_readl (addr, &val); - val &= ~(intr_target_mask << g->intr_target_bit); - val |= g->intr_target_kpss_val << g->intr_target_bit; + ret =qcom_scm_io_readl (addr, &val); +if (!ret) { + val &= ~(intr_target_mask << g->intr_target_bit); + val |= g->intr_target_kpss_val << g->intr_target_bit; - ret =qcom_scm_io_writel (addr, val); + ret =qcom_scm_io_writel (addr, val); + }if (ret) dev_err(pctrl->dev, "Failed routing %lu interrupt to Apps proc",Signature · 1 line
2.56.0.385.gac671c819a-goog
In case Linus wants to apply the entire series at once:
Linus Walleij
maintainerRe: [PATCH 10/10] pinctrl: qcom: Check qcom_scm_io_readl() return value in msm_gpio_irq_set_type()
In reply to Lee JonesQuoted 5 lines · Lee Jones
In
msm_gpio_irq_set_type(), whenpctrl->intr_target_use_scmis set, the return value ofqcom_scm_io_readl(addr, &val)is ignored. If the SCM read fails, val remains uninitialised and its stack contents are modified and written back to the hardware register viaqcom_scm_io_writel().
Quoted 7 lines
Check the return value of
qcom_scm_io_readl()before modifying and writing back val.Fixes 13bec8d49bdf ("pinctrl: qcom: use scm_call to route GPIO irq to Apps")Signed-off-by Lee Jones <[email protected]>
This patch 10/10 applied for fixes.
Yours,
Linus Walleij
Linus Walleij
maintainerHi Lee,
thanks for looking into this!!
I'll wait a week or so for maintainers to pick up individual patches, then just apply the rest.
Poke me with something sharp if I forget it.
Yours,
Linus Walleij