* [PATCH 0/5] use devm_ functions
@ 2012-07-31 13:54 Damien Cassou
2012-07-31 13:54 ` [PATCH 5/5] drivers/video/ep93xx-fb.c: " Damien Cassou
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
These patches introduce devm_ functions in some video drivers.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 5/5] drivers/video/ep93xx-fb.c: use devm_ functions
2012-07-31 13:54 [PATCH 0/5] use devm_ functions Damien Cassou
@ 2012-07-31 13:54 ` Damien Cassou
2012-08-23 20:35 ` Florian Tobias Schandinat
2012-07-31 13:54 ` [PATCH 4/5] drivers/video/da8xx-fb.c: " Damien Cassou
` (3 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
From: Damien Cassou <damien.cassou@lifl.fr>
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
---
drivers/video/ep93xx-fb.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c
index 345d962..69c89f2 100644
--- a/drivers/video/ep93xx-fb.c
+++ b/drivers/video/ep93xx-fb.c
@@ -529,7 +529,8 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
* any of the framebuffer registers.
*/
fbi->res = res;
- fbi->mmio_base = ioremap(res->start, resource_size(res));
+ fbi->mmio_base = devm_ioremap(&pdev->dev, res->start,
+ resource_size(res));
if (!fbi->mmio_base) {
err = -ENXIO;
goto failed_resource;
@@ -553,20 +554,20 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
if (err == 0) {
dev_err(info->dev, "No suitable video mode found\n");
err = -EINVAL;
- goto failed_mode;
+ goto failed_resource;
}
if (mach_info->setup) {
err = mach_info->setup(pdev);
if (err)
- goto failed_mode;
+ goto failed_resource;
}
err = ep93xxfb_check_var(&info->var, info);
if (err)
goto failed_check;
- fbi->clk = clk_get(info->dev, NULL);
+ fbi->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(fbi->clk)) {
err = PTR_ERR(fbi->clk);
fbi->clk = NULL;
@@ -578,19 +579,15 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
err = register_framebuffer(info);
if (err)
- goto failed;
+ goto failed_check;
dev_info(info->dev, "registered. Mode = %dx%d-%d\n",
info->var.xres, info->var.yres, info->var.bits_per_pixel);
return 0;
-failed:
- clk_put(fbi->clk);
failed_check:
if (fbi->mach_info->teardown)
fbi->mach_info->teardown(pdev);
-failed_mode:
- iounmap(fbi->mmio_base);
failed_resource:
ep93xxfb_dealloc_videomem(info);
failed_videomem:
@@ -609,8 +606,6 @@ static int __devexit ep93xxfb_remove(struct platform_device *pdev)
unregister_framebuffer(info);
clk_disable(fbi->clk);
- clk_put(fbi->clk);
- iounmap(fbi->mmio_base);
ep93xxfb_dealloc_videomem(info);
fb_dealloc_cmap(&info->cmap);
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 5/5] drivers/video/ep93xx-fb.c: use devm_ functions
2012-07-31 13:54 ` [PATCH 5/5] drivers/video/ep93xx-fb.c: " Damien Cassou
@ 2012-08-23 20:35 ` Florian Tobias Schandinat
0 siblings, 0 replies; 15+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:35 UTC (permalink / raw)
To: Damien Cassou; +Cc: kernel-janitors, linux-fbdev, linux-kernel
On 07/31/2012 01:54 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
>
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in
> the probe function of a platform device and is only freed in the remove
> function.
>
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
Applied.
Thanks,
Florian Tobias Schandinat
>
> ---
> drivers/video/ep93xx-fb.c | 17 ++++++-----------
> 1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c
> index 345d962..69c89f2 100644
> --- a/drivers/video/ep93xx-fb.c
> +++ b/drivers/video/ep93xx-fb.c
> @@ -529,7 +529,8 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
> * any of the framebuffer registers.
> */
> fbi->res = res;
> - fbi->mmio_base = ioremap(res->start, resource_size(res));
> + fbi->mmio_base = devm_ioremap(&pdev->dev, res->start,
> + resource_size(res));
> if (!fbi->mmio_base) {
> err = -ENXIO;
> goto failed_resource;
> @@ -553,20 +554,20 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
> if (err == 0) {
> dev_err(info->dev, "No suitable video mode found\n");
> err = -EINVAL;
> - goto failed_mode;
> + goto failed_resource;
> }
>
> if (mach_info->setup) {
> err = mach_info->setup(pdev);
> if (err)
> - goto failed_mode;
> + goto failed_resource;
> }
>
> err = ep93xxfb_check_var(&info->var, info);
> if (err)
> goto failed_check;
>
> - fbi->clk = clk_get(info->dev, NULL);
> + fbi->clk = devm_clk_get(&pdev->dev, NULL);
> if (IS_ERR(fbi->clk)) {
> err = PTR_ERR(fbi->clk);
> fbi->clk = NULL;
> @@ -578,19 +579,15 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
>
> err = register_framebuffer(info);
> if (err)
> - goto failed;
> + goto failed_check;
>
> dev_info(info->dev, "registered. Mode = %dx%d-%d\n",
> info->var.xres, info->var.yres, info->var.bits_per_pixel);
> return 0;
>
> -failed:
> - clk_put(fbi->clk);
> failed_check:
> if (fbi->mach_info->teardown)
> fbi->mach_info->teardown(pdev);
> -failed_mode:
> - iounmap(fbi->mmio_base);
> failed_resource:
> ep93xxfb_dealloc_videomem(info);
> failed_videomem:
> @@ -609,8 +606,6 @@ static int __devexit ep93xxfb_remove(struct platform_device *pdev)
>
> unregister_framebuffer(info);
> clk_disable(fbi->clk);
> - clk_put(fbi->clk);
> - iounmap(fbi->mmio_base);
> ep93xxfb_dealloc_videomem(info);
> fb_dealloc_cmap(&info->cmap);
>
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 4/5] drivers/video/da8xx-fb.c: use devm_ functions
2012-07-31 13:54 [PATCH 0/5] use devm_ functions Damien Cassou
2012-07-31 13:54 ` [PATCH 5/5] drivers/video/ep93xx-fb.c: " Damien Cassou
@ 2012-07-31 13:54 ` Damien Cassou
2012-07-31 15:47 ` Sachin Kamat
2012-07-31 13:54 ` [PATCH 3/5] drivers/video/cobalt_lcdfb.c: " Damien Cassou
` (2 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
From: Damien Cassou <damien.cassou@lifl.fr>
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
---
drivers/video/da8xx-fb.c | 34 ++++++++--------------------------
1 file changed, 8 insertions(+), 26 deletions(-)
diff --git a/drivers/video/da8xx-fb.c b/drivers/video/da8xx-fb.c
index 7ae9d53..0429431 100644
--- a/drivers/video/da8xx-fb.c
+++ b/drivers/video/da8xx-fb.c
@@ -947,12 +947,9 @@ static int __devexit fb_remove(struct platform_device *dev)
par->p_palette_base);
dma_free_coherent(NULL, par->vram_size, par->vram_virt,
par->vram_phys);
- free_irq(par->irq, par);
clk_disable(par->lcdc_clk);
clk_put(par->lcdc_clk);
framebuffer_release(info);
- iounmap((void __iomem *)da8xx_fb_reg_base);
- release_mem_region(lcdc_regs->start, resource_size(lcdc_regs));
}
return 0;
@@ -1149,7 +1146,7 @@ static int __devinit fb_probe(struct platform_device *device)
struct fb_info *da8xx_fb_info;
struct clk *fb_clk = NULL;
struct da8xx_fb_par *par;
- resource_size_t len;
+
int ret, i;
unsigned long ulcm;
@@ -1159,29 +1156,20 @@ static int __devinit fb_probe(struct platform_device *device)
}
lcdc_regs = platform_get_resource(device, IORESOURCE_MEM, 0);
- if (!lcdc_regs) {
- dev_err(&device->dev,
- "Can not get memory resource for LCD controller\n");
- return -ENOENT;
- }
-
- len = resource_size(lcdc_regs);
- lcdc_regs = request_mem_region(lcdc_regs->start, len, lcdc_regs->name);
- if (!lcdc_regs)
- return -EBUSY;
-
- da8xx_fb_reg_base = (resource_size_t)ioremap(lcdc_regs->start, len);
+ da8xx_fb_reg_base =
+ (resource_size_t) devm_request_and_ioremap(&device->dev,
+ lcdc_regs);
if (!da8xx_fb_reg_base) {
ret = -EBUSY;
- goto err_request_mem;
+ return ret;
}
fb_clk = clk_get(&device->dev, NULL);
if (IS_ERR(fb_clk)) {
dev_err(&device->dev, "Can not get device clock\n");
ret = -ENODEV;
- goto err_ioremap;
+ return ret;
}
ret = clk_enable(fb_clk);
if (ret)
@@ -1359,8 +1347,8 @@ static int __devinit fb_probe(struct platform_device *device)
else
lcdc_irq_handler = lcdc_irq_handler_rev02;
- ret = request_irq(par->irq, lcdc_irq_handler, 0,
- DRIVER_NAME, par);
+ ret = devm_request_irq(&device->dev, par->irq, lcdc_irq_handler, 0,
+ DRIVER_NAME, par);
if (ret)
goto irq_freq;
return 0;
@@ -1391,12 +1379,6 @@ err_clk_disable:
err_clk_put:
clk_put(fb_clk);
-err_ioremap:
- iounmap((void __iomem *)da8xx_fb_reg_base);
-
-err_request_mem:
- release_mem_region(lcdc_regs->start, len);
-
return ret;
}
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 4/5] drivers/video/da8xx-fb.c: use devm_ functions
2012-07-31 13:54 ` [PATCH 4/5] drivers/video/da8xx-fb.c: " Damien Cassou
@ 2012-07-31 15:47 ` Sachin Kamat
2012-07-31 16:01 ` Damien Cassou
0 siblings, 1 reply; 15+ messages in thread
From: Sachin Kamat @ 2012-07-31 15:47 UTC (permalink / raw)
To: Damien Cassou
Cc: Florian Tobias Schandinat, kernel-janitors, linux-fbdev, linux-kernel
On 31 July 2012 19:24, Damien Cassou <damien.cassou@lifl.fr> wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
>
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in
> the probe function of a platform device and is only freed in the remove
> function.
>
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
>
> ---
> drivers/video/da8xx-fb.c | 34 ++++++++--------------------------
> 1 file changed, 8 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/video/da8xx-fb.c b/drivers/video/da8xx-fb.c
> index 7ae9d53..0429431 100644
> --- a/drivers/video/da8xx-fb.c
> +++ b/drivers/video/da8xx-fb.c
> @@ -947,12 +947,9 @@ static int __devexit fb_remove(struct platform_device *dev)
> par->p_palette_base);
> dma_free_coherent(NULL, par->vram_size, par->vram_virt,
> par->vram_phys);
> - free_irq(par->irq, par);
> clk_disable(par->lcdc_clk);
> clk_put(par->lcdc_clk);
> framebuffer_release(info);
> - iounmap((void __iomem *)da8xx_fb_reg_base);
> - release_mem_region(lcdc_regs->start, resource_size(lcdc_regs));
>
> }
> return 0;
> @@ -1149,7 +1146,7 @@ static int __devinit fb_probe(struct platform_device *device)
> struct fb_info *da8xx_fb_info;
> struct clk *fb_clk = NULL;
> struct da8xx_fb_par *par;
> - resource_size_t len;
> +
> int ret, i;
> unsigned long ulcm;
>
> @@ -1159,29 +1156,20 @@ static int __devinit fb_probe(struct platform_device *device)
> }
>
> lcdc_regs = platform_get_resource(device, IORESOURCE_MEM, 0);
> - if (!lcdc_regs) {
> - dev_err(&device->dev,
> - "Can not get memory resource for LCD controller\n");
> - return -ENOENT;
> - }
> -
> - len = resource_size(lcdc_regs);
>
> - lcdc_regs = request_mem_region(lcdc_regs->start, len, lcdc_regs->name);
> - if (!lcdc_regs)
> - return -EBUSY;
> -
> - da8xx_fb_reg_base = (resource_size_t)ioremap(lcdc_regs->start, len);
> + da8xx_fb_reg_base =
> + (resource_size_t) devm_request_and_ioremap(&device->dev,
> + lcdc_regs);
> if (!da8xx_fb_reg_base) {
> ret = -EBUSY;
> - goto err_request_mem;
> + return ret;
You can directly do
return -EBUSY;
and remove the braces.
> }
>
> fb_clk = clk_get(&device->dev, NULL);
> if (IS_ERR(fb_clk)) {
> dev_err(&device->dev, "Can not get device clock\n");
> ret = -ENODEV;
> - goto err_ioremap;
> + return ret;
ditto
> }
> ret = clk_enable(fb_clk);
> if (ret)
> @@ -1359,8 +1347,8 @@ static int __devinit fb_probe(struct platform_device *device)
> else
> lcdc_irq_handler = lcdc_irq_handler_rev02;
>
> - ret = request_irq(par->irq, lcdc_irq_handler, 0,
> - DRIVER_NAME, par);
> + ret = devm_request_irq(&device->dev, par->irq, lcdc_irq_handler, 0,
> + DRIVER_NAME, par);
> if (ret)
> goto irq_freq;
> return 0;
> @@ -1391,12 +1379,6 @@ err_clk_disable:
> err_clk_put:
> clk_put(fb_clk);
>
> -err_ioremap:
> - iounmap((void __iomem *)da8xx_fb_reg_base);
> -
> -err_request_mem:
> - release_mem_region(lcdc_regs->start, len);
> -
> return ret;
> }
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
With warm regards,
Sachin
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/5] drivers/video/da8xx-fb.c: use devm_ functions
2012-07-31 15:47 ` Sachin Kamat
@ 2012-07-31 16:01 ` Damien Cassou
0 siblings, 0 replies; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 16:01 UTC (permalink / raw)
To: Sachin Kamat
Cc: Florian Tobias Schandinat, kernel-janitors, linux-fbdev, linux-kernel
The whole patch is incorrect because of:
On Tue, Jul 31, 2012 at 5:47 PM, Sachin Kamat <sachin.kamat@linaro.org> wrote:
>> - ret = request_irq(par->irq, lcdc_irq_handler, 0,
>> - DRIVER_NAME, par);
>> + ret = devm_request_irq(&device->dev, par->irq, lcdc_irq_handler, 0,
>> + DRIVER_NAME, par);
The following message explains why this is problematic:
http://marc.info/?l=kernel-janitors&m=134374464625591&w=2
Please ignore this whole patch altogether.
Sorry about that.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 3/5] drivers/video/cobalt_lcdfb.c: use devm_ functions
2012-07-31 13:54 [PATCH 0/5] use devm_ functions Damien Cassou
2012-07-31 13:54 ` [PATCH 5/5] drivers/video/ep93xx-fb.c: " Damien Cassou
2012-07-31 13:54 ` [PATCH 4/5] drivers/video/da8xx-fb.c: " Damien Cassou
@ 2012-07-31 13:54 ` Damien Cassou
2012-08-23 20:36 ` Florian Tobias Schandinat
2012-07-31 13:54 ` [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: " Damien Cassou
2012-07-31 13:54 ` [PATCH 1/5] drivers/video/bf537-lq035.c: " Damien Cassou
4 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
From: Damien Cassou <damien.cassou@lifl.fr>
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
---
drivers/video/cobalt_lcdfb.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/video/cobalt_lcdfb.c b/drivers/video/cobalt_lcdfb.c
index eae46f6..01a4ee7 100644
--- a/drivers/video/cobalt_lcdfb.c
+++ b/drivers/video/cobalt_lcdfb.c
@@ -348,7 +348,8 @@ static int __devinit cobalt_lcdfb_probe(struct platform_device *dev)
}
info->screen_size = resource_size(res);
- info->screen_base = ioremap(res->start, info->screen_size);
+ info->screen_base = devm_ioremap(&dev->dev, res->start,
+ info->screen_size);
info->fbops = &cobalt_lcd_fbops;
info->fix = cobalt_lcdfb_fix;
info->fix.smem_start = res->start;
@@ -359,7 +360,6 @@ static int __devinit cobalt_lcdfb_probe(struct platform_device *dev)
retval = register_framebuffer(info);
if (retval < 0) {
- iounmap(info->screen_base);
framebuffer_release(info);
return retval;
}
@@ -380,7 +380,6 @@ static int __devexit cobalt_lcdfb_remove(struct platform_device *dev)
info = platform_get_drvdata(dev);
if (info) {
- iounmap(info->screen_base);
unregister_framebuffer(info);
framebuffer_release(info);
}
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 3/5] drivers/video/cobalt_lcdfb.c: use devm_ functions
2012-07-31 13:54 ` [PATCH 3/5] drivers/video/cobalt_lcdfb.c: " Damien Cassou
@ 2012-08-23 20:36 ` Florian Tobias Schandinat
0 siblings, 0 replies; 15+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:36 UTC (permalink / raw)
To: Damien Cassou; +Cc: kernel-janitors, linux-fbdev, linux-kernel
On 07/31/2012 01:54 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
>
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in
> the probe function of a platform device and is only freed in the remove
> function.
>
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
Applied.
Thanks,
Florian Tobias Schandinat
>
> ---
> drivers/video/cobalt_lcdfb.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/video/cobalt_lcdfb.c b/drivers/video/cobalt_lcdfb.c
> index eae46f6..01a4ee7 100644
> --- a/drivers/video/cobalt_lcdfb.c
> +++ b/drivers/video/cobalt_lcdfb.c
> @@ -348,7 +348,8 @@ static int __devinit cobalt_lcdfb_probe(struct platform_device *dev)
> }
>
> info->screen_size = resource_size(res);
> - info->screen_base = ioremap(res->start, info->screen_size);
> + info->screen_base = devm_ioremap(&dev->dev, res->start,
> + info->screen_size);
> info->fbops = &cobalt_lcd_fbops;
> info->fix = cobalt_lcdfb_fix;
> info->fix.smem_start = res->start;
> @@ -359,7 +360,6 @@ static int __devinit cobalt_lcdfb_probe(struct platform_device *dev)
>
> retval = register_framebuffer(info);
> if (retval < 0) {
> - iounmap(info->screen_base);
> framebuffer_release(info);
> return retval;
> }
> @@ -380,7 +380,6 @@ static int __devexit cobalt_lcdfb_remove(struct platform_device *dev)
>
> info = platform_get_drvdata(dev);
> if (info) {
> - iounmap(info->screen_base);
> unregister_framebuffer(info);
> framebuffer_release(info);
> }
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: use devm_ functions
2012-07-31 13:54 [PATCH 0/5] use devm_ functions Damien Cassou
` (2 preceding siblings ...)
2012-07-31 13:54 ` [PATCH 3/5] drivers/video/cobalt_lcdfb.c: " Damien Cassou
@ 2012-07-31 13:54 ` Damien Cassou
2012-07-31 13:57 ` Mike Frysinger
2012-07-31 13:54 ` [PATCH 1/5] drivers/video/bf537-lq035.c: " Damien Cassou
4 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
From: Damien Cassou <damien.cassou@lifl.fr>
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
---
drivers/video/bfin-t350mcqb-fb.c | 28 +++++++++-------------------
1 file changed, 9 insertions(+), 19 deletions(-)
diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
index 7a0c05f..43e0d1b 100644
--- a/drivers/video/bfin-t350mcqb-fb.c
+++ b/drivers/video/bfin-t350mcqb-fb.c
@@ -490,9 +490,10 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
fbinfo->fbops = &bfin_t350mcqb_fb_ops;
fbinfo->flags = FBINFO_FLAG_DEFAULT;
- info->fb_buffer = dma_alloc_coherent(NULL, fbinfo->fix.smem_len +
- ACTIVE_VIDEO_MEM_OFFSET,
- &info->dma_handle, GFP_KERNEL);
+ info->fb_buffer = dmam_alloc_coherent(&pdev->dev, NULL,
+ fbinfo->fix.smem_len +
+ ACTIVE_VIDEO_MEM_OFFSET,
+ &info->dma_handle, GFP_KERNEL);
if (NULL == info->fb_buffer) {
printk(KERN_ERR DRIVER_NAME
@@ -514,7 +515,7 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
"Fail to allocate colormap (%d entries)\n",
BFIN_LCD_NBR_PALETTE_ENTRIES);
ret = -EFAULT;
- goto out4;
+ goto out3;
}
if (bfin_t350mcqb_request_ports(1)) {
@@ -529,8 +530,8 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
goto out7;
}
- ret = request_irq(info->irq, bfin_t350mcqb_irq_error, 0,
- "PPI ERROR", info);
+ ret = devm_request_irq(&pdev->dev, info->irq, bfin_t350mcqb_irq_error,
+ 0, "PPI ERROR", info);
if (ret < 0) {
printk(KERN_ERR DRIVER_NAME
": unable to request PPI ERROR IRQ\n");
@@ -541,7 +542,7 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
printk(KERN_ERR DRIVER_NAME
": unable to register framebuffer.\n");
ret = -EINVAL;
- goto out8;
+ goto out7;
}
#ifndef NO_BL_SUPPORT
memset(&props, 0, sizeof(struct backlight_properties));
@@ -554,7 +555,7 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
": unable to register backlight.\n");
ret = -EINVAL;
unregister_framebuffer(fbinfo);
- goto out8;
+ goto out7;
}
lcd_dev = lcd_device_register(DRIVER_NAME, NULL, &bfin_lcd_ops);
@@ -563,15 +564,10 @@ static int __devinit bfin_t350mcqb_probe(struct platform_device *pdev)
return 0;
-out8:
- free_irq(info->irq, info);
out7:
bfin_t350mcqb_request_ports(0);
out6:
fb_dealloc_cmap(&fbinfo->cmap);
-out4:
- dma_free_coherent(NULL, fbinfo->fix.smem_len + ACTIVE_VIDEO_MEM_OFFSET,
- info->fb_buffer, info->dma_handle);
out3:
framebuffer_release(fbinfo);
out2:
@@ -591,12 +587,6 @@ static int __devexit bfin_t350mcqb_remove(struct platform_device *pdev)
unregister_framebuffer(fbinfo);
free_dma(CH_PPI);
- free_irq(info->irq, info);
-
- if (info->fb_buffer != NULL)
- dma_free_coherent(NULL, fbinfo->fix.smem_len +
- ACTIVE_VIDEO_MEM_OFFSET, info->fb_buffer,
- info->dma_handle);
fb_dealloc_cmap(&fbinfo->cmap);
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: use devm_ functions
2012-07-31 13:54 ` [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: " Damien Cassou
@ 2012-07-31 13:57 ` Mike Frysinger
2012-07-31 16:18 ` Damien Cassou
0 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2012-07-31 13:57 UTC (permalink / raw)
To: Damien Cassou
Cc: Florian Tobias Schandinat, kernel-janitors, linux-fbdev, linux-kernel
On Tue, Jul 31, 2012 at 9:54 AM, Damien Cassou <damien.cassou@lifl.fr> wrote:
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in
> the probe function of a platform device and is only freed in the remove
> function.
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: use devm_ functions
2012-07-31 13:57 ` Mike Frysinger
@ 2012-07-31 16:18 ` Damien Cassou
0 siblings, 0 replies; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 16:18 UTC (permalink / raw)
To: Mike Frysinger
Cc: Florian Tobias Schandinat, kernel-janitors, linux-fbdev, linux-kernel
On Tue, Jul 31, 2012 at 3:57 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Tue, Jul 31, 2012 at 9:54 AM, Damien Cassou <damien.cassou@lifl.fr> wrote:
>> The various devm_ functions allocate memory that is released when a driver
>> detaches. This patch uses these functions for data that is allocated in
>> the probe function of a platform device and is only freed in the remove
>> function.
>
> Acked-by: Mike Frysinger <vapier@gentoo.org>
This whole patch is invalid, because of this part:
- info->fb_buffer = dma_alloc_coherent(NULL, fbinfo->fix.smem_len +
- ACTIVE_VIDEO_MEM_OFFSET,
- &info->dma_handle, GFP_KERNEL);
+ info->fb_buffer = dmam_alloc_coherent(&pdev->dev, NULL,
+ fbinfo->fix.smem_len +
+ ACTIVE_VIDEO_MEM_OFFSET,
+ &info->dma_handle, GFP_KERNEL);
dmam_alloc_coherent() is called with 5 arguments but only accepts 4.
Please ignore this whole patch altogether.
I am sorry about that.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/5] drivers/video/bf537-lq035.c: use devm_ functions
2012-07-31 13:54 [PATCH 0/5] use devm_ functions Damien Cassou
` (3 preceding siblings ...)
2012-07-31 13:54 ` [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: " Damien Cassou
@ 2012-07-31 13:54 ` Damien Cassou
2012-08-23 20:36 ` Florian Tobias Schandinat
4 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
From: Damien Cassou <damien.cassou@lifl.fr>
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
---
drivers/video/bf537-lq035.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/video/bf537-lq035.c b/drivers/video/bf537-lq035.c
index befbc80..7347aa1 100644
--- a/drivers/video/bf537-lq035.c
+++ b/drivers/video/bf537-lq035.c
@@ -760,18 +760,20 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
bfin_lq035_fb.flags = FBINFO_DEFAULT;
- bfin_lq035_fb.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
+ bfin_lq035_fb.pseudo_palette = devm_kzalloc(&pdev->dev,
+ sizeof(u32) * 16,
+ GFP_KERNEL);
if (bfin_lq035_fb.pseudo_palette == NULL) {
pr_err("failed to allocate pseudo_palette\n");
ret = -ENOMEM;
- goto out_palette;
+ goto out_table;
}
if (fb_alloc_cmap(&bfin_lq035_fb.cmap, NBR_PALETTE, 0) < 0) {
pr_err("failed to allocate colormap (%d entries)\n",
NBR_PALETTE);
ret = -EFAULT;
- goto out_cmap;
+ goto out_table;
}
if (register_framebuffer(&bfin_lq035_fb) < 0) {
@@ -804,9 +806,6 @@ out_lcd:
unregister_framebuffer(&bfin_lq035_fb);
out_reg:
fb_dealloc_cmap(&bfin_lq035_fb.cmap);
-out_cmap:
- kfree(bfin_lq035_fb.pseudo_palette);
-out_palette:
out_table:
dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
fb_buffer = NULL;
@@ -834,7 +833,6 @@ static int __devexit bfin_lq035_remove(struct platform_device *pdev)
free_dma(CH_PPI);
- kfree(bfin_lq035_fb.pseudo_palette);
fb_dealloc_cmap(&bfin_lq035_fb.cmap);
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 1/5] drivers/video/bf537-lq035.c: use devm_ functions
2012-07-31 13:54 ` [PATCH 1/5] drivers/video/bf537-lq035.c: " Damien Cassou
@ 2012-08-23 20:36 ` Florian Tobias Schandinat
0 siblings, 0 replies; 15+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:36 UTC (permalink / raw)
To: Damien Cassou; +Cc: kernel-janitors, linux-fbdev, linux-kernel
On 07/31/2012 01:54 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
>
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in
> the probe function of a platform device and is only freed in the remove
> function.
>
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
Applied.
Thanks,
Florian Tobias Schandinat
>
> ---
> drivers/video/bf537-lq035.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/video/bf537-lq035.c b/drivers/video/bf537-lq035.c
> index befbc80..7347aa1 100644
> --- a/drivers/video/bf537-lq035.c
> +++ b/drivers/video/bf537-lq035.c
> @@ -760,18 +760,20 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
> bfin_lq035_fb.flags = FBINFO_DEFAULT;
>
>
> - bfin_lq035_fb.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
> + bfin_lq035_fb.pseudo_palette = devm_kzalloc(&pdev->dev,
> + sizeof(u32) * 16,
> + GFP_KERNEL);
> if (bfin_lq035_fb.pseudo_palette == NULL) {
> pr_err("failed to allocate pseudo_palette\n");
> ret = -ENOMEM;
> - goto out_palette;
> + goto out_table;
> }
>
> if (fb_alloc_cmap(&bfin_lq035_fb.cmap, NBR_PALETTE, 0) < 0) {
> pr_err("failed to allocate colormap (%d entries)\n",
> NBR_PALETTE);
> ret = -EFAULT;
> - goto out_cmap;
> + goto out_table;
> }
>
> if (register_framebuffer(&bfin_lq035_fb) < 0) {
> @@ -804,9 +806,6 @@ out_lcd:
> unregister_framebuffer(&bfin_lq035_fb);
> out_reg:
> fb_dealloc_cmap(&bfin_lq035_fb.cmap);
> -out_cmap:
> - kfree(bfin_lq035_fb.pseudo_palette);
> -out_palette:
> out_table:
> dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
> fb_buffer = NULL;
> @@ -834,7 +833,6 @@ static int __devexit bfin_lq035_remove(struct platform_device *pdev)
> free_dma(CH_PPI);
>
>
> - kfree(bfin_lq035_fb.pseudo_palette);
> fb_dealloc_cmap(&bfin_lq035_fb.cmap);
>
>
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 0/5] use devm_ functions
@ 2012-07-31 16:39 Damien Cassou
0 siblings, 0 replies; 15+ messages in thread
From: Damien Cassou @ 2012-07-31 16:39 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
These patches introduce devm_ functions in some video drivers.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 0/5] use devm_ functions
@ 2012-08-03 15:40 Damien Cassou
0 siblings, 0 replies; 15+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel
These patches introduce devm_ functions in some video drivers. They have been
generated using Coccinelle (http://coccinelle.lip6.fr/) and the following
semantic patch:
virtual after_start
virtual returned
virtual returnedDup
virtual arg
virtual argDup
virtual all_args
virtual get
virtual nonull
virtual report
// ---------------------------------------------------------------------
// find functions
@plat depends on !after_start@
identifier i,pfn,rfn;
position p;
@@
struct platform_driver i@p = {
.probe = pfn,
.remove = (<+...rfn...+>),
};
// ---------------------------------------------------------------------
// set up iteration
@initialize:ocaml@
let reporting = ref false
type ret =
UseReturned | UseReturned2 of string | UseReturnedDup | UseReturnedNN
| UseArg | UseArgDup | UseArgNN | UseAllArgs | UseGet
let add pfn rfn alloc free devm_alloc file rule =
let it = new iteration() in
it#set_files [file];
it#add_virtual_rule After_start;
(match rule with
UseReturned -> it#add_virtual_rule Returned
| UseReturnedNN -> it#add_virtual_rule Returned; it#add_virtual_rule Nonull
| UseReturnedDup -> it#add_virtual_rule ReturnedDup
| UseReturned2(free) -> it#add_virtual_rule Returned;
it#add_virtual_identifier Second_free free
| UseArg -> it#add_virtual_rule Arg
| UseArgNN -> it#add_virtual_rule Arg; it#add_virtual_rule Nonull
| UseArgDup -> it#add_virtual_rule ArgDup
| UseAllArgs -> it#add_virtual_rule All_args
| UseGet -> it#add_virtual_rule Get);
if !reporting then it#add_virtual_rule Report;
if not (pfn="") then it#add_virtual_identifier Pfn pfn;
if not (rfn="") then it#add_virtual_identifier Rfn rfn;
if not (alloc="") then it#add_virtual_identifier Alloc alloc;
if not (free="") then it#add_virtual_identifier Free free;
if not (devm_alloc="") then it#add_virtual_identifier Devm_alloc devm_alloc;
it#register()
@script:ocaml depends on report && !after_start@
@@
reporting := true
@script:ocaml@
pfn << plat.pfn;
rfn << plat.rfn;
p << plat.p;
@@
let file = (List.hd p).file in
add pfn rfn "kmalloc" "kfree" "devm_kzalloc" file UseReturned;
add pfn rfn "kzalloc" "kfree" "devm_kzalloc" file UseReturned;
add pfn rfn "ioremap" "iounmap" "devm_ioremap" file UseReturned;
add pfn rfn "ioremap_nocache" "iounmap" "devm_ioremap_nocache" file
UseReturned;
add pfn rfn "clk_get" "clk_put" "devm_clk_get" file UseReturnedDup;
add pfn rfn "clk_get" "clk_put" "devm_clk_get_bad" file UseReturnedNN;
add pfn rfn "usb_get_phy" "usb_put_phy" "devm_usb_get_phy" file UseReturned;
add pfn rfn "pinctrl_get" "pinctrl_put" "devm_pinctrl_get" file UseReturned;
add pfn rfn "pinctrl_get_select_default" "pinctrl_put"
"devm_pinctrl_get_select_default" file UseReturned;
add pfn rfn "regulator_get" "regulator_put" "devm_regulator_get"
file UseReturned;
add pfn rfn "regulator_bulk_get" "regulator_bulk_free"
"devm_regulator_bulk_get" file UseAllArgs;
add pfn rfn "gpio_request" "gpio_free" "devm_gpio_request" file UseArg;
add pfn rfn "gpio_request_one" "gpio_free" "devm_gpio_request_one" file UseArg;
(*
add pfn rfn "request_irq" "free_irq" "devm_request_irq" file UseArg;
add pfn rfn "request_threaded_irq" "free_irq" "devm_request_threaded_irq" file
UseArg;
*)
add pfn rfn "dma_alloc_coherent" "dma_free_coherent" "dmam_alloc_coherent"
file UseReturnedDup;
add pfn rfn "dma_alloc_noncoherent" "dma_free_noncoherent"
"dmam_alloc_noncoherent" file UseReturnedDup;
add pfn rfn "dma_alloc_coherent" "dma_free_coherent" "dmam_alloc_coherent_bad"
file UseReturnedNN;
add pfn rfn "dma_alloc_noncoherent" "dma_free_noncoherent"
"dmam_alloc_noncoherent_bad" file UseReturnedNN;
(* several possibilities... *)
add pfn rfn "request_region" "release_region" "devm_request_region" file
UseGet;
add pfn rfn "request_mem_region" "release_mem_region"
"devm_request_mem_region" file UseGet;
add pfn rfn "request_region" "release_region" "devm_request_region" file
UseArg;
add pfn rfn "request_mem_region" "release_mem_region"
"devm_request_mem_region" file UseArg;
(* fix a bug at the same time *)
add pfn rfn "request_region" "release_resource" "devm_request_region" file
(UseReturned2("kfree"));
add pfn rfn "request_mem_region" "release_resource"
"devm_request_mem_region" file (UseReturned2("kfree"));
add pfn rfn "ioport_map" "ioport_unmap" "devm_ioport_map" file UseReturned
// ---------------------------------------------------------------------
// process the initial definition of the probe function
@preprobe@
identifier virtual.pfn;
position p;
@@
pfn@p(...) { ... }
@probe@
identifier pfn;
position preprobe.p;
@@
pfn@p(...) { ... }
@labelled_return@
identifier probe.pfn,l;
expression e;
@@
pfn(...) { <+... l: return e; ...+> }
// ---------------------------------------------------------------------
// transform functions where free uses the result
@prb depends on returned exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free,virtual.second_free;
expression x,y,e,a;
position p1,p2,p3;
type T1,T2,T3;
@@
pfn(struct platform_device *pdev) { ... when any
x = (T1)alloc@p1(a,...)
<... when strict
when any
when forall
(
y = x;
... when != y = e
when != &y
free@p2(...,(T2)y,...);
... when != x
when != y
second_free@p3(...,(T3)y,...);
|
y = x;
... when != y = e
when != &y
free@p2(...,(T2)y,...);
|
free@p2(...,(T2)x,...);
... when != x
second_free@p3(...,(T3)x,...);
|
free@p2(...,(T2)x,...);
)
...>
}
@script:ocaml@
a << prb.a;
@@
if a = "NULL" then Coccilib.include_match false
@reme exists@
identifier virtual.rfn,virtual.free;
expression prb.x,prb.y;
type T;
@@
rfn(...) { ... free(...,(T)\(x\|y\),...); ... }
@rem depends on reme@
identifier virtual.rfn,virtual.free,virtual.second_free;
expression prb.x,prb.y;
position p4,p5;
type T,T1;
@@
rfn(...) {
<... when strict
(
free@p4(...,(T)\(x\|y\),...);
... when != x
second_free@p5(...,(T1)\(x\|y\),...);
|
free@p4(...,(T)\(x\|y\),...);
)
...>
}
@bad@
identifier virtual.free;
expression prb.x,prb.y;
position p != {prb.p2,rem.p4};
type T;
@@
free@p(...,(T)\(x\|y\),...)
@modif depends on rem && !bad && !report@
expression x;
identifier prb.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
identifier virtual.second_free;
expression list args;
position prb.p1,prb.p2,prb.p3,rem.p4,rem.p5;
type T;
@@
(
- free@p2(...);
|
- second_free@p3(...);
|
- free@p4(...);
|
- second_free@p5(...);
|
x =
- alloc@p1(
+ devm_alloc(&pdev->dev,
args)
|
x =
- (T)alloc@p1(
+ (T)devm_alloc(&pdev->dev,
args)
)
@script:python depends on rem && !bad && report@
p1 << prb.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)
// ---------------------------------------------------------------------
// transform functions where free uses the result
// special case for clk where don't add &pdev->dev
@prbdup depends on returnedDup exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free,virtual.second_free;
expression x,y,e;
expression list args;
position p1,p2,p3;
type T1,T2,T3;
@@
pfn(struct platform_device *pdev) { ... when any
x = (T1)alloc@p1(&pdev->dev,args)
<... when strict
when any
when forall
(
y = x;
... when != y = e
when != &y
free@p2(...,(T2)y,...);
... when != x
when != y
second_free@p3(...,(T3)y,...);
|
y = x;
... when != y = e
when != &y
free@p2(...,(T2)y,...);
|
free@p2(...,(T2)x,...);
... when != x
second_free@p3(...,(T3)x,...);
|
free@p2(...,(T2)x,...);
)
...>
}
@remdupe exists@
identifier virtual.rfn,virtual.free;
expression prbdup.x,prbdup.y;
type T;
@@
rfn(...) { ... free(...,(T)\(x\|y\),...); ... }
@remdup depends on remdupe@
identifier virtual.rfn,virtual.free,virtual.second_free;
expression prbdup.x,prbdup.y;
position p4,p5;
type T,T1;
@@
rfn(...) {
<... when strict
(
free@p4(...,(T)\(x\|y\),...);
... when != x
second_free@p5(...,(T1)\(x\|y\),...);
|
free@p4(...,(T)\(x\|y\),...);
)
...>
}
@baddup@
identifier virtual.free;
expression prbdup.x,prbdup.y;
position p != {prbdup.p2,remdup.p4};
type T;
@@
free@p(...,(T)\(x\|y\),...)
@modifdup depends on remdup && !baddup && !report@
expression x;
identifier virtual.alloc,virtual.free,virtual.devm_alloc;
identifier virtual.second_free;
expression list args;
position prbdup.p1,prbdup.p2,prbdup.p3,remdup.p4,remdup.p5;
type T;
@@
(
- free@p2(...);
|
- second_free@p3(...);
|
- free@p4(...);
|
- second_free@p5(...);
|
x =
- alloc@p1
+ devm_alloc
(args)
|
x =
- (T)alloc@p1
+ (T)devm_alloc
(args)
)
@script:python depends on remdup && !baddup && report@
p1 << prbdup.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)
// ---------------------------------------------------------------------
// transform functions where free uses the first argument
@prbx depends on arg exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression x,y,e;
expression list args;
position p1,p2;
@@
pfn(struct platform_device *pdev) { ... when any
alloc@p1(x,args)
<... when strict
when any
when forall
(
y = x;
... when != y = e
when != &y
free@p2(y,...);
|
free@p2(x,...)
)
...>
}
@script:ocaml@
x << prbx.x;
@@
if x = "NULL" then Coccilib.include_match false
@remxe exists@
identifier virtual.rfn, virtual.free;
expression prbx.x,prbx.y;
@@
rfn(...) { ... free(\(x\|y\),...); ... }
@remx depends on remxe@
identifier virtual.rfn, virtual.free;
expression prbx.x,prbx.y;
position p3;
@@
rfn(...) {
<... when strict
free@p3(\(x\|y\),...)
...>
}
@badx@
identifier virtual.free;
expression prbx.x,prbx.y;
position p != {prbx.p2,remx.p3};
@@
free@p(\(x\|y\),...)
@modifx depends on remx && !badx && !report@
expression x;
identifier prbx.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
expression list args;
position prbx.p1,prbx.p2,remx.p3;
@@
(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1(
+ devm_alloc(&pdev->dev,
x,args)
)
@script:python depends on remx && !badx && report@
p1 << prbx.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)
// ---------------------------------------------------------------------
// transform functions where free uses the first argument
@prbxdup depends on argDup exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression y,e;
expression list args;
position p1,p2;
@@
pfn(struct platform_device *pdev) { ... when any
alloc@p1(&pdev->dev,args)
<... when strict
when any
when forall
(
y = &pdev->dev;
... when != y = e
when != &y
free@p2(y,...);
|
free@p2(&pdev->dev,...)
)
...>
}
@remxedup exists@
identifier virtual.rfn, virtual.free, prbxdup.pdev;
expression prbxdup.y;
@@
rfn(...) { ... free(\(&pdev->dev\|y\),...); ... }
@remxdup depends on remxedup@
identifier virtual.rfn, virtual.free, prbxdup.pdev;
expression prbxdup.y;
position p3;
@@
rfn(...) {
<... when strict
free@p3(\(&pdev->dev\|y\),...)
...>
}
@badxdup@
identifier virtual.free,prbxdup.pdev;
expression prbxdup.y;
position p != {prbxdup.p2,remxdup.p3};
@@
free@p(\(&pdev->dev\|y\),...)
@modifxdup depends on remxdup && !badxdup && !report@
identifier virtual.alloc,virtual.free,virtual.devm_alloc;
expression list args;
position prbxdup.p1,prbxdup.p2,remxdup.p3;
@@
(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1
+ devm_alloc
(args)
)
@script:python depends on remxdup && !badxdup && report@
p1 << prbxdup.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)
// ---------------------------------------------------------------------
// transform functions where free uses all arguments
@prbax depends on all_args exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression list x;
position p1,p2;
@@
pfn(struct platform_device *pdev) { ... when any
alloc@p1(x)
<... when strict
when any
when forall
free@p2(x)
...>
}
@remaxe exists@
identifier virtual.rfn, virtual.free;
expression list prbax.x;
@@
rfn(...) { ... free(x); ... }
@remax depends on remaxe@
identifier virtual.rfn, virtual.free;
expression list prbax.x;
position p3;
@@
rfn(...) {
<... when strict
free@p3(x)
...>
}
@badax@
identifier virtual.free;
expression list prbax.x;
position p != {prbax.p2,remax.p3};
@@
free@p(x)
@modifax depends on remax && !badax && !report@
identifier prbax.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
expression list x;
position prbax.p1,prbax.p2,remax.p3;
@@
(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1(
+ devm_alloc(&pdev->dev,
x)
)
@script:python depends on remax && !badax && report@
p1 << prbax.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)
// ---------------------------------------------------------------------
// transform functions where free uses the result of platform_get_resource
@prbg depends on get exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression x,y,e;
expression list args;
position p1,p2;
@@
pfn(struct platform_device *pdev) { ... when any
alloc@p1(x,args)
<... when strict
when any
when forall
(
y = x;
... when != y = e
when != &y
free@p2(y,...);
|
free@p2(x,...)
)
...>
}
@remge exists@
identifier virtual.rfn, virtual.free;
identifier z;
identifier pdev;
expression e,n;
@@
rfn(struct platform_device *pdev) { ... when any
z = platform_get_resource(pdev, IORESOURCE_MEM, n)
... when != z = e
when != &z
free(z->start,...)
...
}
@remg depends on remge@
identifier virtual.rfn, virtual.free;
identifier z;
identifier pdev;
position p3;
expression e,n;
@@
rfn(struct platform_device *pdev) {
<... when strict
z = platform_get_resource(pdev, IORESOURCE_MEM, n)
... when strict
when != z = e
when != &z
free@p3(z->start,...)
...>
}
@badg@
identifier virtual.free;
position p != {prbg.p2,remg.p3};
@@
free@p(...)
@modifg depends on remg && !badg && !report@
expression x;
identifier prbg.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
expression list args;
position prbg.p1,prbg.p2,remg.p3;
@@
(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1(
+ devm_alloc(&pdev->dev,
x,args)
)
@script:python depends on remg && !badg && report@
p1 << prbg.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)
// ---------------------------------------------------------------------
// cleanup, if the drvdata was only used to enable the free
// probably only relevant for kmalloc/kzalloc
@dclean depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn, pdev, i;
type T;
@@
rfn(struct platform_device *pdev) { ...
(
- T i = platform_get_drvdata(pdev);
|
- T i = dev_get_drvdata(&pdev->drv);
|
- T i;
... when != i
(
- i = platform_get_drvdata(pdev);
|
- i = dev_get_drvdata(&pdev->drv);
)
)
... when != i
}
@rclean depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn, pdev, i;
type T;
@@
rfn(struct platform_device *pdev) { ...
(
- T i = platform_get_resource(pdev,...);
|
- T i;
... when != i
- i = platform_get_resource(pdev,...);
)
... when != i
}
// ---------------------------------------------------------------------
// cleanup empty ifs, etc
@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier probe.pfn;
@@
pfn(...) { <...
- if (...) {}
...> }
@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn;
@@
rfn(...) { <...
- if (...) {}
...> }
@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier probe.pfn;
expression ret,e;
@@
pfn(...) { <...
+ return
- ret =
e;
- return ret;
...> }
@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn;
expression ret,e;
@@
rfn(...) { <...
+ return
- ret =
e;
- return ret;
...> }
// ---------------------------------------------------------------------
// this is likely to leave dead code, if l: is preceded by a return
// because we are control-flow based, there is no way to match on that
@depends on labelled_return && (modif || modifdup || modifx || modifxdup || modifax || modifg)@
identifier l,l1,l2;
expression e;
statement S;
identifier probe.pfn;
identifier i;
statement S1,S2;
@@
pfn(...) { <...
- goto l;
+ goto l2;
...
-l:
<... when != S
when any
l1:
...>
l2:
(
(<+...i...+>);
|
if (...) S1 else S2
|
while (...) S1
|
for (...;...;...) S1
|
return e;
)
...> }
@depends on !labelled_return && (modif || modifdup || modifx || modifxdup || modifax || modifg)@
identifier l,l1,l2;
expression e;
statement S;
identifier probe.pfn;
identifier i;
statement S1,S2;
@@
pfn(...) { <...
(
- goto l;
+ goto l2;
...
-l:
<... when != S
when any
l1:
...>
l2:
(
(<+...i...+>);
|
if (...) S1 else S2
|
while (...) S1
|
for (...;...;...) S1
)
|
- goto l;
+ return e;
...
-l:
<... when != S
when any
l1:
...>
return e;
)
...> }
@depends on !labelled_return && (modif || modifdup || modifx || modifxdup || modifax || modifg)@
expression e1,e2;
identifier probe.pfn;
@@
pfn(...) { <...
-e1 = e2;
-return e1;
+return e2;
...> }
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2012-08-23 20:36 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-31 13:54 [PATCH 0/5] use devm_ functions Damien Cassou
2012-07-31 13:54 ` [PATCH 5/5] drivers/video/ep93xx-fb.c: " Damien Cassou
2012-08-23 20:35 ` Florian Tobias Schandinat
2012-07-31 13:54 ` [PATCH 4/5] drivers/video/da8xx-fb.c: " Damien Cassou
2012-07-31 15:47 ` Sachin Kamat
2012-07-31 16:01 ` Damien Cassou
2012-07-31 13:54 ` [PATCH 3/5] drivers/video/cobalt_lcdfb.c: " Damien Cassou
2012-08-23 20:36 ` Florian Tobias Schandinat
2012-07-31 13:54 ` [PATCH 2/5] drivers/video/bfin-t350mcqb-fb.c: " Damien Cassou
2012-07-31 13:57 ` Mike Frysinger
2012-07-31 16:18 ` Damien Cassou
2012-07-31 13:54 ` [PATCH 1/5] drivers/video/bf537-lq035.c: " Damien Cassou
2012-08-23 20:36 ` Florian Tobias Schandinat
2012-07-31 16:39 [PATCH 0/5] " Damien Cassou
2012-08-03 15:40 Damien Cassou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).