Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'gpio-fixes-for-v5.18-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio fix from Bartosz Golaszewski:

- fix a race condition with consumers accessing the fields of GPIO IRQ
chips before they're fully initialized

* tag 'gpio-fixes-for-v5.18-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
gpio: Restrict usage of GPIO chip irq members before initialization

+28
+19
drivers/gpio/gpiolib.c
··· 1404 1404 { 1405 1405 struct irq_domain *domain = gc->irq.domain; 1406 1406 1407 + #ifdef CONFIG_GPIOLIB_IRQCHIP 1408 + /* 1409 + * Avoid race condition with other code, which tries to lookup 1410 + * an IRQ before the irqchip has been properly registered, 1411 + * i.e. while gpiochip is still being brought up. 1412 + */ 1413 + if (!gc->irq.initialized) 1414 + return -EPROBE_DEFER; 1415 + #endif 1416 + 1407 1417 if (!gpiochip_irqchip_irq_valid(gc, offset)) 1408 1418 return -ENXIO; 1409 1419 ··· 1602 1592 gpiochip_set_irq_hooks(gc); 1603 1593 1604 1594 acpi_gpiochip_request_interrupts(gc); 1595 + 1596 + /* 1597 + * Using barrier() here to prevent compiler from reordering 1598 + * gc->irq.initialized before initialization of above 1599 + * GPIO chip irq members. 1600 + */ 1601 + barrier(); 1602 + 1603 + gc->irq.initialized = true; 1605 1604 1606 1605 return 0; 1607 1606 }
+9
include/linux/gpio/driver.h
··· 222 222 bool per_parent_data; 223 223 224 224 /** 225 + * @initialized: 226 + * 227 + * Flag to track GPIO chip irq member's initialization. 228 + * This flag will make sure GPIO chip irq members are not used 229 + * before they are initialized. 230 + */ 231 + bool initialized; 232 + 233 + /** 225 234 * @init_hw: optional routine to initialize hardware before 226 235 * an IRQ chip will be added. This is quite useful when 227 236 * a particular driver wants to clear IRQ related registers