drivers/thermal/k3: Convert to devm_platform_ioremap_resource()
Subsystems (5)
PATCH 1/6 drivers/thermal/k3: Convert to devm_platform_ioremap_resource()
Use devm_platform_ioremap_resource() to simplify code.
--- drivers/thermal/k3_bandgap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/thermal/k3_bandgap.c +1 -3
@@ -160,7 +160,6 @@ static const struct of_device_id of_k3_bandgap_match[];static int k3_bandgap_probe (struct platform_device *pdev) {int ret =0 , cnt, val, id; -struct resource *res;struct device *dev = &pdev->dev;struct k3_bandgap *bgp;struct k3_thermal_data *data;
@@ -173,8 +172,7 @@ static int k3_bandgap_probe(struct platform_device *pdev)if (!bgp)return -ENOMEM ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - bgp->base =devm_ioremap_resource (dev, res); + bgp->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (bgp->base))return PTR_ERR (bgp->base);
Signature · 1 line
2.39.0
PATCH 2/6 thermal/drivers/k3_j72xx_bandgap: Convert to devm_platform_ioremap_resource()
Use devm_platform_ioremap_resource() to simplify code.
--- drivers/thermal/k3_j72xx_bandgap.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/thermal/k3_j72xx_bandgap.c +3 -7
@@ -346,7 +346,6 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) {int ret =0 , cnt, val, id;int high_max, low_temp; -struct resource *res;struct device *dev = &pdev->dev;struct k3_j72xx_bandgap *bgp;struct k3_thermal_data *data;
@@ -376,13 +375,11 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev)return -ENOMEM ; bgp->dev = dev; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - bgp->base =devm_ioremap_resource (dev, res); + bgp->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (bgp->base))return PTR_ERR (bgp->base); - res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); - bgp->cfg2_base =devm_ioremap_resource (dev, res); + bgp->cfg2_base =devm_platform_ioremap_resource (pdev,1 );if (IS_ERR (bgp->cfg2_base))return PTR_ERR (bgp->cfg2_base);
@@ -400,8 +397,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev)* https://www.ti.com/lit/er/sprz455c/sprz455c.pdf */ if (workaround_needed) { - res =platform_get_resource (pdev,IORESOURCE_MEM ,2 ); - fuse_base =devm_ioremap_resource (dev, res); + fuse_base =devm_platform_ioremap_resource (pdev,2 );if (IS_ERR (fuse_base))return PTR_ERR (fuse_base);
Signature · 1 line
2.39.0
PATCH 3/6 thermal/drivers/qcom: Convert to devm_platform_ioremap_resource()
In reply to Yangtao LiUse devm_platform_ioremap_resource() to simplify code.
--- drivers/thermal/qcom/tsens.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/thermal/qcom/tsens.c +2 -5
@@ -890,7 +890,6 @@ int __init init_common(struct tsens_priv *priv)void __iomem *tm_base, *srot_base;struct device *dev = priv->dev;u32 ver_minor; -struct resource *res;u32 enabled;int ret, i, j;struct platform_device *op =of_find_device_by_node (priv->dev->of_node);
@@ -901,8 +900,7 @@ int __init init_common(struct tsens_priv *priv)if (op->num_resources >1 ) {/* DT with separate SROT and TM address space */ priv->tm_offset =0 ; - res =platform_get_resource (op,IORESOURCE_MEM ,1 ); - srot_base =devm_ioremap_resource (dev, res); + srot_base =devm_platform_ioremap_resource (op,1 );if (IS_ERR (srot_base)) { ret =PTR_ERR (srot_base); goto err_put_device;
@@ -920,8 +918,7 @@ int __init init_common(struct tsens_priv *priv) }if (tsens_version (priv) >=VER_0_1 ) { - res =platform_get_resource (op,IORESOURCE_MEM ,0 ); - tm_base =devm_ioremap_resource (dev, res); + tm_base =devm_platform_ioremap_resource (op,0 );if (IS_ERR (tm_base)) { ret =PTR_ERR (tm_base); goto err_put_device;
Signature · 1 line
2.39.0
PATCH 4/6 drivers/thermal/rcar_gen3_thermal: Convert to devm_platform_ioremap_resource()
In reply to Yangtao LiUse devm_platform_ioremap_resource() to simplify code.
--- drivers/thermal/rcar_gen3_thermal.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/thermal/rcar_gen3_thermal.c +1 -6
@@ -481,7 +481,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) {struct rcar_gen3_thermal_priv *priv;struct device *dev = &pdev->dev; -struct resource *res;struct thermal_zone_device *zone;unsigned int i;int ret;
@@ -504,17 +503,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)for (i =0 ; i <TSC_MAX_NUM ; i++) {struct rcar_gen3_thermal_tsc *tsc; - res =platform_get_resource (pdev,IORESOURCE_MEM , i); -if (!res) -break ; - tsc =devm_kzalloc (dev,sizeof (*tsc),GFP_KERNEL );if (!tsc) { ret = -ENOMEM ; goto error_unregister; } - tsc->base =devm_ioremap_resource (dev, res); + tsc->base =devm_platform_ioremap_resource (pdev, i);if (IS_ERR (tsc->base)) { ret =PTR_ERR (tsc->base); goto error_unregister;
Signature · 1 line
2.39.0
Re: [PATCH 4/6] drivers/thermal/rcar_gen3_thermal: Convert to devm_platform_ioremap_resource()
Hi Yangtao,
Thanks for your work.
Quoted 3 lines · Yangtao Li
Use
devm_platform_ioremap_resource()to simplify code.Signed-off-by Yangtao Li <[email protected]>
This do indeed simplify the code, but it also breaks the driver :-)
Before the change, failing to find a resource at position "i", breaks the probe loop, and probing continues and the number of resource described are the number of TSC find are used.
After the change failing to find all possible TCS will fail the whole probe process, even if some TCS where described. And not describing max number of TCS on each system is perfectly fine.
Quoted 38 lines
--- drivers/thermal/rcar_gen3_thermal.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/thermal/rcar_gen3_thermal.c +1
-6@@ -481,7 +481,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) {struct rcar_gen3_thermal_priv *priv;struct device *dev = &pdev->dev; -struct resource *res;struct thermal_zone_device *zone;unsigned int i;int ret;@@ -504,17 +503,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)for (i =0 ; i <TSC_MAX_NUM ; i++) {struct rcar_gen3_thermal_tsc *tsc; - res =platform_get_resource (pdev,IORESOURCE_MEM , i); -if (!res) -break ; - tsc =devm_kzalloc (dev,sizeof (*tsc),GFP_KERNEL );if (!tsc) { ret = -ENOMEM ; goto error_unregister; } - tsc->base =devm_ioremap_resource (dev, res); + tsc->base =devm_platform_ioremap_resource (pdev, i);if (IS_ERR (tsc->base)) { ret =PTR_ERR (tsc->base); goto error_unregister;Signature · 1 line
2.39.0
Signature · 2 lines
Kind Regards, Niklas Söderlund
Re: [PATCH 4/6] drivers/thermal/rcar_gen3_thermal: Convert to devm_platform_ioremap_resource()
Hi Niklas,
Quoted 9 lines · Niklas Söderlund
Hi Yangtao,
Thanks for your work.
Quoted 3 lines · Yangtao Li
Use
devm_platform_ioremap_resource()to simplify code.Signed-off-by Yangtao Li <[email protected]>This do indeed simplify the code, but it also breaks the driver :-)
How about the patch below? Can the following rcar driver also take a similar approach?
drivers/thermal/rcar_gen3_thermal.c +0 -0
@@ -481,7 +481,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
{
struct rcar_gen3_thermal_priv *priv;
struct device *dev = &pdev->dev;
- struct resource *res;
struct thermal_zone_device *zone;
unsigned int i;
int ret;
@@ -503,22 +502,23 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
for (i = 0; i < TSC_MAX_NUM; i++) { struct rcar_gen3_thermal_tsc *tsc; + void __iomem *base;
- res = platform_get_resource(pdev, IORESOURCE_MEM, i); - if (!res)
- break;
+ base = devm_platform_ioremap_resource(pdev, i); + if (IS_ERR(base)) {
+ if (PTR_ERR(base) == -EINVAL)
+ break;
- tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); - if (!tsc) {
- ret = -ENOMEM;
+ ret = PTR_ERR(base);
goto error_unregister;
}
- tsc->base = devm_ioremap_resource(dev, res); - if (IS_ERR(tsc->base)) {
- ret = PTR_ERR(tsc->base);
+ tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); + if (!tsc) {
+ ret = -ENOMEM;
goto error_unregister;
}
+ tsc->base = base;
priv->tscs[i] = tsc;
}
Quoted 48 lines
Before the change, failing to find a resource at position "i", breaks the probe loop, and probing continues and the number of resource described are the number of TSC find are used.
After the change failing to find all possible TCS will fail the whole probe process, even if some TCS where described. And not describing max number of TCS on each system is perfectly fine.
Nacked-by Niklas Söderlund <[email protected]>Quoted 38 lines
--- drivers/thermal/rcar_gen3_thermal.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/thermal/rcar_gen3_thermal.c +1
-6@@ -481,7 +481,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) {struct rcar_gen3_thermal_priv *priv;struct device *dev = &pdev->dev; -struct resource *res;struct thermal_zone_device *zone;unsigned int i;int ret;@@ -504,17 +503,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)for (i =0 ; i <TSC_MAX_NUM ; i++) {struct rcar_gen3_thermal_tsc *tsc; - res =platform_get_resource (pdev,IORESOURCE_MEM , i); -if (!res) -break ; - tsc =devm_kzalloc (dev,sizeof (*tsc),GFP_KERNEL );if (!tsc) { ret = -ENOMEM ; goto error_unregister; } - tsc->base =devm_ioremap_resource (dev, res); + tsc->base =devm_platform_ioremap_resource (pdev, i);if (IS_ERR (tsc->base)) { ret =PTR_ERR (tsc->base); goto error_unregister;Signature · 1 line
2.39.0
Re: [PATCH 4/6] drivers/thermal/rcar_gen3_thermal: Convert to devm_platform_ioremap_resource()
Hi Yangtao,
Quoted 8 lines · Yangtao Li
Hi Niklas,
Quoted 4 lines · Niklas Söderlund
Hi Yangtao,
Thanks for your work.
Quoted 8 lines
Quoted 5 lines · Yangtao Li
Quoted 3 lines
Use
devm_platform_ioremap_resource()to simplify code.Signed-off-by Yangtao Li <[email protected]>This do indeed simplify the code, but it also breaks the driver :-)
How about the patch below? Can the following rcar driver also take a similar approach?
Maybe it could, I would need to test it and I'm traveling this week with no access to hardware. But I don't like the change you propose, as it makes the code more complex without any other goal then to s/platform_get_resource/devm_platform_ioremap_resource/.
If you have a reason, like trying to remove platform_get_resource() from the kernel or such I will consider the change. But if you only want to change things *because* I think the current code do the right thing in a clear way, look for resource, if found map it else use what resources have been found already. Adding special case based on return code is IMHO more complex, again if you need to go that route please add a comment describing the special case.
Quoted 98 lines
drivers/thermal/rcar_gen3_thermal.c +0
-1@@ -481,7 +481,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) { struct rcar_gen3_thermal_priv *priv; struct device *dev = &pdev->dev; - struct resource *res; struct thermal_zone_device *zone; unsigned int i;int ret;
drivers/thermal/rcar_gen3_thermal.c +10
-9@@ -503,22 +502,23 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) for (i = 0; i < TSC_MAX_NUM; i++) { struct rcar_gen3_thermal_tsc *tsc; + void __iomem *base; - res = platform_get_resource(pdev, IORESOURCE_MEM, i); - if (!res) - break; + base = devm_platform_ioremap_resource(pdev, i); + if (IS_ERR(base)) { + if (PTR_ERR(base) == -EINVAL) + break; - tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); - if (!tsc) { - ret = -ENOMEM; + ret = PTR_ERR(base); goto error_unregister; } - tsc->base = devm_ioremap_resource(dev, res); - if (IS_ERR(tsc->base)) { - ret = PTR_ERR(tsc->base); + tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); + if (!tsc) { + ret = -ENOMEM; goto error_unregister; } + tsc->base = base; priv->tscs[i] = tsc;}
Quoted 46 lines
Before the change, failing to find a resource at position "i", breaks the probe loop, and probing continues and the number of resource described are the number of TSC find are used.
After the change failing to find all possible TCS will fail the whole probe process, even if some TCS where described. And not describing max number of TCS on each system is perfectly fine.
Nacked-by Niklas Söderlund <[email protected]>Quoted 36 lines
--- drivers/thermal/rcar_gen3_thermal.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/thermal/rcar_gen3_thermal.c +1
-6@@ -481,7 +481,6 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) {struct rcar_gen3_thermal_priv *priv;struct device *dev = &pdev->dev; -struct resource *res;struct thermal_zone_device *zone;unsigned int i;int ret;@@ -504,17 +503,13 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)for (i =0 ; i <TSC_MAX_NUM ; i++) {struct rcar_gen3_thermal_tsc *tsc; - res =platform_get_resource (pdev,IORESOURCE_MEM , i); -if (!res) -break ; - tsc =devm_kzalloc (dev,sizeof (*tsc),GFP_KERNEL );if (!tsc) { ret = -ENOMEM ; goto error_unregister; } - tsc->base =devm_ioremap_resource (dev, res); + tsc->base =devm_platform_ioremap_resource (pdev, i);if (IS_ERR (tsc->base)) { ret =PTR_ERR (tsc->base); goto error_unregister;Signature · 1 line
2.39.0
Signature · 2 lines
Kind Regards, Niklas Söderlund
PATCH 5/6 thermal/drivers/rcar: Convert to devm_platform_ioremap_resource()
In reply to Yangtao LiUse devm_platform_ioremap_resource() to simplify code.
--- drivers/thermal/rcar_thermal.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/thermal/rcar_thermal.c +2 -9
@@ -397,7 +397,6 @@ static int rcar_thermal_probe(struct platform_device *pdev)struct rcar_thermal_common *common;struct rcar_thermal_priv *priv;struct device *dev = &pdev->dev; -struct resource *res;const struct rcar_thermal_chip *chip =of_device_get_match_data (dev);int mres =0 ;int i;
@@ -435,9 +434,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)* Then, driver uses common registers * rcar_has_irq_support() will be enabled */ - res =platform_get_resource (pdev,IORESOURCE_MEM , - mres++); - common->base =devm_ioremap_resource (dev, res); + common->base =devm_platform_ioremap_resource (pdev, mres++);if (IS_ERR (common->base)) { ret =PTR_ERR (common->base); goto error_unregister;
@@ -459,17 +456,13 @@ static int rcar_thermal_probe(struct platform_device *pdev) }for (i =0 ;; i++) { - res =platform_get_resource (pdev,IORESOURCE_MEM , mres++); -if (!res) -break ; - priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv) { ret = -ENOMEM ; goto error_unregister; } - priv->base =devm_ioremap_resource (dev, res); + priv->base =devm_platform_ioremap_resource (pdev, mres++);if (IS_ERR (priv->base)) { ret =PTR_ERR (priv->base); goto error_unregister;
Signature · 1 line
2.39.0
Re: [PATCH 5/6] thermal/drivers/rcar: Convert to devm_platform_ioremap_resource()
Hi Yangtao,
Thanks for your work.
Quoted 20 lines · Yangtao Li
Use
devm_platform_ioremap_resource()to simplify code.Signed-off-by Yangtao Li <[email protected]>--- drivers/thermal/rcar_thermal.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)drivers/thermal/rcar_thermal.c +0
-1@@ -397,7 +397,6 @@ static int rcar_thermal_probe(struct platform_device *pdev)struct rcar_thermal_common *common;struct rcar_thermal_priv *priv;struct device *dev = &pdev->dev; -struct resource *res;const struct rcar_thermal_chip *chip =of_device_get_match_data (dev);int mres =0 ;int i;
drivers/thermal/rcar_thermal.c static int rcar_thermal_probe(struct platform_device *pdev) · line 437
Quoted 7 lines
drivers/thermal/rcar_thermal.c +1
-3@@ -435,9 +434,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)* Then, driver uses common registers * rcar_has_irq_support() will be enabled */ - res =platform_get_resource (pdev,IORESOURCE_MEM , - mres++); - common->base =devm_ioremap_resource (dev, res); + common->base =devm_platform_ioremap_resource (pdev, mres++);
This change is fine, please post a separate patch for it.
drivers/thermal/rcar_thermal.c static int rcar_thermal_probe(struct platform_device *pdev) · line 464
Quoted 10 lines
drivers/thermal/rcar_thermal.c +0
-3if (IS_ERR (common->base)) { ret =PTR_ERR (common->base); goto error_unregister;@@ -459,17 +456,13 @@ static int rcar_thermal_probe(struct platform_device *pdev) }for (i =0 ;; i++) { - res =platform_get_resource (pdev,IORESOURCE_MEM , mres++); -if (!res) -break ;
This change is not OK as it changes the behavior of the driver same as in patch 5/6.
Quoted 15 lines
drivers/thermal/rcar_thermal.c +1
-2- priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv) { ret = -ENOMEM ; goto error_unregister; } - priv->base =devm_ioremap_resource (dev, res); + priv->base =devm_platform_ioremap_resource (pdev, mres++);if (IS_ERR (priv->base)) { ret =PTR_ERR (priv->base); goto error_unregister;Signature · 1 line
2.39.0
Signature · 2 lines
Kind Regards, Niklas Söderlund
PATCH 6/6 drivers/thermal/ti-soc-thermal: Use devm_platform_get_and_ioremap_resource()
In reply to Yangtao LiConvert platform_get_resource(), devm_ioremap_resource() to a single call to devm_platform_get_and_ioremap_resource(), as this is exactly what this function does.
--- drivers/thermal/ti-soc-thermal/ti-bandgap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/thermal/ti-soc-thermal/ti-bandgap.c +1 -2
@@ -847,10 +847,9 @@ static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev) do { void __iomem *chunk; - res = platform_get_resource(pdev, IORESOURCE_MEM, i); + chunk = devm_platform_get_and_ioremap_resource(pdev, i, &res); if (!res) break; - chunk = devm_ioremap_resource(&pdev->dev, res); if (i == 0) bgp->base = chunk; if (IS_ERR(chunk))
Signature · 1 line
2.39.0