]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.97/net-phy-mdio_bus-add-missing-device_del-in-mdiobus_register-error-handling.patch
Linux 4.9.154
[thirdparty/kernel/stable-queue.git] / releases / 4.14.97 / net-phy-mdio_bus-add-missing-device_del-in-mdiobus_register-error-handling.patch
1 From foo@baz Sat Jan 26 10:34:35 CET 2019
2 From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
3 Date: Wed, 16 Jan 2019 10:53:58 +0100
4 Subject: net: phy: mdio_bus: add missing device_del() in mdiobus_register() error handling
5
6 From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
7
8 [ Upstream commit e40e2a2e78664fa90ea4b9bdf4a84efce2fea9d9 ]
9
10 The current code in __mdiobus_register() doesn't properly handle
11 failures returned by the devm_gpiod_get_optional() call: it returns
12 immediately, without unregistering the device that was added by the
13 call to device_register() earlier in the function.
14
15 This leaves a stale device, which then causes a NULL pointer
16 dereference in the code that handles deferred probing:
17
18 [ 1.489982] Unable to handle kernel NULL pointer dereference at virtual address 00000074
19 [ 1.498110] pgd = (ptrval)
20 [ 1.500838] [00000074] *pgd=00000000
21 [ 1.504432] Internal error: Oops: 17 [#1] SMP ARM
22 [ 1.509133] Modules linked in:
23 [ 1.512192] CPU: 1 PID: 51 Comm: kworker/1:3 Not tainted 4.20.0-00039-g3b73a4cc8b3e-dirty #99
24 [ 1.520708] Hardware name: Xilinx Zynq Platform
25 [ 1.525261] Workqueue: events deferred_probe_work_func
26 [ 1.530403] PC is at klist_next+0x10/0xfc
27 [ 1.534403] LR is at device_for_each_child+0x40/0x94
28 [ 1.539361] pc : [<c0683fbc>] lr : [<c0455d90>] psr: 200e0013
29 [ 1.545628] sp : ceeefe68 ip : 00000001 fp : ffffe000
30 [ 1.550863] r10: 00000000 r9 : c0c66790 r8 : 00000000
31 [ 1.556079] r7 : c0457d44 r6 : 00000000 r5 : ceeefe8c r4 : cfa2ec78
32 [ 1.562604] r3 : 00000064 r2 : c0457d44 r1 : ceeefe8c r0 : 00000064
33 [ 1.569129] Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
34 [ 1.576263] Control: 18c5387d Table: 0ed7804a DAC: 00000051
35 [ 1.582013] Process kworker/1:3 (pid: 51, stack limit = 0x(ptrval))
36 [ 1.588280] Stack: (0xceeefe68 to 0xceef0000)
37 [ 1.592630] fe60: cfa2ec78 c0c03c08 00000000 c0457d44 00000000 c0c66790
38 [ 1.600814] fe80: 00000000 c0455d90 ceeefeac 00000064 00000000 0d7a542e cee9d494 cfa2ec78
39 [ 1.608998] fea0: cfa2ec78 00000000 c0457d44 c0457d7c cee9d494 c0c03c08 00000000 c0455dac
40 [ 1.617182] fec0: cf98ba44 cf926a00 cee9d494 0d7a542e 00000000 cf935a10 cf935a10 cf935a10
41 [ 1.625366] fee0: c0c4e9b8 c0457d7c c0c4e80c 00000001 cf935a10 c0457df4 cf935a10 c0c4e99c
42 [ 1.633550] ff00: c0c4e99c c045a27c c0c4e9c4 ced63f80 cfde8a80 cfdebc00 00000000 c013893c
43 [ 1.641734] ff20: cfde8a80 cfde8a80 c07bd354 ced63f80 ced63f94 cfde8a80 00000008 c0c02d00
44 [ 1.649936] ff40: cfde8a98 cfde8a80 ffffe000 c0139a30 ffffe000 c0c6624a c07bd354 00000000
45 [ 1.658120] ff60: ffffe000 cee9e780 ceebfe00 00000000 ceeee000 ced63f80 c0139788 cf8cdea4
46 [ 1.666304] ff80: cee9e79c c013e598 00000001 ceebfe00 c013e44c 00000000 00000000 00000000
47 [ 1.674488] ffa0: 00000000 00000000 00000000 c01010e8 00000000 00000000 00000000 00000000
48 [ 1.682671] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
49 [ 1.690855] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000
50 [ 1.699058] [<c0683fbc>] (klist_next) from [<c0455d90>] (device_for_each_child+0x40/0x94)
51 [ 1.707241] [<c0455d90>] (device_for_each_child) from [<c0457d7c>] (device_reorder_to_tail+0x38/0x88)
52 [ 1.716476] [<c0457d7c>] (device_reorder_to_tail) from [<c0455dac>] (device_for_each_child+0x5c/0x94)
53 [ 1.725692] [<c0455dac>] (device_for_each_child) from [<c0457d7c>] (device_reorder_to_tail+0x38/0x88)
54 [ 1.734927] [<c0457d7c>] (device_reorder_to_tail) from [<c0457df4>] (device_pm_move_to_tail+0x28/0x40)
55 [ 1.744235] [<c0457df4>] (device_pm_move_to_tail) from [<c045a27c>] (deferred_probe_work_func+0x58/0x8c)
56 [ 1.753746] [<c045a27c>] (deferred_probe_work_func) from [<c013893c>] (process_one_work+0x210/0x4fc)
57 [ 1.762888] [<c013893c>] (process_one_work) from [<c0139a30>] (worker_thread+0x2a8/0x5c0)
58 [ 1.771072] [<c0139a30>] (worker_thread) from [<c013e598>] (kthread+0x14c/0x154)
59 [ 1.778482] [<c013e598>] (kthread) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
60 [ 1.785689] Exception stack(0xceeeffb0 to 0xceeefff8)
61 [ 1.790739] ffa0: 00000000 00000000 00000000 00000000
62 [ 1.798923] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
63 [ 1.807107] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000
64 [ 1.813724] Code: e92d47f0 e1a05000 e8900048 e1a00003 (e5937010)
65 [ 1.819844] ---[ end trace 3c2c0c8b65399ec9 ]---
66
67 The actual error that we had from devm_gpiod_get_optional() was
68 -EPROBE_DEFER, due to the GPIO being provided by a driver that is
69 probed later than the Ethernet controller driver.
70
71 To fix this, we simply add the missing device_del() invocation in the
72 error path.
73
74 Fixes: 69226896ad636 ("mdio_bus: Issue GPIO RESET to PHYs")
75 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
76 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
77 Signed-off-by: David S. Miller <davem@davemloft.net>
78 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
79 ---
80 drivers/net/phy/mdio_bus.c | 1 +
81 1 file changed, 1 insertion(+)
82
83 --- a/drivers/net/phy/mdio_bus.c
84 +++ b/drivers/net/phy/mdio_bus.c
85 @@ -358,6 +358,7 @@ int __mdiobus_register(struct mii_bus *b
86 if (IS_ERR(gpiod)) {
87 dev_err(&bus->dev, "mii_bus %s couldn't get reset GPIO\n",
88 bus->id);
89 + device_del(&bus->dev);
90 return PTR_ERR(gpiod);
91 } else if (gpiod) {
92 bus->reset_gpiod = gpiod;