staging: iio: adc: Use devm_ioremap_resource() instead of of_iomap()
Subsystems (3)
PATCH 1/1 staging: iio: adc: Use devm_ioremap_resource() instead of of_iomap()
The adc driver uses of_iomap() which doesn't request the resource and isn't device managed so error handling is needed. of_iomap() is mainly used in cases where there is no driver or struct device so a switch to devm_ functions is required.
This patch switches to use devm_ioremap_resource() instead which automatically requests the resource and is freed when the driver detaches.
Removed the error handling to unmap I/O registers i.e. iounmap() in probe and remove functions of this driver and consequently removed an unnecessary label.
--- drivers/staging/iio/adc/spear_adc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/staging/iio/adc/spear_adc.c +8 -10
@@ -262,6 +262,7 @@ static int spear_adc_probe(struct platform_device *pdev)struct device_node *np = pdev->dev.of_node;struct device *dev = &pdev->dev;struct spear_adc_state *st; +struct resource *res;struct iio_dev *indio_dev =NULL ;int ret = -ENODEV ;int irq;
@@ -280,24 +281,24 @@ static int spear_adc_probe(struct platform_device *pdev)* (e.g. SPEAr3xx). Let's provide two register base addresses * to support multi-arch kernels. */ - st->adc_base_spear6xx =of_iomap (np,0 ); -if (!st->adc_base_spear6xx) { -dev_err (dev,"failed mapping memory\n" ); -return -ENOMEM ; - } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + st->adc_base_spear6xx =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (st->adc_base_spear6xx)) +return PTR_ERR (st->adc_base_spear6xx); + st->adc_base_spear3xx = (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx; st->clk =devm_clk_get (dev,NULL );if (IS_ERR (st->clk)) {dev_err (dev,"failed getting clock\n" ); - goto errout1; +return ret; } ret =clk_prepare_enable (st->clk);if (ret) {dev_err (dev,"failed enabling clock\n" ); - goto errout1; +return ret; } irq =platform_get_irq (pdev,0 );
@@ -356,8 +357,6 @@ static int spear_adc_probe(struct platform_device *pdev) errout2:clk_disable_unprepare (st->clk); -errout1: -iounmap (st->adc_base_spear6xx);return ret; }
@@ -367,7 +366,6 @@ static int spear_adc_remove(struct platform_device *pdev)struct spear_adc_state *st =iio_priv (indio_dev);clk_disable_unprepare (st->clk); -iounmap (st->adc_base_spear6xx);return 0 ; }
Signature · 1 line
1.9.1
Quoted 8 lines · Amitoj Kaur Chawla
The adc driver uses
of_iomap()which doesn't request the resource and isn't device managed so error handling is needed.of_iomap()is mainly used in cases where there is no driver or struct device so a switch todevm_functions is required.This patch switches to use
devm_ioremap_resource()instead which automatically requests the resource and is freed when the driver detaches.
The above doesn't explain sufficiently why the transformation is correct. You would have to look at the definitions of the functions involved, and show that in this case they do the same thing. Do you have anoher patch that makes this transformation? What kind of justification does it give?
julia
Quoted 80 lines
Removed the error handling to unmap I/O registers i.e.
iounmap()in probe and remove functions of this driver and consequently removed an unnecessary label.Signed-off-by Amitoj Kaur Chawla <[email protected]>--- drivers/staging/iio/adc/spear_adc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/staging/iio/adc/spear_adc.c +8
-10@@ -262,6 +262,7 @@ static int spear_adc_probe(struct platform_device *pdev)struct device_node *np = pdev->dev.of_node;struct device *dev = &pdev->dev;struct spear_adc_state *st; +struct resource *res;struct iio_dev *indio_dev =NULL ;int ret = -ENODEV ;int irq;@@ -280,24 +281,24 @@ static int spear_adc_probe(struct platform_device *pdev)* (e.g. SPEAr3xx). Let's provide two register base addresses * to support multi-arch kernels. */ - st->adc_base_spear6xx =of_iomap (np,0 ); -if (!st->adc_base_spear6xx) { -dev_err (dev,"failed mapping memory\n" ); -return -ENOMEM ; - } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + st->adc_base_spear6xx =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (st->adc_base_spear6xx)) +return PTR_ERR (st->adc_base_spear6xx); + st->adc_base_spear3xx = (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx; st->clk =devm_clk_get (dev,NULL );if (IS_ERR (st->clk)) {dev_err (dev,"failed getting clock\n" ); - goto errout1; +return ret; } ret =clk_prepare_enable (st->clk);if (ret) {dev_err (dev,"failed enabling clock\n" ); - goto errout1; +return ret; } irq =platform_get_irq (pdev,0 );@@ -356,8 +357,6 @@ static int spear_adc_probe(struct platform_device *pdev) errout2:clk_disable_unprepare (st->clk); -errout1: -iounmap (st->adc_base_spear6xx);return ret; }@@ -367,7 +366,6 @@ static int spear_adc_remove(struct platform_device *pdev)struct spear_adc_state *st =iio_priv (indio_dev);clk_disable_unprepare (st->clk); -iounmap (st->adc_base_spear6xx);return 0 ; }Signature · 8 lines
1.9.1 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160223181623.GA20782%40amitoj-Inspiron-3542. For more options, visit https://groups.google.com/d/optout.
Quoted 9 lines · Julia Lawall
Quoted 8 lines
The adc driver uses
of_iomap()which doesn't request the resource and isn't device managed so error handling is needed.of_iomap()is mainly used in cases where there is no driver or struct device so a switch todevm_functions is required.This patch switches to use
devm_ioremap_resource()instead which automatically requests the resource and is freed when the driver detaches.
Quoted 6 lines
The above doesn't explain sufficiently why the transformation is correct. You would have to look at the definitions of the functions involved, and show that in this case they do the same thing. Do you have anoher patch that makes this transformation? What kind of justification does it give?
julia
I made the change based on these two patches
<https://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/log/?qt=grep&q=use+devm_ioremap_resource%28%29+instead+of+of_iomap%28%29>
and this discussion.
<http://comments.gmane.org/gmane.linux.drivers.devicetree/33334>
Amitoj
Quoted 12 lines · Amitoj Kaur Chawla
Quoted 9 lines · Julia Lawall
Quoted 8 lines
The adc driver uses
of_iomap()which doesn't request the resource and isn't device managed so error handling is needed.of_iomap()is mainly used in cases where there is no driver or struct device so a switch todevm_functions is required.This patch switches to use
devm_ioremap_resource()instead which automatically requests the resource and is freed when the driver detaches.
Quoted 8 lines
Quoted 6 lines
The above doesn't explain sufficiently why the transformation is correct. You would have to look at the definitions of the functions involved, and show that in this case they do the same thing. Do you have anoher patch that makes this transformation? What kind of justification does it give?
julia
I made the change based on these two patches and this discussion.
The link for the two patches doesn't work for me. Do you have the commit ids?
julia
Quoted 11 lines
Amitoj
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CA%2B5yK5HbDKJoRZYOa0PuJjAOuQt68yVM-%3D_aGR%3DC7im%3DE5Vo3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 3 lines · Julia Lawall
The link for the two patches doesn't work for me. Do you have the commit ids?
Commit ids c3f0dd38996d5f4e7c681099ba18cc1587155edb and b5f3b75d9d3b5526d973fc0bfee5680bdc6acf2a
Amitoj
Quoted 6 lines · Amitoj Kaur Chawla
Quoted 3 lines · Julia Lawall
The link for the two patches doesn't work for me. Do you have the commit ids?
Commit ids
c3f0dd38996d5f4e7c681099ba18cc1587155edbandb5f3b75d9d3b5526d973fc0bfee5680bdc6acf2a
OK, thanks. I don't remember if you had a semantic patch for this. Maybe you could see how often the issue occurs elsewhere in the kernel.
julia
Quoted 10 lines · Julia Lawall
Quoted 5 lines
Quoted 3 lines
The link for the two patches doesn't work for me. Do you have the commit ids?
Commit ids
c3f0dd38996d5f4e7c681099ba18cc1587155edbandb5f3b75d9d3b5526d973fc0bfee5680bdc6acf2aOK, thanks. I don't remember if you had a semantic patch for this. Maybe you could see how often the issue occurs elsewhere in the kernel.
julia
I don't as of now since I just found this after your comments on the other patch.
I was, indeed, thinking of writing one if this patch is accepted.
Amitoj
Quoted 7 lines · Amitoj Kaur Chawla
Quoted 6 lines · Julia Lawall
Quoted 5 lines
Quoted 3 lines
The link for the two patches doesn't work for me. Do you have the commit ids?
Commit ids
c3f0dd38996d5f4e7c681099ba18cc1587155edbandb5f3b75d9d3b5526d973fc0bfee5680bdc6acf2a
Quoted 8 lines
Quoted 4 lines
OK, thanks. I don't remember if you had a semantic patch for this. Maybe you could see how often the issue occurs elsewhere in the kernel.
julia
I don't as of now since I just found this after your comments on the other patch.
I was, indeed, thinking of writing one if this patch is accepted.
OK, that's a reasonable stretgy.
julia
Quoted 10 lines
Amitoj
Signature · 5 lines
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CA%2B5yK5F%2B1_fweJuz7Z1ER3-phvyWZckLpU7vjjwV_zZ%2BaM4dwA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Quoted 80 lines · Amitoj Kaur Chawla
The adc driver uses
of_iomap()which doesn't request the resource and isn't device managed so error handling is needed.of_iomap()is mainly used in cases where there is no driver or struct device so a switch todevm_functions is required.This patch switches to use
devm_ioremap_resource()instead which automatically requests the resource and is freed when the driver detaches.Removed the error handling to unmap I/O registers i.e.
iounmap()in probe and remove functions of this driver and consequently removed an unnecessary label.Signed-off-by Amitoj Kaur Chawla <[email protected]>--- drivers/staging/iio/adc/spear_adc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/staging/iio/adc/spear_adc.c +8
-11@@ -262,6 +262,7 @@ static int spear_adc_probe(struct platform_device *pdev)struct device_node *np = pdev->dev.of_node;struct device *dev = &pdev->dev;struct spear_adc_state *st; +struct resource *res;struct iio_dev *indio_dev =NULL ;int ret = -ENODEV ;int irq;@@ -280,24 +281,24 @@ static int spear_adc_probe(struct platform_device *pdev)* (e.g. SPEAr3xx). Let's provide two register base addresses * to support multi-arch kernels. */ - st->adc_base_spear6xx =of_iomap (np,0 ); -if (!st->adc_base_spear6xx) { -dev_err (dev,"failed mapping memory\n" ); -return -ENOMEM ; - } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + st->adc_base_spear6xx =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (st->adc_base_spear6xx)) +return PTR_ERR (st->adc_base_spear6xx); + st->adc_base_spear3xx = (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx; st->clk =devm_clk_get (dev,NULL );if (IS_ERR (st->clk)) {dev_err (dev,"failed getting clock\n" ); - goto errout1; +return ret; } ret =clk_prepare_enable (st->clk);if (ret) {dev_err (dev,"failed enabling clock\n" ); - goto errout1; +return ret; } irq =platform_get_irq (pdev,0 );@@ -356,8 +357,6 @@ static int spear_adc_probe(struct platform_device *pdev) errout2:clk_disable_unprepare (st->clk); -errout1: -iounmap (st->adc_base_spear6xx);return ret; }@@ -367,7 +366,6 @@ static int spear_adc_remove(struct platform_device *pdev)struct spear_adc_state *st =iio_priv (indio_dev);clk_disable_unprepare (st->clk); -iounmap (st->adc_base_spear6xx);return 0 ; } --
Quoted 2 lines
1.9.1
Since another patch has been dropped for this file, I will rebase and resend this patch.
Amitoj