From: Srinivas Kandagatla <srinivas.kandaga...@linaro.org> Usecase: device_link consumer driver is removed when a remote processor is crashed or force stopped. In this case the device_link supplier is arm-smmu driver and consumer is rpmsg driver. device_link state in such case is updated from DL_STATE_ACTIVE to DL_STATE_AVAILABLE in __device_release_driver() call, However if device_links_purge() is called before this happens, then it would throw a warning about ACTIVE state of the link as shown in below log.
This patch moves call to device_links_purge() after bus_remove_device(), so that device link state is updated correctly before purge. ------------[ cut here ]------------ WARNING: CPU: 0 PID: 2180 at drivers/base/core.c:599 device_del+0x90/0x300 Modules linked in: CPU: 0 PID: 2180 Comm: bash Not tainted 4.11.0-00279-g4a4a8de-dirty #19 Hardware name: Qualcomm Technologies, Inc. DB820c (DT) task: ffff8000d74b0d80 task.stack: ffff8000d6d58000 PC is at device_del+0x90/0x300 LR is at device_del+0x4c/0x300 pc : [<ffff0000085eee90>] lr : [<ffff0000085eee4c>] pstate: 60000145 sp : ffff8000d6d5b9c0 x29: ffff8000d6d5b9c0 x28: ffff8000d74b0d80 x27: ffff000008b52000 x26: 0000000000000040 x25: 0000000000000124 x24: ffff8000d75c5410 x23: ffff8000d75c68b0 x22: ffff8000d75c5400 x21: ffff000009245000 x20: ffff8000d75c6810 x19: ffff8000d75c6890 x18: 0000000000000000 x17: 0000ffff9963f110 x16: ffff00000820132c x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000018 x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f x9 : 0000000040000000 x8 : 0000000000210d00 x7 : 0000000000000000 x6 : 0000000000000001 x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000000000000003 x0 : ffff8000d74e7380 ---[ end trace 73ceac58f2b5affd ]--- Call trace: Exception stack(0xffff8000d6d5b7f0 to 0xffff8000d6d5b920) b7e0: ffff8000d75c6890 0001000000000000 b800: ffff8000d6d5b9c0 ffff0000085eee90 ffff8000d6d5b860 ffff000008274fdc b820: ffff8000d6d5b940 ffff0000081e3ab0 ffff7e00035d7100 ffff8000d74b0d80 b840: ffff8000d6d5b960 ffff0000081e3ab0 ffff7e00035d6400 ffff8000d74b0d80 b860: ffff8000d6d5b980 ffff0000081e3ab0 ffff7e0003663200 ffff8000d74b0d80 b880: 00000000002f19c0 ffff8000d98c8100 ffff8000d74e7380 0000000000000003 b8a0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 b8c0: 0000000000000001 0000000000000000 0000000000210d00 0000000040000000 b8e0: 7f7f7f7f7f7f7f7f 0101010101010101 0000000000000018 0000000000000000 b900: 0000000000000000 0000000000000000 ffff00000820132c 0000ffff9963f110 [<ffff0000085eee90>] device_del+0x90/0x300 [<ffff0000085f5670>] platform_device_del+0x28/0x94 [<ffff0000085f56f0>] platform_device_unregister+0x14/0x2c [<ffff0000088fc150>] of_platform_device_destroy+0xa4/0xa8 [<ffff0000085ee104>] device_for_each_child+0x44/0x88 [<ffff0000088fc090>] of_platform_depopulate+0x30/0x4c [<ffff0000084ff6a4>] qcom_rpmsg_q6_remove+0x44/0x54 [<ffff00000890c2b0>] rpmsg_dev_remove+0x38/0x68 [<ffff0000085f3d60>] device_release_driver_internal+0x148/0x1c8 [<ffff0000085f3df4>] device_release_driver+0x14/0x1c [<ffff0000085f2854>] bus_remove_device+0xdc/0x150 [<ffff0000085eeff8>] device_del+0x1f8/0x300 [<ffff0000085ef11c>] device_unregister+0x1c/0x6c [<ffff00000890fba4>] qcom_smd_remove_device+0xc/0x18 [<ffff0000085ee104>] device_for_each_child+0x44/0x88 [<ffff00000890fb54>] qcom_smd_unregister_edge+0x3c/0x6c [<ffff000008909c48>] smd_subdev_remove+0x18/0x28 [<ffff000008907cb4>] rproc_shutdown+0x84/0x168 [<ffff000008908644>] state_store+0x94/0xec [<ffff0000085ed794>] dev_attr_store+0x18/0x28 [<ffff000008277d60>] sysfs_kf_write+0x40/0x50 [<ffff00000827705c>] kernfs_fop_write+0xb0/0x1d0 [<ffff0000081fed04>] __vfs_write+0x28/0x110 [<ffff0000081fffd4>] vfs_write+0xa0/0x190 [<ffff000008201370>] SyS_write+0x44/0xa0 [<ffff000008082f30>] el0_svc_naked+0x24/0x28 msm-pcm-dsp adsp-pil:smd-edge:apr:pcm0: Dropping the link to 1600000.arm,smmu-lpass_q6 iommu: Removing device adsp-pil:smd-edge:apr:pcm0 from group 1 remoteproc remoteproc0: stopped remote processor adsp-pil Signed-off-by: Srinivas Kandagatla <srinivas.kandaga...@linaro.org> --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 8dde934f8d15..6e38c6fdc3f4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1826,7 +1826,6 @@ void device_del(struct device *dev) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DEL_DEVICE, dev); - device_links_purge(dev); dpm_sysfs_remove(dev); if (parent) klist_del(&dev->p->knode_parent); @@ -1851,6 +1850,7 @@ void device_del(struct device *dev) device_remove_file(dev, &dev_attr_uevent); device_remove_attrs(dev); bus_remove_device(dev); + device_links_purge(dev); device_pm_remove(dev); driver_deferred_probe_del(dev); device_remove_properties(dev); -- 2.11.0