提交 ee9a25e5 编写于 作者: M Maciej W. Rozycki 提交者: Linus Torvalds

[PATCH] tgafb: switch to framebuffer_alloc()

This is a set of changes to update the driver to the framebuffer_alloc() API.
Included, there is also a fix to a memory leak due to the colour map
allocation not being freed upon driver's removal.  Aside from the fix there
are no functional changes.
Signed-off-by: NMaciej W. Rozycki <macro@linux-mips.org>
Cc: James Simmons <jsimmons@infradead.org>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 e019630e
...@@ -1342,14 +1342,10 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1342,14 +1342,10 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
TGA_24PLUSZ_FB_OFFSET TGA_24PLUSZ_FB_OFFSET
}; };
struct all_info {
struct fb_info info;
struct tga_par par;
u32 pseudo_palette[16];
} *all;
void __iomem *mem_base; void __iomem *mem_base;
unsigned long bar0_start, bar0_len; unsigned long bar0_start, bar0_len;
struct fb_info *info;
struct tga_par *par;
u8 tga_type; u8 tga_type;
int ret; int ret;
...@@ -1360,13 +1356,14 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1360,13 +1356,14 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
} }
/* Allocate the fb and par structures. */ /* Allocate the fb and par structures. */
all = kmalloc(sizeof(*all), GFP_KERNEL); info = framebuffer_alloc(sizeof(struct tga_par), &pdev->dev);
if (!all) { if (!info) {
printk(KERN_ERR "tgafb: Cannot allocate memory\n"); printk(KERN_ERR "tgafb: Cannot allocate memory\n");
return -ENOMEM; return -ENOMEM;
} }
memset(all, 0, sizeof(*all));
pci_set_drvdata(pdev, all); par = info->par;
pci_set_drvdata(pdev, info);
/* Request the mem regions. */ /* Request the mem regions. */
bar0_start = pci_resource_start(pdev, 0); bar0_start = pci_resource_start(pdev, 0);
...@@ -1386,25 +1383,23 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1386,25 +1383,23 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
/* Grab info about the card. */ /* Grab info about the card. */
tga_type = (readl(mem_base) >> 12) & 0x0f; tga_type = (readl(mem_base) >> 12) & 0x0f;
all->par.pdev = pdev; par->pdev = pdev;
all->par.tga_mem_base = mem_base; par->tga_mem_base = mem_base;
all->par.tga_fb_base = mem_base + fb_offset_presets[tga_type]; par->tga_fb_base = mem_base + fb_offset_presets[tga_type];
all->par.tga_regs_base = mem_base + TGA_REGS_OFFSET; par->tga_regs_base = mem_base + TGA_REGS_OFFSET;
all->par.tga_type = tga_type; par->tga_type = tga_type;
pci_read_config_byte(pdev, PCI_REVISION_ID, &all->par.tga_chip_rev); pci_read_config_byte(pdev, PCI_REVISION_ID, &par->tga_chip_rev);
/* Setup framebuffer. */ /* Setup framebuffer. */
all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT; FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT;
all->info.fbops = &tgafb_ops; info->fbops = &tgafb_ops;
all->info.screen_base = all->par.tga_fb_base; info->screen_base = par->tga_fb_base;
all->info.par = &all->par; info->pseudo_palette = (void *)(par + 1);
all->info.pseudo_palette = all->pseudo_palette;
/* This should give a reasonable default video mode. */ /* This should give a reasonable default video mode. */
ret = fb_find_mode(&all->info.var, &all->info, mode_option, ret = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL,
NULL, 0, NULL,
tga_type == TGA_TYPE_8PLANE ? 8 : 32); tga_type == TGA_TYPE_8PLANE ? 8 : 32);
if (ret == 0 || ret == 4) { if (ret == 0 || ret == 4) {
printk(KERN_ERR "tgafb: Could not find valid video mode\n"); printk(KERN_ERR "tgafb: Could not find valid video mode\n");
...@@ -1412,29 +1407,28 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1412,29 +1407,28 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
goto err1; goto err1;
} }
if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { if (fb_alloc_cmap(&info->cmap, 256, 0)) {
printk(KERN_ERR "tgafb: Could not allocate color map\n"); printk(KERN_ERR "tgafb: Could not allocate color map\n");
ret = -ENOMEM; ret = -ENOMEM;
goto err1; goto err1;
} }
tgafb_set_par(&all->info); tgafb_set_par(info);
tgafb_init_fix(&all->info); tgafb_init_fix(info);
all->info.device = &pdev->dev; if (register_framebuffer(info) < 0) {
if (register_framebuffer(&all->info) < 0) {
printk(KERN_ERR "tgafb: Could not register framebuffer\n"); printk(KERN_ERR "tgafb: Could not register framebuffer\n");
ret = -EINVAL; ret = -EINVAL;
goto err1; goto err1;
} }
printk(KERN_INFO "tgafb: DC21030 [TGA] detected, rev=0x%02x\n", printk(KERN_INFO "tgafb: DC21030 [TGA] detected, rev=0x%02x\n",
all->par.tga_chip_rev); par->tga_chip_rev);
printk(KERN_INFO "tgafb: at PCI bus %d, device %d, function %d\n", printk(KERN_INFO "tgafb: at PCI bus %d, device %d, function %d\n",
pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->bus->number, PCI_SLOT(pdev->devfn),
PCI_FUNC(pdev->devfn)); PCI_FUNC(pdev->devfn));
printk(KERN_INFO "fb%d: %s frame buffer device at 0x%lx\n", printk(KERN_INFO "fb%d: %s frame buffer device at 0x%lx\n",
all->info.node, all->info.fix.id, bar0_start); info->node, info->fix.id, bar0_start);
return 0; return 0;
...@@ -1443,7 +1437,7 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1443,7 +1437,7 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
iounmap(mem_base); iounmap(mem_base);
release_mem_region(bar0_start, bar0_len); release_mem_region(bar0_start, bar0_len);
err0: err0:
kfree(all); framebuffer_release(info);
return ret; return ret;
} }
...@@ -1456,10 +1450,11 @@ tgafb_pci_unregister(struct pci_dev *pdev) ...@@ -1456,10 +1450,11 @@ tgafb_pci_unregister(struct pci_dev *pdev)
if (!info) if (!info)
return; return;
unregister_framebuffer(info); unregister_framebuffer(info);
fb_dealloc_cmap(&info->cmap);
iounmap(par->tga_mem_base); iounmap(par->tga_mem_base);
release_mem_region(pci_resource_start(pdev, 0), release_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0)); pci_resource_len(pdev, 0));
kfree(info); framebuffer_release(info);
} }
#ifdef MODULE #ifdef MODULE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册