]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drivers: base: devres: Allow to release group on device release
authorLucas De Marchi <lucas.demarchi@intel.com>
Sat, 22 Feb 2025 00:10:41 +0000 (16:10 -0800)
committerLucas De Marchi <lucas.demarchi@intel.com>
Tue, 25 Feb 2025 22:29:05 +0000 (14:29 -0800)
When releasing a device, if the release action causes a group to be
released, a warning is emitted because it can't find the group. This
happens because devres_release_all() moves the entire list to a todo
list and also move the group markers. Considering r* normal resource
nodes and g1 a group resource node:

    g1 -----------.
    v   v
r1 -> r2 -> g1[0] -> r3-> g[1] -> r4

After devres_release_all(), dev->devres_head becomes empty and the todo
list it iterates on becomes:

       g1
       v
r1 -> r2 -> r3-> r4 -> g1[0]

When a call to component_del() is made and takes down the aggregate
device, a warning like this happen:

RIP: 0010:devres_release_group+0x362/0x530
...
Call Trace:
 <TASK>
 component_unbind+0x156/0x380
 component_unbind_all+0x1d0/0x270
 mei_component_master_unbind+0x28/0x80 [mei_hdcp]
 take_down_aggregate_device+0xc1/0x160
 component_del+0x1c6/0x3e0
 intel_hdcp_component_fini+0xf1/0x170 [xe]
 xe_display_fini+0x1e/0x40 [xe]

Because the devres group corresponding to the hdcp component cannot be
found. Just ignore this corner case: if the dev->devres_head is empty
and the caller is trying to remove a group, it's likely in the process
of device cleanup so just ignore it instead of warning.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250222001051.3012936-2-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/base/devres.c

index 2152eec0c1352cc46bdef703123e9f2d718bf111..68224f2f83fff2653732070da146eecf3e48f8fe 100644 (file)
@@ -687,6 +687,13 @@ int devres_release_group(struct device *dev, void *id)
                spin_unlock_irqrestore(&dev->devres_lock, flags);
 
                release_nodes(dev, &todo);
+       } else if (list_empty(&dev->devres_head)) {
+               /*
+                * dev is probably dying via devres_release_all(): groups
+                * have already been removed and are on the process of
+                * being released - don't touch and don't warn.
+                */
+               spin_unlock_irqrestore(&dev->devres_lock, flags);
        } else {
                WARN_ON(1);
                spin_unlock_irqrestore(&dev->devres_lock, flags);