Skip to contentSkip to conversation

: Fix for SBUS framebuffer oops in 2.6.23-rc1

PATCH New David Miller 1 participant 1 message Jul 28, 2007 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Fix for SBUS framebuffer oops in 2.6.23-rc1

Those seeing crashes when using the SBUS framebuffer drivers in 2.6.23-rc1 can try out the following patch which should fix the problem.

Thanks.

commit c962c92edcefb92611f917ab1eb515a98e5b4848

Author: David S. Miller <[email protected]>
Date:   Fri Jul 27 22:31:46 2007 -0700

[VIDEO]: Fix OOPS in all SBUS framebuffer drivers.

All of these drivers use a silly:

struct all_info {
struct fb_info info;
struct foo_par par;
};

struct all_info *all = kzalloc(sizeof(*all), GFP_KERNEL); all->info.par = &all->par;

etc. etc. code sequence, basically replicating the provided framebuffer_alloc()/framebuffer_release(), and doing it badly.

Not only is this massive code duplication, it also caused a bug in that we weren't setting the fb_info->device pointer which results in an OOPS when fb_is_primary_device() runs.

Fix all of this by using framebuffer_{alloc,release}() and passing in "&of_device->dev" as the device pointer.

drivers/video/bw2.c +51 -49
index b0b2e40..718b9f8 100644
@@ -279,90 +279,91 @@ static void __devinit bw2_do_default_mode(struct bw2_par *par,
 	}
 }
 
-struct all_info {
-	struct fb_info info;
-	struct bw2_par par;
-};
-
-static int __devinit bw2_init_one(struct of_device *op)
+static int __devinit bw2_probe(struct of_device *op, const struct of_device_id *match)
 {
 	struct device_node *dp = op->node;
-	struct all_info *all;
+	struct fb_info *info;
+	struct bw2_par *par;
 	int linebytes, err;
 
-	all = kzalloc(sizeof(*all), GFP_KERNEL);
-	if (!all)
-		return -ENOMEM;
+	info = framebuffer_alloc(sizeof(struct bw2_par), &op->dev);
 
-	spin_lock_init(&all->par.lock);
+	err = -ENOMEM;
+	if (!info)
+		goto out_err;
+	par = info->par;
 
-	all->par.physbase = op->resource[0].start;
-	all->par.which_io = op->resource[0].flags & IORESOURCE_BITS;
+	spin_lock_init(&par->lock);
 
-	sbusfb_fill_var(&all->info.var, dp->node, 1);
+	par->physbase = op->resource[0].start;
+	par->which_io = op->resource[0].flags & IORESOURCE_BITS;
+
+	sbusfb_fill_var(&info->var, dp->node, 1);
 	linebytes = of_getintprop_default(dp, "linebytes",
-					  all->info.var.xres);
+					  info->var.xres);
 
-	all->info.var.red.length = all->info.var.green.length -		all->info.var.blue.length = all->info.var.bits_per_pixel;
-	all->info.var.red.offset = all->info.var.green.offset -		all->info.var.blue.offset = 0;
+	info->var.red.length = info->var.green.length +		info->var.blue.length = info->var.bits_per_pixel;
+	info->var.red.offset = info->var.green.offset +		info->var.blue.offset = 0;
 
-	all->par.regs = of_ioremap(&op->resource[0], BWTWO_REGISTER_OFFSET,
-				   sizeof(struct bw2_regs), "bw2 regs");
+	par->regs = of_ioremap(&op->resource[0], BWTWO_REGISTER_OFFSET,
+			       sizeof(struct bw2_regs), "bw2 regs");
+	if (!par->regs)
+		goto out_release_fb;
 
 	if (!of_find_property(dp, "width", NULL))
-		bw2_do_default_mode(&all->par, &all->info, &linebytes);
+		bw2_do_default_mode(par, info, &linebytes);
 
-	all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
+	par->fbsize = PAGE_ALIGN(linebytes * info->var.yres);
 
-	all->info.flags = FBINFO_DEFAULT;
-	all->info.fbops = &bw2_ops;
+	info->flags = FBINFO_DEFAULT;
+	info->fbops = &bw2_ops;
 
-	all->info.screen_base -		of_ioremap(&op->resource[0], 0, all->par.fbsize, "bw2 ram");
-	all->info.par = &all->par;
+	info->screen_base = of_ioremap(&op->resource[0], 0,
+				       par->fbsize, "bw2 ram");
+	if (!info->screen_base)
+		goto out_unmap_regs;
 
-	bw2_blank(0, &all->info);
+	bw2_blank(0, info);
 
-	bw2_init_fix(&all->info, linebytes);
+	bw2_init_fix(info, linebytes);
 
-	err= register_framebuffer(&all->info);
-	if (err < 0) {
-		of_iounmap(&op->resource[0],
-			   all->par.regs, sizeof(struct bw2_regs));
-		of_iounmap(&op->resource[0],
-			   all->info.screen_base, all->par.fbsize);
-		kfree(all);
-		return err;
-	}
+	err = register_framebuffer(info);
+	if (err < 0)
+		goto out_unmap_screen;
 
-	dev_set_drvdata(&op->dev, all);
+	dev_set_drvdata(&op->dev, info);
 
 	printk("%s: bwtwo at %lx:%lx\n",
-	       dp->full_name,
-	       all->par.which_io, all->par.physbase);
+	       dp->full_name, par->which_io, par->physbase);
 
 	return 0;
-}
 
-static int __devinit bw2_probe(struct of_device *dev, const struct of_device_id *match)
-{
-	struct of_device *op = to_of_device(&dev->dev);
+out_unmap_screen:
+	of_iounmap(&op->resource[0], info->screen_base, par->fbsize);
+
+out_unmap_regs:
+	of_iounmap(&op->resource[0], par->regs, sizeof(struct bw2_regs));
+
+out_release_fb:
+	framebuffer_release(info);
 
-	return bw2_init_one(op);
+out_err:
+	return err;
 }
 
 static int __devexit bw2_remove(struct of_device *op)
 {
-	struct all_info *all = dev_get_drvdata(&op->dev);
+	struct fb_info *info = dev_get_drvdata(&op->dev);
+	struct bw2_par *par = info->par;
 
-	unregister_framebuffer(&all->info);
+	unregister_framebuffer(info);
 
-	of_iounmap(&op->resource[0], all->par.regs, sizeof(struct bw2_regs));
-	of_iounmap(&op->resource[0], all->info.screen_base, all->par.fbsize);
+	of_iounmap(&op->resource[0], par->regs, sizeof(struct bw2_regs));
+	of_iounmap(&op->resource[0], info->screen_base, par->fbsize);
 
-	kfree(all);
+	framebuffer_release(info);
 
 	dev_set_drvdata(&op->dev, NULL);
 
drivers/video/cg14.c +72 -78

212 lines not on this page · raw message

drivers/video/cg3.c +67 -68

170 lines not on this page · raw message

drivers/video/cg6.c +73 -88

208 lines not on this page · raw message

drivers/video/ffb.c +79 -91

236 lines not on this page · raw message

drivers/video/leo.c +65 -77

190 lines not on this page · raw message

drivers/video/p9100.c +63 -75

170 lines not on this page · raw message

drivers/video/tcx.c +89 -94

243 lines not on this page · raw message