316-otto-gpio-uniprocessor-irq-mask.patch 1.9 KB

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