We return immediately from i915_driver_register() if drm_dev_register()
fails, skipping remaining registration steps.  However, the _unregister()
counterpart called at device remove knows nothing about that skip and
executes reverts for all those steps.  For that to work correctly, those
revert functions must be resistant to being called even on uninitialized
objects, or we must not skip their initialization.

If device sysfs setup is skipped then its teardown counterpart,
unconditionally called when unregistering the driver, fails and emits
a warning that taints the kernel:

<3> [525.823143] i915 0000:00:02.0: [drm] *ERROR* Failed to register driver for 
userspace access!
...
<4> [526.441186] ------------[ cut here ]------------
<4> [526.441191] kernfs: can not remove 'error', no directory
<4> [526.441211] WARNING: CPU: 1 PID: 3440 at fs/kernfs/dir.c:1684 
kernfs_remove_by_name_ns+0xbc/0xc0
...
<4> [526.441536] RIP: 0010:kernfs_remove_by_name_ns+0xbc/0xc0
...
<4> [526.441578] Call Trace:
<4> [526.441581]  <TASK>
...
<4> [526.441686]  sysfs_remove_bin_file+0x17/0x30
<4> [526.441691]  i915_gpu_error_sysfs_teardown+0x1d/0x30 [i915]
<4> [526.442226]  i915_teardown_sysfs+0x1c/0x60 [i915]
<4> [526.442369]  i915_driver_remove+0x9d/0x140 [i915]
<4> [526.442473]  i915_pci_remove+0x1e/0x40 [i915]
...

Since restoring symmetry by setting up the device sysfs even after a
failure is not possible due to missing dependencies, teach the teardown
counterpart to handle all components of the never set up device sysfs
gently.

Link: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/9820
Link: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/10131
Link: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/10887
Link: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12817
Signed-off-by: Janusz Krzysztofik <janusz.krzyszto...@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_sysfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_sysfs.c 
b/drivers/gpu/drm/i915/i915_sysfs.c
index 8775beab9cb84..9758a7ca27fd2 100644
--- a/drivers/gpu/drm/i915/i915_sysfs.c
+++ b/drivers/gpu/drm/i915/i915_sysfs.c
@@ -189,6 +189,9 @@ void i915_teardown_sysfs(struct drm_i915_private *dev_priv)
 {
        struct device *kdev = dev_priv->drm.primary->kdev;
 
+       if (!dev_priv->sysfs_gt)
+               return;
+
        i915_gpu_error_sysfs_teardown(dev_priv);
 
        device_remove_bin_file(kdev, &dpf_attrs_1);
-- 
2.47.1

Reply via email to