Protect __release_resource against resources without parents
authorPhil Elwell <phil@raspberrypi.org>
Fri, 13 Mar 2015 12:43:36 +0000 (12:43 +0000)
committerpopcornmix <popcornmix@gmail.com>
Wed, 27 Jan 2021 19:12:45 +0000 (19:12 +0000)
Without this patch, removing a device tree overlay can crash here.

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
kernel/resource.c

index 3ae2f56..2f1a85c 100644 (file)
@@ -214,6 +214,12 @@ static int __release_resource(struct resource *old, bool release_child)
 {
        struct resource *tmp, **p, *chd;
 
+       if (!old->parent) {
+               WARN(old->sibling, "sibling but no parent");
+               if (old->sibling)
+                       return -EINVAL;
+               return 0;
+       }
        p = &old->parent->child;
        for (;;) {
                tmp = *p;