The current error handling in exynos_srom_probe() has a resource leak
in the of_platform_populate() failure path. When this function fails
after successful resource allocation, srom->reg_base is not released.
To fix this issue, replace of_iomap() with
devm_platform_ioremap_resource(). devm_platform_ioremap_resource()
is a specialized function for platform devices.
It allows 'srom->reg_base' to be automatically released whether the
probe function succeeds or fails.
Besides, use IS_ERR() instead of !srom->reg_base
as the return value of devm_platform_ioremap_resource()
can either be a pointer to the remapped memory or
an ERR_PTR() encoded error code if the operation fails.
Signed-off-by: Zhen Ni <redacted>
---
drivers/memory/samsung/exynos-srom.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
From: Krzysztof Kozlowski <krzk@kernel.org> Date: 2025-07-31 09:06:12
On 31/07/2025 10:33, Zhen Ni wrote:
The current error handling in exynos_srom_probe() has a resource leak
in the of_platform_populate() failure path. When this function fails
after successful resource allocation, srom->reg_base is not released.
To fix this issue, replace of_iomap() with
devm_platform_ioremap_resource(). devm_platform_ioremap_resource()
is a specialized function for platform devices.
Don't explain us kernel code. Drop sentence.
It allows 'srom->reg_base' to be automatically released whether the
probe function succeeds or fails.
It's obvious.
Besides, use IS_ERR() instead of !srom->reg_base
I don't understand this. You keep explaining the code and this suggests
you made change here not related to original case. Can you return
srom->reg_base here? No?
as the return value of devm_platform_ioremap_resource()
can either be a pointer to the remapped memory or
an ERR_PTR() encoded error code if the operation fails.
Problem analysis:
1. In exynos_srom_probe(), the reg_base resource is acquired via of_iomap()
2. The of_platform_populate() call at the end of the function has a
possible failure path:
root=root?of_node_get(root):of_find_node_by_path("/");if(!root)return-EINVAL;// Failure return point
3. When this path is taken, reg_base is not released, causing a resource
leak
Verification:
After applying the patch, the Smatch warning is resolved
Best regards,
Zhen
在 2025/7/31 17:06, Krzysztof Kozlowski 写道:
On 31/07/2025 10:33, Zhen Ni wrote:
quoted
The current error handling in exynos_srom_probe() has a resource leak
in the of_platform_populate() failure path. When this function fails
after successful resource allocation, srom->reg_base is not released.
To fix this issue, replace of_iomap() with
devm_platform_ioremap_resource(). devm_platform_ioremap_resource()
is a specialized function for platform devices.
Don't explain us kernel code. Drop sentence.
quoted
It allows 'srom->reg_base' to be automatically released whether the
probe function succeeds or fails.
It's obvious.
quoted
Besides, use IS_ERR() instead of !srom->reg_base
I don't understand this. You keep explaining the code and this suggests
you made change here not related to original case. Can you return
srom->reg_base here? No?
quoted
as the return value of devm_platform_ioremap_resource()
can either be a pointer to the remapped memory or
an ERR_PTR() encoded error code if the operation fails.
The of_platform_populate() call at the end of the function has a
possible failure path, causing a resource leak.
Replace of_iomap() with devm_platform_ioremap_resource() to ensure
automatic cleanup of srom->reg_base.
This issue was detected by smatch static analysis:
drivers/memory/samsung/exynos-srom.c:155 exynos_srom_probe()warn:
'srom->reg_base' from of_iomap() not released on lines: 155.
Fixes: 8ac2266d8831 ("memory: samsung: exynos-srom: Add support for bank configuration")
Cc: stable@vger.kernel.org
Signed-off-by: Zhen Ni <redacted>
---
chanegs in v2:
- Update commit msg
---
drivers/memory/samsung/exynos-srom.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
From: Krzysztof Kozlowski <hidden> Date: 2025-08-13 10:30:08
On Wed, 06 Aug 2025 10:55:38 +0800, Zhen Ni wrote:
The of_platform_populate() call at the end of the function has a
possible failure path, causing a resource leak.
Replace of_iomap() with devm_platform_ioremap_resource() to ensure
automatic cleanup of srom->reg_base.
This issue was detected by smatch static analysis:
drivers/memory/samsung/exynos-srom.c:155 exynos_srom_probe()warn:
'srom->reg_base' from of_iomap() not released on lines: 155.
[...]