Call request_mem_region() on the entire coreboot table to make sure
other devices don't attempt to map the coreboot table in their drivers.
If drivers need that support, it would be better to provide bus APIs
they can use to do that through the mapping created in this file.

Cc: Wei-Ning Huang <[email protected]>
Cc: Julius Werner <[email protected]>
Cc: Brian Norris <[email protected]>
Cc: Samuel Holland <[email protected]>
Signed-off-by: Stephen Boyd <[email protected]>
---
 drivers/firmware/google/coreboot_table.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/google/coreboot_table.c 
b/drivers/firmware/google/coreboot_table.c
index 814913606d22..94c41d814ea5 100644
--- a/drivers/firmware/google/coreboot_table.c
+++ b/drivers/firmware/google/coreboot_table.c
@@ -132,6 +132,7 @@ static int coreboot_table_probe(struct platform_device 
*pdev)
        struct coreboot_table_header *header;
        struct resource *res;
        struct device *dev = &pdev->dev;
+       const char *name;
        void *ptr;
        int ret;
 
@@ -153,10 +154,17 @@ static int coreboot_table_probe(struct platform_device 
*pdev)
                return -ENODEV;
        }
 
-       ptr = devm_memremap(dev, res->start,
-                           header->header_bytes + header->table_bytes,
-                           MEMREMAP_WB);
+       len = header->header_bytes + header->table_bytes;
+       res->end = res->start + len - 1;
+       name = res->name ?: dev_name(dev);
        memunmap(header);
+
+       if (!devm_request_mem_region(dev, res->start, len, name)) {
+               dev_err(dev, "can't request region for resource %pR\n", res);
+               return -EBUSY;
+       }
+
+       ptr = devm_memremap(dev, res->start, len, MEMREMAP_WB);
        if (!ptr)
                return -ENOMEM;
 
-- 
Sent by a computer through tubes

Reply via email to