Skip to contentSkip to conversation

misc: sram: fix check of devm_ioremap*() return value

PATCH In review Vladimir Zapolskiy 1 participant 2 messages Mar 23, 2016 – Apr 18, 2016 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 misc: sram: fix check of devm_ioremap*() return value

Both devm_ioremap() and devm_ioremap_wc() functions return either a pointer to valid iomem region or NULL, check for IS_ERR() is improper and may result in oops on error path. Now on error -ENOMEM is returned.

Fixes 0ab163ad1ea0 ("misc: sram: switch to ioremap_wc from ioremap")

---
I add Fixes: tag for reference, but unfortunately the change can not be cleanly applied to kernel versions liable to the problem.

Changes from v1 to v2:
- had to rebase on top of eb43e023130b ("misc: sram: add optional ioremap without write combining")
- slightly reworded the commit message and subject

v1 of the change: https://lkml.org/lkml/2016/3/6/202

 drivers/misc/sram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/sram.c +2 -2
index 69cdabe..f84b53d 100644
@@ -364,8 +364,8 @@ static int sram_probe(struct platform_device *pdev)
 		sram->virt_base = devm_ioremap(sram->dev, res->start, size);
 	else
 		sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
-	if (IS_ERR(sram->virt_base))
-		return PTR_ERR(sram->virt_base);
+	if (!sram->virt_base)
+		return -ENOMEM;
 
 	sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
 					  NUMA_NO_NODE, NULL);
Signature · 1 line
2.1.4
#1 lore raw

Hi Greg,

Quoted 10 lines · Vladimir Zapolskiy

Both devm_ioremap() and devm_ioremap_wc() functions return either a pointer to valid iomem region or NULL, check for IS_ERR() is improper and may result in oops on error path. Now on error -ENOMEM is returned.

Fixes 0ab163ad1ea0 ("misc: sram: switch to ioremap_wc from ioremap")

---
I add Fixes: tag for reference, but unfortunately the change can not be cleanly applied to kernel versions liable to the problem.

Quoted 6 lines

Changes from v1 to v2:
- had to rebase on top of eb43e023130b ("misc: sram: add optional ioremap without write combining")
- slightly reworded the commit message and subject

v1 of the change: https://lkml.org/lkml/2016/3/6/202

this is a trivial fix of a potential NULL pointer dereference, do you have any review comments?

Quoted 9 lines
 drivers/misc/sram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/sram.c +0 -0
index 69cdabe..f84b53d 100644

drivers/misc/sram.c static int sram_probe(struct platform_device *pdev) · line 371

Quoted 10 lines
drivers/misc/sram.c +2 -2
@@ -364,8 +364,8 @@ static int sram_probe(struct platform_device *pdev)
 		sram->virt_base = devm_ioremap(sram->dev, res->start, size);
 	else
 		sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
-	if (IS_ERR(sram->virt_base))
-		return PTR_ERR(sram->virt_base);
+	if (!sram->virt_base)
+		return -ENOMEM;
 
 	sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
 					  NUMA_NO_NODE, NULL);

--
With best wishes,
Vladimir