From 67fa4436546ccfc4ae883366b9d75aca008fe591 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Wed, 17 Oct 2018 08:44:18 +0200
Subject: [PATCH 1/2] serial: pl011: use device_initcall

When the test 'CONFIG_DEBUG_TEST_DRIVER_REMOVE=y' is enabled, the
following 'Call trace' shows up due to that the pl011 driver get
initiated to late.

[    0.332075] Serial: AMBA PL011 UART driver
[    0.485276] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 39, base_baud = 0) is a PL011 rev1
[    0.502382] console [ttyAMA0] enabled
[    0.515710] Unable to handle kernel paging request at virtual address 0000800074c12000
[    0.516053] Mem abort info:
[    0.516222]   ESR = 0x96000004
[    0.516417]   Exception class = DABT (current EL), IL = 32 bits
[    0.516641]   SET = 0, FnV = 0
[    0.516826]   EA = 0, S1PTW = 0
[    0.516984] Data abort info:
[    0.517149]   ISV = 0, ISS = 0x00000004
[    0.517339]   CM = 0, WnR = 0
[    0.517553] [0000800074c12000] user address but active_mm is swapper
[    0.517928] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[    0.518305] Modules linked in:
[    0.518839] CPU: 0 PID: 13 Comm: kdevtmpfs Not tainted 4.19.0-rc5-next-20180928-00002-g2ba39ab0cd01-dirty #82
[    0.519307] Hardware name: linux,dummy-virt (DT)
[    0.519681] pstate: 80000005 (Nzcv daif -PAN -UAO)
[    0.519959] pc : __destroy_inode+0x94/0x2a8
[    0.520212] lr : __destroy_inode+0x78/0x2a8
[    0.520401] sp : ffff0000098c3b20
[    0.520590] x29: ffff0000098c3b20 x28: 00000000087a3714
[    0.520904] x27: 0000000000002000 x26: 0000000000002000
[    0.521179] x25: ffff000009583000 x24: 0000000000000000
[    0.521467] x23: ffff80007bb52000 x22: ffff80007bbaa7c0
[    0.521737] x21: ffff0000093f9338 x20: 0000000000000000
[    0.522033] x19: ffff80007bbb05d8 x18: 0000000000000400
[    0.522376] x17: 0000000000000000 x16: 0000000000000000
[    0.522727] x15: 0000000000000400 x14: 0000000000000400
[    0.523068] x13: 0000000000000001 x12: 0000000000000001
[    0.523421] x11: 0000000000000000 x10: 0000000000000970
[    0.523749] x9 : ffff0000098c3a60 x8 : ffff80007bbab190
[    0.524017] x7 : ffff80007bbaa880 x6 : 0000000000000c88
[    0.524305] x5 : ffff0000093d96c8 x4 : 61c8864680b583eb
[    0.524567] x3 : ffff0000093d6180 x2 : ffffffffffffffff
[    0.524872] x1 : 0000800074c12000 x0 : 0000800074c12000
[    0.525207] Process kdevtmpfs (pid: 13, stack limit = 0x(____ptrval____))
[    0.525529] Call trace:
[    0.525806]  __destroy_inode+0x94/0x2a8
[    0.526108]  destroy_inode+0x34/0x88
[    0.526370]  evict+0x144/0x1c8
[    0.526636]  iput+0x184/0x230
[    0.526871]  dentry_unlink_inode+0x118/0x130
[    0.527152]  d_delete+0xd8/0xe0
[    0.527420]  vfs_unlink+0x240/0x270
[    0.527665]  handle_remove+0x1d8/0x330
[    0.527875]  devtmpfsd+0x138/0x1c8
[    0.528085]  kthread+0x14c/0x158
[    0.528291]  ret_from_fork+0x10/0x18
[    0.528720] Code: 92800002 aa1403e0 d538d081 8b010000 (c85f7c04)
[    0.529367] ---[ end trace 5a3dee47727f877c ]---
[    0.529957] note: kdevtmpfs[13] exited with preempt_count 2
[    0.543016] Unable to handle kernel NULL pointer dereference at virtual address 000000000000001c
[    0.543409] Mem abort info:
[    0.543610]   ESR = 0x96000004
[    0.543832]   Exception class = DABT (current EL), IL = 32 bits
[    0.544123]   SET = 0, FnV = 0
[    0.544326]   EA = 0, S1PTW = 0
[    0.544505] Data abort info:
[    0.544699]   ISV = 0, ISS = 0x00000004
[    0.544925]   CM = 0, WnR = 0
[    0.545152] [000000000000001c] user address but active_mm is swapper
[    0.545501] Internal error: Oops: 96000004 [#2] PREEMPT SMP
[    0.545774] Modules linked in:
[    0.546167] CPU: 0 PID: 15 Comm: kworker/u2:1 Tainted: G      D           4.19.0-rc5-next-20180928-00002-g2ba39ab0cd01-dirty #82
[    0.546651] Hardware name: linux,dummy-virt (DT)
[    0.547110] Workqueue: netns cleanup_net
[    0.547387] pstate: 80000085 (Nzcv daIf -PAN -UAO)
[    0.547637] pc : put_ucounts+0x28/0xa8
[    0.547885] lr : put_ucounts+0x24/0xa8
[    0.548073] sp : ffff0000098d3cc0
[    0.548258] x29: ffff0000098d3cc0 x28: ffff0000093d9000
[    0.548630] x27: 0000000000000088 x26: ffff00000950b000
[    0.548979] x25: ffff0000098d3da8 x24: 0000000000000000
[    0.549331] x23: ffff80007b806000 x22: 0000000000000004
[    0.549670] x21: 0000000000000000 x20: ffff000009533000
[    0.550021] x19: 0000000000000000 x18: 0000000000000400
[    0.550372] x17: 0000000000000000 x16: 0000000000000000
[    0.550676] x15: 0000000000000000 x14: 0000000000000400
[    0.550939] x13: 00000000000002d0 x12: 00000000001df0e0
[    0.551307] x11: 0000000000000776 x10: 0000000000000970
[    0.551672] x9 : ffff0000098d3b00 x8 : ffff80007bbacc10
[    0.551954] x7 : 0000000000000000 x6 : ffff80007bba80f0
[    0.552239] x5 : 000000001f093800 x4 : 0000000000000000
[    0.552520] x3 : ffff000009533328 x2 : 0000000000000001
[    0.552799] x1 : 0000000000000000 x0 : 0000000000000000
[    0.553103] Process kworker/u2:1 (pid: 15, stack limit = 0x(____ptrval____))
[    0.553333] Call trace:
[    0.553534]  put_ucounts+0x28/0xa8
[    0.553749]  dec_ucount+0xa4/0xc8
[    0.553985]  cleanup_net+0x2d4/0x358
[    0.554221]  process_one_work+0x20c/0x3b8
[    0.554449]  worker_thread+0x54/0x520
[    0.554672]  kthread+0x14c/0x158
[    0.554888]  ret_from_fork+0x10/0x18
[    0.555157] Code: f000a0b4 910ca280 94314bce aa0003f5 (b9401e60)
[    0.555440] ---[ end trace 5a3dee47727f877d ]---

Rework so that pl011_init is called from device_initcall rather than arch_initcall.

Cc: Arnd Bergmann <arnd@arndb.de>
Co-developed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 drivers/tty/serial/amba-pl011.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index ebd33c0232e6..cc611bba5927 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2833,7 +2833,7 @@ static void __exit pl011_exit(void)
  * While this can be a module, if builtin it's most likely the console
  * So let's leave module_exit but move module_init to an earlier place
  */
-arch_initcall(pl011_init);
+device_initcall(pl011_init);
 module_exit(pl011_exit);
 
 MODULE_AUTHOR("ARM Ltd/Deep Blue Solutions Ltd");
-- 
2.19.1

