From 0619d9e8f101320ee0ee95e8071031c9217d50a3 Mon Sep 17 00:00:00 2001 From: Allen Pais Date: Thu, 12 Oct 2017 18:18:23 +0200 Subject: [PATCH 01/42] video: fbdev: matroxfb: return -ENOMEM on allocation failure Signed-off-by: Allen Pais Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/matrox/matroxfb_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/matrox/matroxfb_base.c b/drivers/video/fbdev/matrox/matroxfb_base.c index b9b284d79631..838869c6490c 100644 --- a/drivers/video/fbdev/matrox/matroxfb_base.c +++ b/drivers/video/fbdev/matrox/matroxfb_base.c @@ -2056,7 +2056,7 @@ static int matroxfb_probe(struct pci_dev* pdev, const struct pci_device_id* dumm minfo = kzalloc(sizeof(*minfo), GFP_KERNEL); if (!minfo) - return -1; + return -ENOMEM; minfo->pcidev = pdev; minfo->dead = 0; From 160d9a6b27b71499557d368fb514f8a9fcbde12e Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 12 Oct 2017 18:18:23 +0200 Subject: [PATCH 02/42] video: fbdev: aty: make const arrays static, reduces object code size Don't populate the const arrays ragepro_tbl and ragexl_tbl on the stack, instead make them static. Makes the object code smaller by over 380 bytes: Before: text data bss dec hex filename 41089 10592 768 52449 cce1 atyfb_base.o After: text data bss dec hex filename 40544 10752 768 52064 cb60 atyfb_base.o (gcc version 7.2.0, x86_64) Signed-off-by: Colin Ian King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/aty/atyfb_base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c index 3ec72f19114b..a9a8272f7a6e 100644 --- a/drivers/video/fbdev/aty/atyfb_base.c +++ b/drivers/video/fbdev/aty/atyfb_base.c @@ -2272,10 +2272,10 @@ static void aty_bl_exit(struct backlight_device *bd) static void aty_calc_mem_refresh(struct atyfb_par *par, int xclk) { - const int ragepro_tbl[] = { + static const int ragepro_tbl[] = { 44, 50, 55, 66, 75, 80, 100 }; - const int ragexl_tbl[] = { + static const int ragexl_tbl[] = { 50, 66, 75, 83, 90, 95, 100, 105, 110, 115, 120, 125, 133, 143, 166 }; From b90b3eca16b7ba6f42df35c029b674f1a00b0c69 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 12 Oct 2017 18:18:23 +0200 Subject: [PATCH 03/42] video: fbdev: sis: make const array specialtv static, reduces object code size Don't populate the const array specialtv on the stack, instead make it static. Makes the object code smaller by over 1100 bytes: Before: text data bss dec hex filename 179899 7504 0 187403 2dc0b drivers/video/fbdev/sis/init301.o After: text data bss dec hex filename 178720 7568 0 186288 2d7b0 drivers/video/fbdev/sis/init301.o (gcc version 7.2.0, x86_64) Signed-off-by: Colin Ian King Cc: Thomas Winischhofer Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sis/init301.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/sis/init301.c b/drivers/video/fbdev/sis/init301.c index 1ec9c3e0e1d8..02ee752d5000 100644 --- a/drivers/video/fbdev/sis/init301.c +++ b/drivers/video/fbdev/sis/init301.c @@ -6486,7 +6486,7 @@ SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo) if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) { - const unsigned char specialtv[] = { + static const unsigned char specialtv[] = { 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53, 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a, 0x58,0xe4,0x73,0xda,0x13 From 3961e9ac3a4546a1022988cc93aec0dc29b513de Mon Sep 17 00:00:00 2001 From: Bhumika Goyal Date: Thu, 12 Oct 2017 18:18:23 +0200 Subject: [PATCH 04/42] video: fbdev: dnfb: make fb_var_screeninfo static and const Make this structure static as it is not referenced in any other file. Make it const as it is used only during a copy operation. Signed-off-by: Bhumika Goyal Cc: Julia Lawall [b.zolnierkie: split from combined patch] Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/dnfb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/dnfb.c b/drivers/video/fbdev/dnfb.c index 7b1492d34e98..09415009d797 100644 --- a/drivers/video/fbdev/dnfb.c +++ b/drivers/video/fbdev/dnfb.c @@ -115,7 +115,7 @@ static struct fb_ops dn_fb_ops = { .fb_imageblit = cfb_imageblit, }; -struct fb_var_screeninfo dnfb_var = { +static const struct fb_var_screeninfo dnfb_var = { .xres = 1280, .yres = 1024, .xres_virtual = 2048, From 0c09dd051b0cb9cb949cf8582ff7c9b10bfdfb0f Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 12 Oct 2017 18:28:26 +0200 Subject: [PATCH 05/42] video: fbdev: radeon: make const array post_divs static, reduces object code size Don't populate the read-only const array post_divs on the stack, instead make it static. Makes the object code smaller by 90 bytes: Before: text data bss dec hex filename 40231 8584 896 49711 c22f radeon_base.o After: text data bss dec hex filename 39914 8744 960 49618 c1d2 radeon_base.o (gcc version 7.2.0, x86_64) Signed-off-by: Colin Ian King Cc: Benjamin Herrenschmidt Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/aty/radeon_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c index 1e2ec360f8c1..8ad1643e7d1c 100644 --- a/drivers/video/fbdev/aty/radeon_base.c +++ b/drivers/video/fbdev/aty/radeon_base.c @@ -1534,7 +1534,7 @@ void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode, static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *regs, unsigned long freq) { - const struct { + static const struct { int divider; int bitvalue; } *post_div, From 5eabff1cb9dad4e81ee387ac79f7521d078bfa8f Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 06/42] video: fbdev: pxa3xx_gcu: Use setup_timer and mod_timer Use setup_timer and mod_timer API instead of structure assignments. This is done using Coccinelle and semantic patch used for this as follows: @@ expression x,y,z,a,b; @@ -init_timer (&x); +setup_timer (&x, y, z); +mod_timer (&a, b); -x.function = y; -x.data = z; -x.expires = b; -add_timer(&a); Signed-off-by: Himanshu Jha Cc: "Gustavo A. R. Silva" Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/pxa3xx-gcu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c index 933619da1a94..3366076f9e0f 100644 --- a/drivers/video/fbdev/pxa3xx-gcu.c +++ b/drivers/video/fbdev/pxa3xx-gcu.c @@ -520,12 +520,8 @@ static void pxa3xx_gcu_debug_timedout(unsigned long ptr) QERROR("Timer DUMP"); /* init the timer structure */ - init_timer(&pxa3xx_gcu_debug_timer); - pxa3xx_gcu_debug_timer.function = pxa3xx_gcu_debug_timedout; - pxa3xx_gcu_debug_timer.data = ptr; - pxa3xx_gcu_debug_timer.expires = jiffies + 5*HZ; /* one second */ - - add_timer(&pxa3xx_gcu_debug_timer); + setup_timer(&pxa3xx_gcu_debug_timer, pxa3xx_gcu_debug_timedout, ptr); + mod_timer(&pxa3xx_gcu_debug_timer, jiffies + 5 * HZ); } static void pxa3xx_gcu_init_debug_timer(void) From ba1d36ba09becdc7f65e0140f13b31762ac31941 Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 07/42] video: sa1100fb: use devm_kzalloc() Use devm_kzalloc() when allocating the private data for the framebuffer device. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index fc2aaa5aca23..05a80e08dcde 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1132,12 +1132,11 @@ static struct sa1100fb_info *sa1100fb_init_fbinfo(struct device *dev) struct sa1100fb_info *fbi; unsigned i; - fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16, - GFP_KERNEL); + fbi = devm_kzalloc(dev, sizeof(struct sa1100fb_info) + sizeof(u32) * 16, + GFP_KERNEL); if (!fbi) return NULL; - memset(fbi, 0, sizeof(struct sa1100fb_info)); fbi->dev = dev; strcpy(fbi->fb.fix.id, SA1100_NAME); @@ -1292,7 +1291,6 @@ static int sa1100fb_probe(struct platform_device *pdev) iounmap(fbi->base); if (fbi->clk) clk_put(fbi->clk); - kfree(fbi); release_mem_region(res->start, resource_size(res)); return ret; } From e43064ccd4b47fcb25c7f6806da1e7368312edfe Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 08/42] video: sa1100fb: use devm_clk_get() Use devm_clk_get() to get the clock for the LCD. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index 05a80e08dcde..1562d7607dd2 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1230,10 +1230,9 @@ static int sa1100fb_probe(struct platform_device *pdev) if (!fbi) goto failed; - fbi->clk = clk_get(&pdev->dev, NULL); + fbi->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(fbi->clk)) { ret = PTR_ERR(fbi->clk); - fbi->clk = NULL; goto failed; } @@ -1289,8 +1288,6 @@ static int sa1100fb_probe(struct platform_device *pdev) failed: if (fbi) iounmap(fbi->base); - if (fbi->clk) - clk_put(fbi->clk); release_mem_region(res->start, resource_size(res)); return ret; } From df6b228768db032608edbc58f87bc77d23f94952 Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 09/42] video: sa1100fb: use devm_ioremap_resource() Use devm_ioremap_resource() to map the LCD controller memory region, and remove the unnecessary cleanup for this. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index 1562d7607dd2..ab83970dbfd9 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1217,29 +1217,28 @@ static int sa1100fb_probe(struct platform_device *pdev) return -EINVAL; } - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); irq = platform_get_irq(pdev, 0); - if (irq < 0 || !res) + if (irq < 0) return -EINVAL; - if (!request_mem_region(res->start, resource_size(res), "LCD")) - return -EBUSY; - fbi = sa1100fb_init_fbinfo(&pdev->dev); ret = -ENOMEM; if (!fbi) goto failed; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + fbi->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(fbi->base)) { + ret = PTR_ERR(fbi->base); + goto failed; + } + fbi->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(fbi->clk)) { ret = PTR_ERR(fbi->clk); goto failed; } - fbi->base = ioremap(res->start, resource_size(res)); - if (!fbi->base) - goto failed; - /* Initialize video memory */ ret = sa1100fb_map_video_memory(fbi); if (ret) @@ -1286,9 +1285,6 @@ static int sa1100fb_probe(struct platform_device *pdev) err_free_irq: free_irq(irq, fbi); failed: - if (fbi) - iounmap(fbi->base); - release_mem_region(res->start, resource_size(res)); return ret; } From f6fc8c9dbdc976e4933c5edc13764eafe9897313 Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 10/42] video: sa1100fb: use devm_request_irq() Use devm_request_irq() to request the interrupt (a little earlier too) so we can avoid having to manually clean this up. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index ab83970dbfd9..a48fdb676f3e 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1239,22 +1239,23 @@ static int sa1100fb_probe(struct platform_device *pdev) goto failed; } - /* Initialize video memory */ - ret = sa1100fb_map_video_memory(fbi); - if (ret) - goto failed; - - ret = request_irq(irq, sa1100fb_handle_irq, 0, "LCD", fbi); + ret = devm_request_irq(&pdev->dev, irq, sa1100fb_handle_irq, 0, + "LCD", fbi); if (ret) { dev_err(&pdev->dev, "request_irq failed: %d\n", ret); goto failed; } + /* Initialize video memory */ + ret = sa1100fb_map_video_memory(fbi); + if (ret) + goto failed; + if (machine_is_shannon()) { ret = gpio_request_one(SHANNON_GPIO_DISP_EN, GPIOF_OUT_INIT_LOW, "display enable"); if (ret) - goto err_free_irq; + goto failed; } /* @@ -1282,8 +1283,6 @@ static int sa1100fb_probe(struct platform_device *pdev) err_reg_fb: if (machine_is_shannon()) gpio_free(SHANNON_GPIO_DISP_EN); - err_free_irq: - free_irq(irq, fbi); failed: return ret; } From 5634cbab489e8428f352f257b631c128b8dc869d Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 11/42] video: sa1100fb: use devm_gpio_request_one() Switch to using devm_gpio_request_one() to request the shannon gpio and move the request before the video memory allocation, so we request all device managed resources before this large allocation attempt. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index a48fdb676f3e..7fa6c8f74ec6 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1246,18 +1246,18 @@ static int sa1100fb_probe(struct platform_device *pdev) goto failed; } - /* Initialize video memory */ - ret = sa1100fb_map_video_memory(fbi); - if (ret) - goto failed; - if (machine_is_shannon()) { - ret = gpio_request_one(SHANNON_GPIO_DISP_EN, + ret = devm_gpio_request_one(&pdev->dev, SHANNON_GPIO_DISP_EN, GPIOF_OUT_INIT_LOW, "display enable"); if (ret) goto failed; } + /* Initialize video memory */ + ret = sa1100fb_map_video_memory(fbi); + if (ret) + goto failed; + /* * This makes sure that our colour bitfield * descriptors are correctly initialised. @@ -1268,7 +1268,7 @@ static int sa1100fb_probe(struct platform_device *pdev) ret = register_framebuffer(&fbi->fb); if (ret < 0) - goto err_reg_fb; + goto failed; #ifdef CONFIG_CPU_FREQ fbi->freq_transition.notifier_call = sa1100fb_freq_transition; @@ -1280,9 +1280,6 @@ static int sa1100fb_probe(struct platform_device *pdev) /* This driver cannot be unloaded at the moment */ return 0; - err_reg_fb: - if (machine_is_shannon()) - gpio_free(SHANNON_GPIO_DISP_EN); failed: return ret; } From c244f8e48c9f1875101201eaa0ecd2bfb17a5405 Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:12 +0200 Subject: [PATCH 12/42] video: sa1100fb: clean up failure path We merely return from the failed path, so remove all the gotos and use return statements instead. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index 7fa6c8f74ec6..16a974471c02 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1222,41 +1222,36 @@ static int sa1100fb_probe(struct platform_device *pdev) return -EINVAL; fbi = sa1100fb_init_fbinfo(&pdev->dev); - ret = -ENOMEM; if (!fbi) - goto failed; + return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); fbi->base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(fbi->base)) { - ret = PTR_ERR(fbi->base); - goto failed; - } + if (IS_ERR(fbi->base)) + return PTR_ERR(fbi->base); fbi->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(fbi->clk)) { - ret = PTR_ERR(fbi->clk); - goto failed; - } + if (IS_ERR(fbi->clk)) + return PTR_ERR(fbi->clk); ret = devm_request_irq(&pdev->dev, irq, sa1100fb_handle_irq, 0, "LCD", fbi); if (ret) { dev_err(&pdev->dev, "request_irq failed: %d\n", ret); - goto failed; + return ret; } if (machine_is_shannon()) { ret = devm_gpio_request_one(&pdev->dev, SHANNON_GPIO_DISP_EN, GPIOF_OUT_INIT_LOW, "display enable"); if (ret) - goto failed; + return ret; } /* Initialize video memory */ ret = sa1100fb_map_video_memory(fbi); if (ret) - goto failed; + return ret; /* * This makes sure that our colour bitfield From 0ab76581a9fee0413c54907076fcd79fcc271843 Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:13 +0200 Subject: [PATCH 13/42] video: sa1100fb: fix video memory allocation leak Don't leak the video memory allocation if register_framebuffer() fails. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index 16a974471c02..56d514b5d252 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -1262,8 +1262,11 @@ static int sa1100fb_probe(struct platform_device *pdev) platform_set_drvdata(pdev, fbi); ret = register_framebuffer(&fbi->fb); - if (ret < 0) - goto failed; + if (ret < 0) { + dma_free_wc(fbi->dev, fbi->map_size, fbi->map_cpu, + fbi->map_dma); + return ret; + } #ifdef CONFIG_CPU_FREQ fbi->freq_transition.notifier_call = sa1100fb_freq_transition; @@ -1274,9 +1277,6 @@ static int sa1100fb_probe(struct platform_device *pdev) /* This driver cannot be unloaded at the moment */ return 0; - - failed: - return ret; } static struct platform_driver sa1100fb_driver = { From cb6bc3ff59e3ff7a6fba8ca6ee649d532b4e17f2 Mon Sep 17 00:00:00 2001 From: Russell King Date: Tue, 17 Oct 2017 16:01:13 +0200 Subject: [PATCH 14/42] video: sa1100fb: move pseudo palette into sa1100fb_info structure Move the pseudo palette inside the driver private data structure so we don't have to play tricks to cater for it. Signed-off-by: Russell King Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/sa1100fb.c | 9 +++------ drivers/video/fbdev/sa1100fb.h | 2 ++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/sa1100fb.c b/drivers/video/fbdev/sa1100fb.c index 56d514b5d252..15ae50063296 100644 --- a/drivers/video/fbdev/sa1100fb.c +++ b/drivers/video/fbdev/sa1100fb.c @@ -323,13 +323,11 @@ sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, * according to the RGB bitfield information. */ if (regno < 16) { - u32 *pal = fbi->fb.pseudo_palette; - val = chan_to_field(red, &fbi->fb.var.red); val |= chan_to_field(green, &fbi->fb.var.green); val |= chan_to_field(blue, &fbi->fb.var.blue); - pal[regno] = val; + fbi->pseudo_palette[regno] = val; ret = 0; } break; @@ -1132,8 +1130,7 @@ static struct sa1100fb_info *sa1100fb_init_fbinfo(struct device *dev) struct sa1100fb_info *fbi; unsigned i; - fbi = devm_kzalloc(dev, sizeof(struct sa1100fb_info) + sizeof(u32) * 16, - GFP_KERNEL); + fbi = devm_kzalloc(dev, sizeof(struct sa1100fb_info), GFP_KERNEL); if (!fbi) return NULL; @@ -1158,7 +1155,7 @@ static struct sa1100fb_info *sa1100fb_init_fbinfo(struct device *dev) fbi->fb.fbops = &sa1100fb_ops; fbi->fb.flags = FBINFO_DEFAULT; fbi->fb.monspecs = monspecs; - fbi->fb.pseudo_palette = (fbi + 1); + fbi->fb.pseudo_palette = fbi->pseudo_palette; fbi->rgb[RGB_4] = &rgb_4; fbi->rgb[RGB_8] = &rgb_8; diff --git a/drivers/video/fbdev/sa1100fb.h b/drivers/video/fbdev/sa1100fb.h index 0139d13377a5..7a1a9ca33cec 100644 --- a/drivers/video/fbdev/sa1100fb.h +++ b/drivers/video/fbdev/sa1100fb.h @@ -69,6 +69,8 @@ struct sa1100fb_info { const struct sa1100fb_mach_info *inf; struct clk *clk; + + u32 pseudo_palette[16]; }; #define TO_INF(ptr,member) container_of(ptr,struct sa1100fb_info,member) From 2e307cba0c56eba45649eb0f0f43b999e64aae94 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:28 +0100 Subject: [PATCH 15/42] video: fbdev: au1200fb: Fix a potential double free If 'fb_alloc_cmap()' fails, 'fbi->pseudo_palette' is freed and an error code is returned by 'au1200fb_init_fbinfo()'. The only caller, 'au1200fb_drv_probe()' goes to an error handling path where resources allocated in 'fb_alloc_cmap()' are freed. This leads to a double free of 'fbi->pseudo_palette'. Fix it by letting the caller free all resources in case of failure in 'au1200fb_init_fbinfo()'. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 5f04b4096c42..a5facc2ad90b 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1553,7 +1553,6 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev) if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { print_err("Fail to allocate colormap (%d entries)", AU1200_LCD_NBR_PALETTE_ENTRIES); - kfree(fbi->pseudo_palette); return -EFAULT; } From 8cae353e6b01ac3f18097f631cdbceb5ff28c7f3 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:28 +0100 Subject: [PATCH 16/42] video: fbdev: au1200fb: Return an error code if a memory allocation fails 'ret' is known to be 0 at this point. In case of memory allocation error in 'framebuffer_alloc()', return -ENOMEM instead. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index a5facc2ad90b..7fa41026984d 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1680,8 +1680,10 @@ static int au1200fb_drv_probe(struct platform_device *dev) fbi = framebuffer_alloc(sizeof(struct au1200fb_device), &dev->dev); - if (!fbi) + if (!fbi) { + ret = -ENOMEM; goto failed; + } _au1200fb_infos[plane] = fbi; fbdev = fbi->par; From 451f130602619a17c8883dd0b71b11624faffd51 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:28 +0100 Subject: [PATCH 17/42] video: fbdev: au1200fb: Release some resources if a memory allocation fails We should go through the error handling code instead of returning -ENOMEM directly. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 7fa41026984d..cf54168d44dc 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1702,7 +1702,8 @@ static int au1200fb_drv_probe(struct platform_device *dev) if (!fbdev->fb_mem) { print_err("fail to allocate frambuffer (size: %dK))", fbdev->fb_len / 1024); - return -ENOMEM; + ret = -ENOMEM; + goto failed; } /* From 703a4af427a9bf3028f1a9369fcec7bfcf56f0ed Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:29 +0100 Subject: [PATCH 18/42] video: fbdev: au1200fb: Fix incorrect IRQ freeing 'au1200fb_drv_probe()' can not fail after a successful call to 'request_irq()'. So there is no point to call 'free_irq()' in the error handling path. Moreover, the hard coded AU1200_LCD_INT looks boggus since commit 1630d85a8312 ("au1200fb: fix hardcoded IRQ"). So, remove it. Signed-off-by: Christophe JAILLET Cc: Tejun Heo [b.zolnierkie: patch summary and description fixups] Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index cf54168d44dc..0d8ed0ef9183 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1766,8 +1766,6 @@ failed: fb_dealloc_cmap(&fbi->cmap); kfree(fbi->pseudo_palette); } - if (plane == 0) - free_irq(AU1200_LCD_INT, (void*)dev); return ret; } From 6bbbb6805a72bd8c3e9ee626add6b6e8527bb971 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:29 +0100 Subject: [PATCH 19/42] video: fbdev: au1200fb: Fix error handling path Rewrite the exit path based on 'au1200fb_drv_remove()'. We can safely iterate for all already handled planes. Even if not completely initialized, the functions that are called will silently accept the 'fb_info' structure that is passed. As soon as we find a NULL in the '_au1200fb_infos' array, we know that we have released all what we needed to release. So we can 'break'. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 0d8ed0ef9183..e531543bc707 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1760,11 +1760,19 @@ static int au1200fb_drv_probe(struct platform_device *dev) return 0; failed: - /* NOTE: This only does the current plane/window that failed; others are still active */ - if (fbi) { + for (plane = 0; plane < device_count; ++plane) { + fbi = _au1200fb_infos[plane]; + if (!fbi) + break; + + /* Clean up all probe data */ + unregister_framebuffer(fbi); if (fbi->cmap.len != 0) fb_dealloc_cmap(&fbi->cmap); kfree(fbi->pseudo_palette); + + framebuffer_release(fbi); + _au1200fb_infos[plane] = NULL; } return ret; } From 58a81afcffeb457e56e8498c8bf5b73c1623c0b5 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:29 +0100 Subject: [PATCH 20/42] video: fbdev: au1200fb: Remove some dead code There is no need to shut gcc up. It should not complain. Axe 'fbdev', it is never used in this function. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index e531543bc707..970ce761ff89 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1667,10 +1667,6 @@ static int au1200fb_drv_probe(struct platform_device *dev) printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name); printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name); - /* shut gcc up */ - ret = 0; - fbdev = NULL; - for (plane = 0; plane < device_count; ++plane) { bpp = winbpp(win->w[plane].mode_winctrl1); if (win->w[plane].xres == 0) @@ -1780,7 +1776,6 @@ failed: static int au1200fb_drv_remove(struct platform_device *dev) { struct au1200fb_platdata *pd = platform_get_drvdata(dev); - struct au1200fb_device *fbdev; struct fb_info *fbi; int plane; @@ -1789,7 +1784,6 @@ static int au1200fb_drv_remove(struct platform_device *dev) for (plane = 0; plane < device_count; ++plane) { fbi = _au1200fb_infos[plane]; - fbdev = fbi->par; /* Clean up all probe data */ unregister_framebuffer(fbi); From 0620865611c9e398f8feaccbe49be946bc6e04d1 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:29 +0100 Subject: [PATCH 21/42] video: fbdev: au1200fb: Propagate an error code We should propagate the error code returned by 'fb_alloc_cmap()' instead of returning -EFAULT. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 970ce761ff89..687ea2a8f810 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1518,7 +1518,7 @@ static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id) static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev) { struct fb_info *fbi = fbdev->fb_info; - int bpp; + int bpp, ret; fbi->fbops = &au1200fb_fb_ops; @@ -1550,10 +1550,11 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev) return -ENOMEM; } - if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { + ret = fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0); + if (ret < 0) { print_err("Fail to allocate colormap (%d entries)", AU1200_LCD_NBR_PALETTE_ENTRIES); - return -EFAULT; + return ret; } strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id)); From ab798b908737e999e5d9bcebe972e9d5002583cc Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Thu, 9 Nov 2017 18:09:30 +0100 Subject: [PATCH 22/42] video: fbdev: au1200fb: Style clean up Style clean-up. Signed-off-by: Christophe JAILLET Cc: Tejun Heo Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1200fb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 687ea2a8f810..87d5a62bf6ca 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -1546,14 +1546,13 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev) } fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL); - if (!fbi->pseudo_palette) { + if (!fbi->pseudo_palette) return -ENOMEM; - } ret = fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0); if (ret < 0) { print_err("Fail to allocate colormap (%d entries)", - AU1200_LCD_NBR_PALETTE_ENTRIES); + AU1200_LCD_NBR_PALETTE_ENTRIES); return ret; } @@ -1717,7 +1716,8 @@ static int au1200fb_drv_probe(struct platform_device *dev) print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024); /* Init FB data */ - if ((ret = au1200fb_init_fbinfo(fbdev)) < 0) + ret = au1200fb_init_fbinfo(fbdev); + if (ret < 0) goto failed; /* Register new framebuffer */ From 2d81482821e9a825030cf4ba60de990f1a2bdfd0 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 9 Nov 2017 18:09:30 +0100 Subject: [PATCH 23/42] video: fbdev: mxsfb: fix pixelclock polarity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PIXDATA flags of the display_flags enum are controller centric, e.g. NEGEDGE means the controller shall drive the data signals on pixelclocks negative edge. However, the drivers flag is display centric: Sample the data on negative (falling) edge. Therefore, change the if statement to check for the POSEDGE flag (which is typically not set): Drive on positive edge => sample on negative edge Signed-off-by: Stefan Agner Acked-by: Shawn Guo Cc: Jean-Christophe Plagniol-Villard Cc: Sascha Hauer Cc: Liu Ying Cc: Lothar Waßmann Cc: Fabio Estevam Cc: Max Krummenacher Cc: Mauro Salvini Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/mxsfb.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/mxsfb.c b/drivers/video/fbdev/mxsfb.c index 7846f0e8bbbb..79b1dc7f042b 100644 --- a/drivers/video/fbdev/mxsfb.c +++ b/drivers/video/fbdev/mxsfb.c @@ -150,7 +150,7 @@ #define STMLCDIF_24BIT 3 /** pixel data bus to the display is of 24 bit width */ #define MXSFB_SYNC_DATA_ENABLE_HIGH_ACT (1 << 6) -#define MXSFB_SYNC_DOTCLK_FALLING_ACT (1 << 7) /* negtive edge sampling */ +#define MXSFB_SYNC_DOTCLK_FALLING_ACT (1 << 7) /* negative edge sampling */ enum mxsfb_devtype { MXSFB_V3, @@ -788,7 +788,16 @@ static int mxsfb_init_fbinfo_dt(struct mxsfb_info *host, if (vm.flags & DISPLAY_FLAGS_DE_HIGH) host->sync |= MXSFB_SYNC_DATA_ENABLE_HIGH_ACT; - if (vm.flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE) + + /* + * The PIXDATA flags of the display_flags enum are controller + * centric, e.g. NEGEDGE means drive data on negative edge. + * However, the drivers flag is display centric: Sample the + * data on negative (falling) edge. Therefore, check for the + * POSEDGE flag: + * drive on positive edge => sample on negative edge + */ + if (vm.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE) host->sync |= MXSFB_SYNC_DOTCLK_FALLING_ACT; put_display_node: From 1e7d4beba2f5c8d22c46e15d3b89559934356501 Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Thu, 9 Nov 2017 18:09:30 +0100 Subject: [PATCH 24/42] video: fbdev: remove dead igafb driver igafb driver hasn't compiled since at least kernel v2.6.34 as commit 6016a363f6b5 ("of: unify phandle name in struct device_node") missed updating igafb.c to use dp->phandle instead of dp->node. Cc: "David S. Miller" Cc: Bhumika Goyal Signed-off-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/Kconfig | 10 - drivers/video/fbdev/Makefile | 1 - drivers/video/fbdev/igafb.c | 579 ----------------------------------- include/video/iga.h | 24 -- 4 files changed, 614 deletions(-) delete mode 100644 drivers/video/fbdev/igafb.c delete mode 100644 include/video/iga.h diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig index 5e58f5ec0a28..2f615b7f1c9f 100644 --- a/drivers/video/fbdev/Kconfig +++ b/drivers/video/fbdev/Kconfig @@ -905,16 +905,6 @@ config FB_LEO This is the frame buffer device driver for the SBUS-based Sun ZX (leo) frame buffer cards. -config FB_IGA - bool "IGA 168x display support" - depends on (FB = y) && SPARC32 - select FB_CFB_FILLRECT - select FB_CFB_COPYAREA - select FB_CFB_IMAGEBLIT - help - This is the framebuffer device for the INTERGRAPHICS 1680 and - successor frame buffer cards. - config FB_XVR500 bool "Sun XVR-500 3DLABS Wildcat support" depends on (FB = y) && PCI && SPARC64 diff --git a/drivers/video/fbdev/Makefile b/drivers/video/fbdev/Makefile index ee8c81405a7f..deb76674e5e9 100644 --- a/drivers/video/fbdev/Makefile +++ b/drivers/video/fbdev/Makefile @@ -64,7 +64,6 @@ obj-$(CONFIG_FB_HGA) += hgafb.o obj-$(CONFIG_FB_XVR500) += sunxvr500.o obj-$(CONFIG_FB_XVR2500) += sunxvr2500.o obj-$(CONFIG_FB_XVR1000) += sunxvr1000.o -obj-$(CONFIG_FB_IGA) += igafb.o obj-$(CONFIG_FB_APOLLO) += dnfb.o obj-$(CONFIG_FB_Q40) += q40fb.o obj-$(CONFIG_FB_TGA) += tgafb.o diff --git a/drivers/video/fbdev/igafb.c b/drivers/video/fbdev/igafb.c deleted file mode 100644 index 486f18897414..000000000000 --- a/drivers/video/fbdev/igafb.c +++ /dev/null @@ -1,579 +0,0 @@ -/* - * linux/drivers/video/igafb.c -- Frame buffer device for IGA 1682 - * - * Copyright (C) 1998 Vladimir Roganov and Gleb Raiko - * - * This driver is partly based on the Frame buffer device for ATI Mach64 - * and partially on VESA-related code. - * - * Copyright (C) 1997-1998 Geert Uytterhoeven - * Copyright (C) 1998 Bernd Harries - * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) - * - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file COPYING in the main directory of this archive for - * more details. - */ - -/****************************************************************************** - - TODO: - Despite of IGA Card has advanced graphic acceleration, - initial version is almost dummy and does not support it. - Support for video modes and acceleration must be added - together with accelerated X-Windows driver implementation. - - Most important thing at this moment is that we have working - JavaEngine1 console & X with new console interface. - -******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifdef CONFIG_SPARC -#include -#include -#endif - -#include