Skip to contentSkip to conversation

mfd: syscon: Re-use resource_size() to count max_register

PATCH Applied Andy Shevchenko 3 participants 6 messages Nov 15, 2019 – Dec 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mfd: syscon: Re-use resource_size() to count max_register

Instead of open coded variant use resource_size() and replace weird '- 3' to more understandable '- 4'.

---
 drivers/mfd/syscon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/syscon.c +1 -1
index e22197c832e8..13626bb2d432 100644
@@ -245,7 +245,7 @@ static int syscon_probe(struct platform_device *pdev)
 	if (!base)
 		return -ENOMEM;
 
-	syscon_config.max_register = res->end - res->start - 3;
+	syscon_config.max_register = resource_size(res) - 4;
 	if (pdata)
 		syscon_config.name = pdata->label;
 	syscon->regmap = devm_regmap_init_mmio(dev, base, &syscon_config);
Signature · 1 line
2.24.0
#1 lore raw

PATCH 2/2 mfd: syscon: Switch to use devm_ioremap_resource()

Instead of checking resource pointer for being NULL and report some not very standard error codes in this case, switch to devm_ioremap_resource() API.

---
 drivers/mfd/syscon.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mfd/syscon.c +3 -6
index 13626bb2d432..fad961b2e4a5 100644
@@ -238,12 +238,9 @@ static int syscon_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENOENT;
-
-	base = devm_ioremap(dev, res->start, resource_size(res));
-	if (!base)
-		return -ENOMEM;
+	base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 
 	syscon_config.max_register = resource_size(res) - 4;
 	if (pdata)
Signature · 1 line
2.24.0
maintainer
#2 lore raw

Re: [PATCH v1 2/2] mfd: syscon: Switch to use devm_ioremap_resource()

Quoted 6 lines · Andy Shevchenko

Instead of checking resource pointer for being NULL and report some not very standard error codes in this case, switch to devm_ioremap_resource() API.

IIRC there are some slightly odd uses of syscon that rely on on us not calling devm_request_mem_region here, which is implied by devm_ioremap_resource() but not devm_ioremap().

A patch to add a comment about this might be helpful though.

Arnd

Quoted 27 lines
---
 drivers/mfd/syscon.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mfd/syscon.c +3 -7
index 13626bb2d432..fad961b2e4a5 100644
@@ -238,12 +238,9 @@ static int syscon_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!res)
-               return -ENOENT;
-
-       base = devm_ioremap(dev, res->start, resource_size(res));
-       if (!base)
-               return -ENOMEM;
+       base = devm_ioremap_resource(dev, res);
+       if (IS_ERR(base))
+               return PTR_ERR(base);
 
        syscon_config.max_register = resource_size(res) - 4;
        if (pdata)
--

2.24.0

#3 lore raw

Re: [PATCH v1 2/2] mfd: syscon: Switch to use devm_ioremap_resource()

Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Andy Shevchenko

Instead of checking resource pointer for being NULL and report some not very standard error codes in this case, switch to devm_ioremap_resource() API.

Quoted 5 lines
Quoted 1 line

IIRC there are some slightly odd uses of syscon that rely on on us not calling devm_request_mem_region here, which is implied by devm_ioremap_resource() but not devm_ioremap().

Ah, I see.

Quoted 1 line

A patch to add a comment about this might be helpful though.

I think the comment won't help if there are overlapping regions are in use. Probably no need to apply this for now.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by on v1 1/2
#4 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

Instead of open coded variant use resource_size() and replace weird '- 3' to more understandable '- 4'.

---

Quoted 19 lines
 drivers/mfd/syscon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/syscon.c +1 -2
index e22197c832e8..13626bb2d432 100644
@@ -245,7 +245,7 @@ static int syscon_probe(struct platform_device *pdev)
        if (!base)
                return -ENOMEM;
 
-       syscon_config.max_register = res->end - res->start - 3;
+       syscon_config.max_register = resource_size(res) - 4;
        if (pdata)
                syscon_config.name = pdata->label;
        syscon->regmap = devm_regmap_init_mmio(dev, base, &syscon_config);
--

2.24.0

Applied
#5 lore raw
In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko

Instead of open coded variant use resource_size() and replace weird '- 3' to more understandable '- 4'.

---
 drivers/mfd/syscon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog