]> git.baikalelectronics.ru Git - kernel.git/commitdiff
of: restricted dma: Fix condition for rmem init
authorDavid Brazdil <dbrazdil@google.com>
Fri, 17 Sep 2021 13:14:23 +0000 (14:14 +0100)
committerRob Herring <robh@kernel.org>
Fri, 17 Sep 2021 20:58:09 +0000 (15:58 -0500)
of_dma_set_restricted_buffer fails to handle negative return values from
of_property_count_elems_of_size, e.g. when the property does not exist.
This results in an attempt to assign a non-existent reserved memory
region to the device and a warning being printed. Fix the condition to
take negative values into account.

Fixes: 3b06c5856cdd ("of: restricted dma: Don't fail device probe on rmem init failure")
Cc: Will Deacon <will@kernel.org>
Signed-off-by: David Brazdil <dbrazdil@google.com>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210917131423.2760155-1-dbrazdil@google.com
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/device.c

index 5b043ee308240bf0d389e92aebb462dcb044382a..b0800c260f64a219848888eee8762fafee0aef64 100644 (file)
@@ -85,7 +85,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
                        break;
        }
 
-       if (i != count && of_reserved_mem_device_init_by_idx(dev, of_node, i))
+       /*
+        * Attempt to initialize a restricted-dma-pool region if one was found.
+        * Note that count can hold a negative error code.
+        */
+       if (i < count && of_reserved_mem_device_init_by_idx(dev, of_node, i))
                dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n");
 }