The function sprd_clk_regmap_init() doesn't always return success,
drivers should return immediately when it fails ranther than
continue the clock initialization.
The patch 1/3 in this set switchs to use devm_ioremap_resources()
instead of of_iomap(), that will make caller programs more simple.
Chunyan Zhang (3):
clk: sprd: Switch from of_iomap() to devm_ioremap_resource()
clk: sprd: Check error only for devm_regmap_init_mmio()
clk: sprd: Add check the return value of sprd_clk_regmap_init()
drivers/clk/sprd/common.c | 9 +++++++--
drivers/clk/sprd/sc9860-clk.c | 4 +++-
2 files changed, 10 insertions(+), 3 deletions(-)
--
2.17.1
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 <[email protected]>
---
drivers/clk/sprd/common.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
index e038b0447206..9ce690999eaa 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,7 +51,11 @@ 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)) {
--
2.17.1
The function devm_regmap_init_mmio() wouldn't return NULL pointer for
now, so only need to ensure the return value is not an error code.
Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clk/sprd/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
index 9ce690999eaa..a5bdca1de5d0 100644
--- a/drivers/clk/sprd/common.c
+++ b/drivers/clk/sprd/common.c
@@ -58,7 +58,7 @@ int sprd_clk_regmap_init(struct platform_device *pdev,
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);
}
--
2.17.1
sprd_clk_regmap_init() doesn't always return success, adding check
for its return value should make the code more strong.
Signed-off-by: Chunyan Zhang <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
---
drivers/clk/sprd/sc9860-clk.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/sprd/sc9860-clk.c b/drivers/clk/sprd/sc9860-clk.c
index 9980ab55271b..1ed45b4f2fe8 100644
--- a/drivers/clk/sprd/sc9860-clk.c
+++ b/drivers/clk/sprd/sc9860-clk.c
@@ -2031,7 +2031,9 @@ static int sc9860_clk_probe(struct platform_device *pdev)
}
desc = match->data;
- sprd_clk_regmap_init(pdev, desc);
+ ret = sprd_clk_regmap_init(pdev, desc);
+ if (ret)
+ return ret;
return sprd_clk_probe(&pdev->dev, desc->hw_clks);
}
--
2.17.1
sprd_clk_regmap_init() doesn't always return success, adding check
for its return value should make the code more strong.
Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clk/sprd/sc9860-clk.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/sprd/sc9860-clk.c b/drivers/clk/sprd/sc9860-clk.c
index 9980ab55271b..1ed45b4f2fe8 100644
--- a/drivers/clk/sprd/sc9860-clk.c
+++ b/drivers/clk/sprd/sc9860-clk.c
@@ -2031,7 +2031,9 @@ static int sc9860_clk_probe(struct platform_device *pdev)
}
desc = match->data;
- sprd_clk_regmap_init(pdev, desc);
+ ret = sprd_clk_regmap_init(pdev, desc);
+ if (ret)
+ return ret;
return sprd_clk_probe(&pdev->dev, desc->hw_clks);
}
--
2.17.1
The function sprd_clk_regmap_init() doesn't always return success,
drivers should return immediately when it fails rather than
continue the clock initialization.
The patch 1/3 in this set switchs to use devm_ioremap_resources()
instead of of_iomap(), that will make caller programs more simple.
Changes from V1:
- Split out the patch 2/3 from 1/2 of the first version;
- Added reviewed-by from Baolin.
Chunyan Zhang (3):
clk: sprd: Switch from of_iomap() to devm_ioremap_resource()
clk: sprd: Check error only for devm_regmap_init_mmio()
clk: sprd: Add check the return value of sprd_clk_regmap_init()
drivers/clk/sprd/common.c | 9 +++++++--
drivers/clk/sprd/sc9860-clk.c | 4 +++-
2 files changed, 10 insertions(+), 3 deletions(-)
--
2.17.1
On Wed, 22 May 2019 at 09:15, Chunyan Zhang <[email protected]> wrote:
>
> The function devm_regmap_init_mmio() wouldn't return NULL pointer for
> now, so only need to ensure the return value is not an error code.
>
> Signed-off-by: Chunyan Zhang <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
> ---
> drivers/clk/sprd/common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
> index 9ce690999eaa..a5bdca1de5d0 100644
> --- a/drivers/clk/sprd/common.c
> +++ b/drivers/clk/sprd/common.c
> @@ -58,7 +58,7 @@ int sprd_clk_regmap_init(struct platform_device *pdev,
>
> 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);
> }
> --
> 2.17.1
>
--
Baolin Wang
Best Regards
On Wed, 22 May 2019 at 09:15, Chunyan Zhang <[email protected]> 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 <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
> ---
> drivers/clk/sprd/common.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
> index e038b0447206..9ce690999eaa 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,7 +51,11 @@ 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)) {
> --
> 2.17.1
>
--
Baolin Wang
Best Regards
Quoting Chunyan Zhang (2019-05-21 18:15:01)
> 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 <[email protected]>
Applied to clk-next
> diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
> index e038b0447206..9ce690999eaa 100644
> --- a/drivers/clk/sprd/common.c
> +++ b/drivers/clk/sprd/common.c
> @@ -50,7 +51,11 @@ 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))
There's also devm_platform_ioremap_resource() if you want to save even
more lines!
> + return PTR_ERR(base);
> +
Quoting Chunyan Zhang (2019-05-21 18:15:02)
> The function devm_regmap_init_mmio() wouldn't return NULL pointer for
> now, so only need to ensure the return value is not an error code.
>
> Signed-off-by: Chunyan Zhang <[email protected]>
> ---
Applied to clk-next
Quoting Chunyan Zhang (2019-05-21 18:15:03)
> sprd_clk_regmap_init() doesn't always return success, adding check
> for its return value should make the code more strong.
>
> Signed-off-by: Chunyan Zhang <[email protected]>
> Reviewed-by: Baolin Wang <[email protected]>
> ---
Applied to clk-next
On Thu, 27 Jun 2019 at 02:16, Stephen Boyd <[email protected]> wrote:
>
> Quoting Chunyan Zhang (2019-05-21 18:15:01)
> > 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 <[email protected]>
>
> Applied to clk-next
>
> > diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
> > index e038b0447206..9ce690999eaa 100644
> > --- a/drivers/clk/sprd/common.c
> > +++ b/drivers/clk/sprd/common.c
> > @@ -50,7 +51,11 @@ 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))
>
> There's also devm_platform_ioremap_resource() if you want to save even
> more lines!
Yes indeed, thanks for the information.
Considering this patch was queued to your tree, I decide to use this
more integrated function later :)
Cheers,
Chunyan
>
> > + return PTR_ERR(base);
> > +