Skip to content

Commit 1c16697

Browse files
JuliaLawallschandinat
authored andcommitted
drivers/video/au*fb.c: use devm_ functions
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. In au1100fb.c, the probe function now returns -ENODEV on failure. Signed-off-by: Julia Lawall <[email protected]> Acked-by: Manuel Lauss <[email protected]> Signed-off-by: Florian Tobias Schandinat <[email protected]>
1 parent 92a9c19 commit 1c16697

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

drivers/video/au1100fb.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
477477
u32 sys_clksrc;
478478

479479
/* Allocate new device private */
480-
fbdev = kzalloc(sizeof(struct au1100fb_device), GFP_KERNEL);
480+
fbdev = devm_kzalloc(&dev->dev, sizeof(struct au1100fb_device),
481+
GFP_KERNEL);
481482
if (!fbdev) {
482483
print_err("fail to allocate device private record");
483484
return -ENOMEM;
@@ -498,8 +499,9 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
498499
au1100fb_fix.mmio_start = regs_res->start;
499500
au1100fb_fix.mmio_len = resource_size(regs_res);
500501

501-
if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
502-
DRIVER_NAME)) {
502+
if (!devm_request_mem_region(au1100fb_fix.mmio_start,
503+
au1100fb_fix.mmio_len,
504+
DRIVER_NAME)) {
503505
print_err("fail to lock memory region at 0x%08lx",
504506
au1100fb_fix.mmio_start);
505507
return -EBUSY;
@@ -514,8 +516,9 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
514516
fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
515517
(fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
516518

517-
fbdev->fb_mem = dma_alloc_coherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len),
518-
&fbdev->fb_phys, GFP_KERNEL);
519+
fbdev->fb_mem = dmam_alloc_coherent(&dev->dev, &dev->dev,
520+
PAGE_ALIGN(fbdev->fb_len),
521+
&fbdev->fb_phys, GFP_KERNEL);
519522
if (!fbdev->fb_mem) {
520523
print_err("fail to allocate frambuffer (size: %dK))",
521524
fbdev->fb_len / 1024);
@@ -557,14 +560,14 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
557560
fbdev->info.fbops = &au1100fb_ops;
558561
fbdev->info.fix = au1100fb_fix;
559562

560-
if (!(fbdev->info.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL))) {
563+
fbdev->info.pseudo_palette =
564+
devm_kzalloc(&dev->dev, sizeof(u32) * 16, GFP_KERNEL);
565+
if (!fbdev->info.pseudo_palette)
561566
return -ENOMEM;
562-
}
563567

564568
if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
565569
print_err("Fail to allocate colormap (%d entries)",
566570
AU1100_LCD_NBR_PALETTE_ENTRIES);
567-
kfree(fbdev->info.pseudo_palette);
568571
return -EFAULT;
569572
}
570573

@@ -582,20 +585,16 @@ static int __devinit au1100fb_drv_probe(struct platform_device *dev)
582585
return 0;
583586

584587
failed:
585-
if (fbdev->regs) {
586-
release_mem_region(fbdev->regs_phys, fbdev->regs_len);
587-
}
588588
if (fbdev->fb_mem) {
589589
dma_free_noncoherent(&dev->dev, fbdev->fb_len, fbdev->fb_mem,
590590
fbdev->fb_phys);
591591
}
592592
if (fbdev->info.cmap.len != 0) {
593593
fb_dealloc_cmap(&fbdev->info.cmap);
594594
}
595-
kfree(fbdev);
596595
platform_set_drvdata(dev, NULL);
597596

598-
return 0;
597+
return -ENODEV;
599598
}
600599

601600
int au1100fb_drv_remove(struct platform_device *dev)
@@ -615,14 +614,7 @@ int au1100fb_drv_remove(struct platform_device *dev)
615614
/* Clean up all probe data */
616615
unregister_framebuffer(&fbdev->info);
617616

618-
release_mem_region(fbdev->regs_phys, fbdev->regs_len);
619-
620-
dma_free_coherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem,
621-
fbdev->fb_phys);
622-
623617
fb_dealloc_cmap(&fbdev->info.cmap);
624-
kfree(fbdev->info.pseudo_palette);
625-
kfree((void*)fbdev);
626618

627619
return 0;
628620
}

drivers/video/au1200fb.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ static int __devinit au1200fb_drv_probe(struct platform_device *dev)
17241724
/* Allocate the framebuffer to the maximum screen size */
17251725
fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
17261726

1727-
fbdev->fb_mem = dma_alloc_noncoherent(&dev->dev,
1727+
fbdev->fb_mem = dmam_alloc_noncoherent(&dev->dev, &dev->dev,
17281728
PAGE_ALIGN(fbdev->fb_len),
17291729
&fbdev->fb_phys, GFP_KERNEL);
17301730
if (!fbdev->fb_mem) {
@@ -1788,9 +1788,6 @@ static int __devinit au1200fb_drv_probe(struct platform_device *dev)
17881788

17891789
failed:
17901790
/* NOTE: This only does the current plane/window that failed; others are still active */
1791-
if (fbdev->fb_mem)
1792-
dma_free_noncoherent(&dev->dev, PAGE_ALIGN(fbdev->fb_len),
1793-
fbdev->fb_mem, fbdev->fb_phys);
17941791
if (fbi) {
17951792
if (fbi->cmap.len != 0)
17961793
fb_dealloc_cmap(&fbi->cmap);
@@ -1817,10 +1814,6 @@ static int __devexit au1200fb_drv_remove(struct platform_device *dev)
18171814

18181815
/* Clean up all probe data */
18191816
unregister_framebuffer(fbi);
1820-
if (fbdev->fb_mem)
1821-
dma_free_noncoherent(&dev->dev,
1822-
PAGE_ALIGN(fbdev->fb_len),
1823-
fbdev->fb_mem, fbdev->fb_phys);
18241817
if (fbi->cmap.len != 0)
18251818
fb_dealloc_cmap(&fbi->cmap);
18261819
kfree(fbi->pseudo_palette);

0 commit comments

Comments
 (0)