Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

framebuffer: fix screen corruption when copying

The function bitcpy_rev has a bug that may result in screen corruption.
The bug happens under these conditions:
* the end of the destination area of a copy operation is aligned on a long
word boundary
* the end of the source area is not aligned on a long word boundary
* we are copying more than one long word

In this case, the variable shift is non-zero and the variable first is
zero. The statements FB_WRITEL(comp(d0, FB_READL(dst), first), dst) reads
the last long word of the destination and writes it back unchanged
(because first is zero). Correctly, we should write the variable d0 to the
last word of the destination in this case.

This patch fixes the bug by introducing and extra test if first is zero.

The patch also removes the references to fb_memmove in the code that is
commented out because fb_memmove was removed from framebuffer subsystem.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>

authored by

Mikulas Patocka and committed by
Tomi Valkeinen
5b789da8 f74a289b

+8 -5
+8 -5
drivers/video/fbdev/core/cfbcopyarea.c
··· 55 55 * If you suspect bug in this function, compare it with this simple 56 56 * memmove implementation. 57 57 */ 58 - fb_memmove((char *)dst + ((dst_idx & (bits - 1))) / 8, 59 - (char *)src + ((src_idx & (bits - 1))) / 8, n / 8); 58 + memmove((char *)dst + ((dst_idx & (bits - 1))) / 8, 59 + (char *)src + ((src_idx & (bits - 1))) / 8, n / 8); 60 60 return; 61 61 #endif 62 62 ··· 221 221 * If you suspect bug in this function, compare it with this simple 222 222 * memmove implementation. 223 223 */ 224 - fb_memmove((char *)dst + ((dst_idx & (bits - 1))) / 8, 225 - (char *)src + ((src_idx & (bits - 1))) / 8, n / 8); 224 + memmove((char *)dst + ((dst_idx & (bits - 1))) / 8, 225 + (char *)src + ((src_idx & (bits - 1))) / 8, n / 8); 226 226 return; 227 227 #endif 228 228 ··· 324 324 d0 = d0 << left | d1 >> right; 325 325 } 326 326 d0 = fb_rev_pixels_in_long(d0, bswapmask); 327 - FB_WRITEL(comp(d0, FB_READL(dst), first), dst); 327 + if (!first) 328 + FB_WRITEL(d0, dst); 329 + else 330 + FB_WRITEL(comp(d0, FB_READL(dst), first), dst); 328 331 d0 = d1; 329 332 dst--; 330 333 n -= dst_idx+1;