ath25: switch default kernel to 5.15
[openwrt/staging/ldir.git] / target / linux / realtek / patches-5.10 / 316-otto-gpio-uniprocessor-irq-mask.patch
1 From bde6311569ef25a00c3beaeabfd6b78b19651872 Mon Sep 17 00:00:00 2001
2 From: Sander Vanheule <sander@svanheule.net>
3 Date: Sun, 29 May 2022 19:38:09 +0200
4 Subject: [PATCH] realtek: don't unmask non-maskable GPIO IRQs
5
6 On uniprocessor builds, for_each_cpu(cpu, mask) will assume 'mask'
7 always contains exactly one CPU, and ignore the actual mask contents.
8 This causes the loop to run, even when it shouldn't on an empty mask,
9 and tries to access an uninitialised pointer.
10
11 Fix this by wrapping the loop in a cpumask_empty() check, to ensure it
12 will not run on uniprocessor builds if the CPU mask is empty.
13
14 Fixes: af6cd37f42f3 ("realtek: replace RTL93xx GPIO patches")
15 Reported-by: INAGAKI Hiroshi <musashino.open@gmail.com>
16 Reported-by: Robert Marko <robimarko@gmail.com>
17 Tested-by: Robert Marko <robimarko@gmail.com>
18 Submitted-by: Sander Vanheule <sander@svanheule.net>
19 ---
20 drivers/gpio/gpio-realtek-otto.c | 9 +++++++++++--
21 1 file changed, 11 insertions(+), 2 deletions(-)
22
23 --- a/drivers/gpio/gpio-realtek-otto.c
24 +++ b/drivers/gpio/gpio-realtek-otto.c
25 @@ -304,6 +304,7 @@ static int realtek_gpio_irq_set_affinity
26 static int realtek_gpio_irq_init(struct gpio_chip *gc)
27 {
28 struct realtek_gpio_ctrl *ctrl = gpiochip_get_data(gc);
29 + void __iomem *irq_cpu_mask;
30 unsigned int port;
31 int cpu;
32
33 @@ -311,8 +312,16 @@ static int realtek_gpio_irq_init(struct
34 realtek_gpio_write_imr(ctrl, port, 0, 0);
35 realtek_gpio_clear_isr(ctrl, port, GENMASK(7, 0));
36
37 - for_each_cpu(cpu, &ctrl->cpu_irq_maskable)
38 - iowrite8(GENMASK(7, 0), realtek_gpio_irq_cpu_mask(ctrl, port, cpu));
39 + /*
40 + * Uniprocessor builds assume a mask always contains one CPU,
41 + * so only start the loop if we have at least one maskable CPU.
42 + */
43 + if(!cpumask_empty(&ctrl->cpu_irq_maskable)) {
44 + for_each_cpu(cpu, &ctrl->cpu_irq_maskable) {
45 + irq_cpu_mask = realtek_gpio_irq_cpu_mask(ctrl, port, cpu);
46 + iowrite8(GENMASK(7, 0), irq_cpu_mask);
47 + }
48 + }
49 }
50
51 return 0;