[PATCH v5] PCI: rcar-ep: Fix the issue of the name parameter when calling devm_request_mem_region()

From: kingdix10
Date: Wed Jan 08 2025 - 19:53:55 EST


From: King Dix <kingdix10@xxxxxx>

When using devm_request_mem_region() to request a resource and the name
parameter is a stack string variable, it may cause errors when executing
the command `cat /proc/iomem`. Depending on the content of the memory, the
manifestations of errors may vary. One possible output may be as follows:

$ cat /proc/iomem
30000000-37ffffff :
38000000-3fffffff :

Another possibility is that garbage characters may appear after the colon.
In very rare cases, if no NUL-terminator is found in memory, the system
might crash because the string iterator may access unmapped memory above
the stack.

Fix this by replacing outbound_name with the name of the previously
requested resource. With the patch applied, the output is as follows:

$ cat /proc/iomem
30000000-37ffffff : memory2
38000000-3fffffff : memory3

Fixes: 2a6d0d63d999 ("PCI: rcar: Add endpoint mode support")

Signed-off-by: King Dix <kingdix10@xxxxxx>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
---
Changes in v5:
- Add examples of error outputs to the comment.
Changes in v4:
- Add more information to the comment.
Changes in v3:
- Fix the spelling issue in the comment.
Changes in v2:
- Fix the code indentation issue.
---
drivers/pci/controller/pcie-rcar-ep.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pcie-rcar-ep.c b/drivers/pci/controller/pcie-rcar-ep.c
index 047e2cef5afc..c5e0d025bc43 100644
--- a/drivers/pci/controller/pcie-rcar-ep.c
+++ b/drivers/pci/controller/pcie-rcar-ep.c
@@ -107,7 +107,7 @@ static int rcar_pcie_parse_outbound_ranges(struct rcar_pcie_endpoint *ep,
}
if (!devm_request_mem_region(&pdev->dev, res->start,
resource_size(res),
- outbound_name)) {
+ res->name)) {
dev_err(pcie->dev, "Cannot request memory region %s.\n",
outbound_name);
return -EIO;
--
2.43.0