diff mbox series

[1/2] clk: sprd: Switch from of_iomap() to devm_ioremap_resource()

Message ID 20190521060952.2949-2-zhang.chunyan@linaro.org
State Superseded
Headers show
Series Return immediately if sprd_clk_regmap_init() fails | expand

Commit Message

Chunyan Zhang May 21, 2019, 6:09 a.m. UTC
devm_ioremap_resources() automatically requests resources and devm_ wrappers
do better error handling and unmapping of the I/O region when needed,
that would make drivers more clean and simple.

Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org>

---
 drivers/clk/sprd/common.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

-- 
2.17.1

Comments

(Exiting) Baolin Wang May 21, 2019, 6:38 a.m. UTC | #1
Hi Chunyan,

On Tue, 21 May 2019 at 14:15, Chunyan Zhang <zhang.chunyan@linaro.org> wrote:
>

> devm_ioremap_resources() automatically requests resources and devm_ wrappers

> do better error handling and unmapping of the I/O region when needed,

> that would make drivers more clean and simple.

>

> Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org>

> ---

>  drivers/clk/sprd/common.c | 9 +++++++--

>  1 file changed, 7 insertions(+), 2 deletions(-)

>

> diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c

> index e038b0447206..a5bdca1de5d0 100644

> --- a/drivers/clk/sprd/common.c

> +++ b/drivers/clk/sprd/common.c

> @@ -42,6 +42,7 @@ int sprd_clk_regmap_init(struct platform_device *pdev,

>         void __iomem *base;

>         struct device_node *node = pdev->dev.of_node;

>         struct regmap *regmap;

> +       struct resource *res;

>

>         if (of_find_property(node, "sprd,syscon", NULL)) {

>                 regmap = syscon_regmap_lookup_by_phandle(node, "sprd,syscon");

> @@ -50,10 +51,14 @@ int sprd_clk_regmap_init(struct platform_device *pdev,

>                         return PTR_ERR(regmap);

>                 }

>         } else {

> -               base = of_iomap(node, 0);

> +               res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

> +               base = devm_ioremap_resource(&pdev->dev, res);

> +               if (IS_ERR(base))

> +                       return PTR_ERR(base);

> +

>                 regmap = devm_regmap_init_mmio(&pdev->dev, base,

>                                                &sprdclk_regmap_config);

> -               if (IS_ERR_OR_NULL(regmap)) {

> +               if (IS_ERR(regmap)) {


You did not mention this fix in your commit message, and it's better
to move into one separate patch.

>                         pr_err("failed to init regmap\n");

>                         return PTR_ERR(regmap);

>                 }

> --

> 2.17.1

>



-- 
Baolin Wang
Best Regards
Stephen Boyd May 21, 2019, 6:57 p.m. UTC | #2
Quoting Baolin Wang (2019-05-20 23:38:03)
> On Tue, 21 May 2019 at 14:15, Chunyan Zhang <zhang.chunyan@linaro.org> wrote:

> >                                                &sprdclk_regmap_config);

> > -               if (IS_ERR_OR_NULL(regmap)) {

> > +               if (IS_ERR(regmap)) {

> 

> You did not mention this fix in your commit message, and it's better

> to move into one separate patch.

> 


Please resend with it split out.
diff mbox series

Patch

diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
index e038b0447206..a5bdca1de5d0 100644
--- a/drivers/clk/sprd/common.c
+++ b/drivers/clk/sprd/common.c
@@ -42,6 +42,7 @@  int sprd_clk_regmap_init(struct platform_device *pdev,
 	void __iomem *base;
 	struct device_node *node = pdev->dev.of_node;
 	struct regmap *regmap;
+	struct resource *res;
 
 	if (of_find_property(node, "sprd,syscon", NULL)) {
 		regmap = syscon_regmap_lookup_by_phandle(node, "sprd,syscon");
@@ -50,10 +51,14 @@  int sprd_clk_regmap_init(struct platform_device *pdev,
 			return PTR_ERR(regmap);
 		}
 	} else {
-		base = of_iomap(node, 0);
+		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		base = devm_ioremap_resource(&pdev->dev, res);
+		if (IS_ERR(base))
+			return PTR_ERR(base);
+
 		regmap = devm_regmap_init_mmio(&pdev->dev, base,
 					       &sprdclk_regmap_config);
-		if (IS_ERR_OR_NULL(regmap)) {
+		if (IS_ERR(regmap)) {
 			pr_err("failed to init regmap\n");
 			return PTR_ERR(regmap);
 		}