Commit fe598ab
hwmon: (vt8231) Convert macros to functions to avoid TOCTOU
The macro FAN_FROM_REG evaluates its arguments multiple times. When used
with shared driver data, this leads to Time-of-Check to Time-of-Use
(TOCTOU) race conditions, potentially causing divide-by-zero errors.
Convert the macro to a static function to ensure arguments are evaluated
only once.
Additionally, in fan_div_store, move the reading of the old register
value and the calculation of the minimum limit inside the update lock.
This ensures that the read-modify-write sequence operates on consistent
data, preventing race conditions during fan divider updates.
Link: https://lore.kernel.org/all/CALbr=LYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=o1xxMJ8=5z8B-g@mail.gmail.com/
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
Link: https://lore.kernel.org/r/20251124165900.4713-1-hanguidong02@gmail.com
[groeck: Dropped unnecessary line split]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>1 parent 4faaa77 commit fe598ab
1 file changed
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
| |||
561 | 566 | | |
562 | 567 | | |
563 | 568 | | |
564 | | - | |
| 569 | + | |
565 | 570 | | |
566 | 571 | | |
567 | 572 | | |
| |||
571 | 576 | | |
572 | 577 | | |
573 | 578 | | |
574 | | - | |
| 579 | + | |
575 | 580 | | |
576 | 581 | | |
577 | 582 | | |
| |||
613 | 618 | | |
614 | 619 | | |
615 | 620 | | |
616 | | - | |
617 | | - | |
618 | | - | |
| 621 | + | |
| 622 | + | |
619 | 623 | | |
620 | 624 | | |
621 | 625 | | |
622 | 626 | | |
623 | 627 | | |
624 | 628 | | |
625 | 629 | | |
| 630 | + | |
| 631 | + | |
626 | 632 | | |
627 | 633 | | |
628 | 634 | | |
| |||
0 commit comments