drivers/watchdog/s3c2410_wdt.c: Convert release_resource to release_region/release_mem_region
Subsystems (3)
PATCH 1/2 drivers/watchdog/s3c2410_wdt.c: Convert release_resource to release_region/release_mem_region
Request_mem_region should be used with release_mem_region, not release_resource.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x,E;
@@
*x = request_mem_region(...)
... when != release_mem_region(x)
when != x = E
* release_resource(x);
// </smpl>
--- drivers/watchdog/s3c2410_wdt.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/watchdog/s3c2410_wdt.c +8 -11
@@ -402,7 +402,6 @@ static inline void s3c2410wdt_cpufreq_deregister(void)static int __devinit s3c2410wdt_probe (struct platform_device *pdev) { -struct resource *res;struct device *dev;unsigned int wtcon;int started =0 ;
@@ -416,20 +415,19 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)/* get the memory region for the watchdog timer */ - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (res =NULL ) { + wdt_mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (wdt_mem =NULL ) {dev_err (dev,"no memory resource specified\n" );return -ENOENT ; } - size =resource_size (res); - wdt_mem =request_mem_region (res->start, size, pdev->name); -if (wdt_mem =NULL ) { + size =resource_size (wdt_mem); +if (!request_mem_region (wdt_mem->start, size, pdev->name)) {dev_err (dev,"failed to get memory region\n" );return -EBUSY ; } - wdt_base =ioremap (res->start, size); + wdt_base =ioremap (wdt_mem->start, size);if (wdt_base =NULL ) {dev_err (dev,"failed to ioremap() region\n" ); ret = -EINVAL ;
@@ -524,8 +522,8 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)iounmap (wdt_base); err_req: -release_resource (wdt_mem); -kfree (wdt_mem); +release_mem_region (wdt_mem->start, size); + wdt_mem =NULL ;return ret; }
@@ -545,8 +543,7 @@ static int __devexit s3c2410wdt_remove(struct platform_device *dev)iounmap (wdt_base); -release_resource (wdt_mem); -kfree (wdt_mem); +release_mem_region (wdt_mem->start,resource_size (wdt_mem)); wdt_mem =NULL ;return 0 ; }
Quoted 17 lines · Julia Lawall
Request_mem_regionshould be used withrelease_mem_region, notrelease_resource.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@@
expression x,E;
@@
*x =request_mem_region(...)
... when !=release_mem_region(x)when != x = E*
release_resource(x);
// </smpl>
Review
Quoted 7 lines
Signed-off-by Julia Lawall <[email protected]>--- drivers/watchdog/s3c2410_wdt.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/drivers/watchdog/s3c2410_wdt.c
Quoted 12 lines
index 25b39bf..95ae53d 100644
drivers/watchdog/s3c2410_wdt.c +0
-1@@ -402,7 +402,6 @@ static inline void s3c2410wdt_cpufreq_deregister(void)static int __devinit s3c2410wdt_probe (struct platform_device *pdev) { -struct resource *res;struct device *dev;unsigned int wtcon;int started =0 ;
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct · line 420
Quoted 8 lines
drivers/watchdog/s3c2410_wdt.c +2
-2@@ -416,20 +415,19 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)/* get the memory region for the watchdog timer */ - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (res =NULL ) { + wdt_mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (wdt_mem =NULL ) {
Hmm...I think, 'res' is better for platform_get_resource(). Do we _really_ need to change the name?...
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct platform_device *pdev) · line 425
Quoted 9 lines
drivers/watchdog/s3c2410_wdt.c +2
-3dev_err (dev,"no memory resource specified\n" );return -ENOENT ; } - size =resource_size (res); - wdt_mem =request_mem_region (res->start, size, pdev->name); -if (wdt_mem =NULL ) { + size =resource_size (wdt_mem); +if (!request_mem_region (wdt_mem->start, size, pdev->name)) {
If we keep the name 'res', don't need to change above.
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct platform_device *pdev) · line 430
Quoted 6 lines
drivers/watchdog/s3c2410_wdt.c +1
-1dev_err (dev,"failed to get memory region\n" );return -EBUSY ; } - wdt_base =ioremap (res->start, size); + wdt_base =ioremap (wdt_mem->start, size);
Same as above.
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct · line 526
Quoted 11 lines
drivers/watchdog/s3c2410_wdt.c +0
-0if (wdt_base =NULL ) {dev_err (dev,"failed to ioremap() region\n" );drivers/watchdog/s3c2410_wdt.c +1
-2ret = -EINVAL ;@@ -524,8 +522,8 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)iounmap (wdt_base ); err_req: -release_resource (wdt_mem); -kfree (wdt_mem); +release_mem_region (wdt_mem->start, size);
release_mem_region(res->start, size); ?
drivers/watchdog/s3c2410_wdt.c static int __devexit s3c2410wdt_remove(struct · line 547
Quoted 12 lines
drivers/watchdog/s3c2410_wdt.c +1
-0+ wdt_mem =NULL ;return ret;}
drivers/watchdog/s3c2410_wdt.c +1
-2@@ -545,8 +543,7 @@ static int __devexit s3c2410wdt_remove(struct platform_device *dev)iounmap (wdt_base ); -release_resource (wdt_mem); -kfree (wdt_mem); +release_mem_region (wdt_mem->start,resource_size (wdt_mem));
release_mem_region(res->start, resource_size(res)); ?
Quoted 3 lines
drivers/watchdog/s3c2410_wdt.c +0
-0wdt_mem =NULL ;return 0 ;}
Thanks.
Best regards,
Kgene.
--
Kukjin Kim <[email protected]>, Senior Engineer, SW Solution Development Team, Samsung Electronics Co., Ltd.
Quoted 42 lines · Kukjin Kim
Quoted 17 lines · Julia Lawall
Request_mem_regionshould be used withrelease_mem_region, notrelease_resource.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@@
expression x,E;
@@
*x =request_mem_region(...)
... when !=release_mem_region(x)when != x = E*
release_resource(x);
// </smpl>Review
Quoted 7 lines
Signed-off-by Julia Lawall <[email protected]>--- drivers/watchdog/s3c2410_wdt.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/drivers/watchdog/s3c2410_wdt.cQuoted 16 lines
index 25b39bf..95ae53d 100644
drivers/watchdog/s3c2410_wdt.c +0
-1@@ -402,7 +402,6 @@ static inline void s3c2410wdt_cpufreq_deregister(void)static int __devinit s3c2410wdt_probe (struct platform_device *pdev) { -struct resource *res;struct device *dev;unsigned int wtcon;int started =0 ;@@ -416,20 +415,19 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)/* get the memory region for the watchdog timer */
Quoted 7 lines
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct platform_device *pdev) · line 419
Quoted 4 lines
drivers/watchdog/s3c2410_wdt.c +2
-2- res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (res =NULL ) { + wdt_mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (wdt_mem =NULL ) {Hmm...I think, 'res' is better for
platform_get_resource(). Do we _really_ need to change the name?...
wdt_mem is a global variable. Is res a good name for a global variable? One could say wdt_mem = res, if that seems better.
julia
Quoted 68 lines
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct platform_device *pdev) · line 425
Quoted 9 lines
drivers/watchdog/s3c2410_wdt.c +2
-3dev_err (dev,"no memory resource specified\n" );return -ENOENT ; } - size =resource_size (res); - wdt_mem =request_mem_region (res->start, size, pdev->name); -if (wdt_mem =NULL ) { + size =resource_size (wdt_mem); +if (!request_mem_region (wdt_mem->start, size, pdev->name)) {If we keep the name 'res', don't need to change above.
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct platform_device *pdev) · line 430
Quoted 6 lines
drivers/watchdog/s3c2410_wdt.c +1
-1dev_err (dev,"failed to get memory region\n" );return -EBUSY ; } - wdt_base =ioremap (res->start, size); + wdt_base =ioremap (wdt_mem->start, size);Same as above.
drivers/watchdog/s3c2410_wdt.c static int __devinit s3c2410wdt_probe(struct · line 526
Quoted 11 lines
drivers/watchdog/s3c2410_wdt.c +0
-0if (wdt_base =NULL ) {dev_err (dev,"failed to ioremap() region\n" );drivers/watchdog/s3c2410_wdt.c +1
-2ret = -EINVAL ;@@ -524,8 +522,8 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)iounmap (wdt_base ); err_req: -release_resource (wdt_mem); -kfree (wdt_mem); +release_mem_region (wdt_mem->start, size);
release_mem_region(res->start, size); ?drivers/watchdog/s3c2410_wdt.c static int __devexit s3c2410wdt_remove(struct · line 547
Quoted 12 lines
drivers/watchdog/s3c2410_wdt.c +1
-0+ wdt_mem =NULL ;return ret;}
drivers/watchdog/s3c2410_wdt.c +1
-2@@ -545,8 +543,7 @@ static int __devexit s3c2410wdt_remove(struct platform_device *dev)iounmap (wdt_base ); -release_resource (wdt_mem); -kfree (wdt_mem); +release_mem_region (wdt_mem->start,resource_size (wdt_mem));
release_mem_region(res->start, resource_size(res)); ?Quoted 3 lines
drivers/watchdog/s3c2410_wdt.c +0
-0wdt_mem =NULL ;return 0 ;}
Thanks.
Best regards,
Kgene.
--
Kukjin Kim <[email protected]>, Senior Engineer, SW Solution Development Team, Samsung Electronics Co., Ltd.--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Julia, Kukjin Kim,
Quoted 5 lines
Quoted 2 lines
Hmm...I think, 'res' is better for
platform_get_resource(). Do we _really_ need to change the name?...
wdt_memis a global variable. Is res a good name for a global variable? One could saywdt_mem= res, if that seems better.
If you look at the code then you have:
static struct resource *wdt_mem;
static struct resource *wdt_irq;
and in the probe function you have:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ... wdt_mem = request_mem_region(res->start, size, pdev->name); ... wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
So doing Julia's:
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...
if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
...
wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0)seems the best solution to me (since you then have both resources being polulated via platform_get_resource(pdev,... ).
Kind regards,
Wim.
Quoted 19 lines · Wim Van Sebroeck
Hi Julia, Kukjin Kim,
Quoted 5 lines
Quoted 2 lines
Hmm...I think, 'res' is better for
platform_get_resource(). Do we _really_ need to change the name?...
wdt_memis a global variable. Is res a good name for a global variable? One could saywdt_mem= res, if that seems better.If you look at the code then you have:
static struct resource*wdt_mem;
static struct resource*wdt_irq;and in the probe function you have:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ... wdt_mem = request_mem_region(res->start, size, pdev->name); ... wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
Quoted 8 lines
So doing Julia's:
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); ... if (!request_mem_region(wdt_mem->start, size, pdev->name)) { ... wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0)seems the best solution to me (since you then have both resources being polulated via platform_get_resource(pdev,... ).
Actually, I later realized that one can also use the result of request_mem_region in place of res. Even though it is not the same structure, it has the same start and end field information, which is the only information that is used. But I haven't had a chance to send a patch that follows that strategy. So if it is preferred to keep res, then that can be done.
julia
Hi Julia,
Quoted 6 lines
Actually, I later realized that one can also use the result of
request_mem_regionin place of res. Even though it is not the same structure, it has the same start and end field information, which is the only information that is used. But I haven't had a chance to send a patch that follows that strategy. So if it is preferred to keep res, then that can be done.
If you look at the driver then you will see that it will use wdt_base to control the device:
static void __iomem *wdt_base;
...
res=platform_get_resource(pdev, IORESOURCE_MEM, 0);
...wdt_base = ioremap(res->start, size);
So the memory resource is only used for:
1) requesting the memory region
2) ioremapping the memory so that we can use the registers.
My opinion: res can go out so that wdt_mem and wdt_irq get similar platform resource info.
Kind regards,
Wim.