kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset
PATCH 1/1 kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset
The function apple_airport_reset is not called in atomic context. Thus mdelay can be replaced with usleep_range, to avoid busy wait.
This is reported by a static analysis tool named DCNS written by myself.
--- arch/x86/kernel/early-quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/early-quirks.c +1 -1
@@ -604,7 +604,7 @@ static void __init apple_airport_reset(int bus, int slot, int func)if ((pmcsr &PCI_PM_CTRL_STATE_MASK ) !=PCI_D0 ) { pmcsr &= ~PCI_PM_CTRL_STATE_MASK ;write_pci_config_16 (bus, slot, func,BCM4331_PM_CAP +PCI_PM_CTRL , pmcsr); -mdelay (10 ); +usleep_range (10000 ,11000 ); pmcsr =read_pci_config_16 (bus, slot, func,BCM4331_PM_CAP +PCI_PM_CTRL );if ((pmcsr &PCI_PM_CTRL_STATE_MASK ) !=PCI_D0 ) {
Signature · 1 line
1.7.9.5
Quoted 4 lines · Jia-Ju Bai
The function
apple_airport_resetis not called in atomic context. Thus mdelay can be replaced withusleep_range, to avoid busy wait.This is reported by a static analysis tool named DCNS written by myself.
No, usleep_range() is built on hrtimers and at this point in the boot sequence we haven't called hrtimers_init() yet.
Look at init/main.c:start_kernel() and note that setup_arch() (which calls early_quirks()) is called way before hrtimers_init().
Please amend your static checker to consider every call to mdelay() that occurs before hrtimers_init() a false positive, or manually verify each patch for this constraint before submission.
I'll test your patch later today on my MacBook Pro but I suspect it'll cause a boot crash or hang. In any case the choice of mdelay() here was deliberate.
Thanks,
Lukas
Quoted 22 lines
Signed-off-by Jia-Ju Bai <[email protected]>--- arch/x86/kernel/early-quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/early-quirks.c +1
-1@@ -604,7 +604,7 @@ static void __init apple_airport_reset(int bus, int slot, int func)if ((pmcsr &PCI_PM_CTRL_STATE_MASK ) !=PCI_D0 ) { pmcsr &= ~PCI_PM_CTRL_STATE_MASK ;write_pci_config_16 (bus, slot, func,BCM4331_PM_CAP +PCI_PM_CTRL , pmcsr); -mdelay (10 ); +usleep_range (10000 ,11000 ); pmcsr =read_pci_config_16 (bus, slot, func,BCM4331_PM_CAP +PCI_PM_CTRL );if ((pmcsr &PCI_PM_CTRL_STATE_MASK ) !=PCI_D0 ) {Signature · 1 line
1.7.9.5
Quoted 7 lines · Lukas Wunner
On Wed, Jan 24, 2018 at 10:38:22AM +0800, Jia-Ju Bai wrote:
Please amend your static checker to consider every call to
mdelay()that occurs beforehrtimers_init()a false positive, or manually verify each patch for this constraint before submission.In any case the choice of
mdelay()here was deliberate.
Perhaps, we need to put a comment for the next "Markus Elfring" crawler.
Signature · 2 lines
With Best Regards, Andy Shevchenko