* [PATCH] kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset
@ 2018-01-24 2:38 Jia-Ju Bai
2018-01-24 5:33 ` Lukas Wunner
0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2018-01-24 2:38 UTC (permalink / raw)
To: tglx, mingo, hpa, paulo.r.zanoni, kstewart, gregkh, lukas
Cc: x86, linux-kernel, Jia-Ju Bai
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.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
arch/x86/kernel/early-quirks.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 1e82f78..559e81a 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -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) {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset
2018-01-24 2:38 [PATCH] kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset Jia-Ju Bai
@ 2018-01-24 5:33 ` Lukas Wunner
2018-01-24 16:13 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Lukas Wunner @ 2018-01-24 5:33 UTC (permalink / raw)
To: Jia-Ju Bai
Cc: tglx, mingo, hpa, paulo.r.zanoni, kstewart, gregkh, x86, linux-kernel
On Wed, Jan 24, 2018 at 10:38:22AM +0800, Jia-Ju Bai wrote:
> 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.
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
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
> arch/x86/kernel/early-quirks.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
> index 1e82f78..559e81a 100644
> --- a/arch/x86/kernel/early-quirks.c
> +++ b/arch/x86/kernel/early-quirks.c
> @@ -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) {
> --
> 1.7.9.5
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset
2018-01-24 5:33 ` Lukas Wunner
@ 2018-01-24 16:13 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2018-01-24 16:13 UTC (permalink / raw)
To: Lukas Wunner
Cc: Jia-Ju Bai, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
paulo.r.zanoni, kstewart, Greg Kroah-Hartman, x86,
Linux Kernel Mailing List
On Wed, Jan 24, 2018 at 7:33 AM, Lukas Wunner <lukas@wunner.de> wrote:
> 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 before hrtimers_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.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-24 16:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24 2:38 [PATCH] kernel: x86: early-quirks: Replace mdelay with usleep_range in apple_airport_reset Jia-Ju Bai
2018-01-24 5:33 ` Lukas Wunner
2018-01-24 16:13 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.