mailbox: zynqmp: Fix off by 1 errors
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Mon, 28 Jul 2025 15:47:09 +0000 (16:47 +0100)
committerMichal Simek <michal.simek@amd.com>
Mon, 25 Aug 2025 14:20:47 +0000 (16:20 +0200)
Use resource_size to correctly calculate the size to pass to
devm_ioremap and avoid the off by 1 errors previously present.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Link: https://lore.kernel.org/r/20250728-zynqmp-ipi-v1-1-b2bd144a9521@linaro.org
Signed-off-by: Michal Simek <michal.simek@amd.com>
drivers/mailbox/zynqmp-ipi.c

index 851aa73..f622773 100644 (file)
@@ -188,7 +188,7 @@ static int zynqmp_ipi_dest_probe(struct udevice *dev)
                return -EINVAL;
        };
        zynqmp->local_req_regs = devm_ioremap(dev, res.start,
-                                             (res.start - res.end));
+                                             resource_size(&res));
        if (!zynqmp->local_req_regs)
                return -EINVAL;
 
@@ -197,7 +197,7 @@ static int zynqmp_ipi_dest_probe(struct udevice *dev)
                return -EINVAL;
        };
        zynqmp->local_res_regs = devm_ioremap(dev, res.start,
-                                             (res.start - res.end));
+                                             resource_size(&res));
        if (!zynqmp->local_res_regs)
                return -EINVAL;
 
@@ -206,7 +206,7 @@ static int zynqmp_ipi_dest_probe(struct udevice *dev)
                return -EINVAL;
        };
        zynqmp->remote_req_regs = devm_ioremap(dev, res.start,
-                                              (res.start - res.end));
+                                              resource_size(&res));
        if (!zynqmp->remote_req_regs)
                return -EINVAL;
 
@@ -215,7 +215,7 @@ static int zynqmp_ipi_dest_probe(struct udevice *dev)
                return -EINVAL;
        };
        zynqmp->remote_res_regs = devm_ioremap(dev, res.start,
-                                              (res.start - res.end));
+                                              resource_size(&res));
        if (!zynqmp->remote_res_regs)
                return -EINVAL;