Skip to content

Commit

Permalink
video: fbdev: imxfb: Convert request_mem_region + ioremap to devm_ior…
Browse files Browse the repository at this point in the history
…emap_resource

This has several advantages:

 - No need for manual undo of the two functions in the error path and
   the remove function.
 - Drops error handling in .remove()
   Note that returning early in .remove() yields resource leaks that
   often result in access of freed memory or unmapped registers later.
 - Fixes a resource leak
   request_mem_region allocates memory for the returned pointer that was
   never freed.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Helge Deller <deller@gmx.de>
  • Loading branch information
Uwe Kleine-König authored and hdeller committed Jul 26, 2022
1 parent ded77a7 commit b083c22
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions drivers/video/fbdev/imxfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,13 +937,6 @@ static int imxfb_probe(struct platform_device *pdev)
info->fix.smem_len = max_t(size_t, info->fix.smem_len,
m->mode.xres * m->mode.yres * bytes_per_pixel);

res = request_mem_region(res->start, resource_size(res),
DRIVER_NAME);
if (!res) {
ret = -EBUSY;
goto failed_req;
}

fbi->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(fbi->clk_ipg)) {
ret = PTR_ERR(fbi->clk_ipg);
Expand Down Expand Up @@ -977,7 +970,7 @@ static int imxfb_probe(struct platform_device *pdev)
goto failed_getclock;
}

fbi->regs = ioremap(res->start, resource_size(res));
fbi->regs = devm_ioremap_resource(&pdev->dev, res);
if (fbi->regs == NULL) {
dev_err(&pdev->dev, "Cannot map frame buffer registers\n");
ret = -ENOMEM;
Expand Down Expand Up @@ -1049,11 +1042,9 @@ static int imxfb_probe(struct platform_device *pdev)
dma_free_wc(&pdev->dev, fbi->map_size, info->screen_buffer,
fbi->map_dma);
failed_map:
iounmap(fbi->regs);
failed_ioremap:
failed_getclock:
release_mem_region(res->start, resource_size(res));
failed_req:
failed_of_parse:
kfree(info->pseudo_palette);
failed_init:
Expand All @@ -1065,20 +1056,13 @@ static int imxfb_remove(struct platform_device *pdev)
{
struct fb_info *info = platform_get_drvdata(pdev);
struct imxfb_info *fbi = info->par;
struct resource *res;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -EINVAL;

imxfb_disable_controller(fbi);

unregister_framebuffer(info);
fb_dealloc_cmap(&info->cmap);
dma_free_wc(&pdev->dev, fbi->map_size, info->screen_buffer,
fbi->map_dma);
iounmap(fbi->regs);
release_mem_region(res->start, resource_size(res));
kfree(info->pseudo_palette);
framebuffer_release(info);

Expand Down

0 comments on commit b083c22

Please sign in to comment.