From: Zsolt Kajtar soci@c64.rulez.org
[ Upstream commit aad1d99beaaf132e2024a52727c24894cdf9474a ]
It could be triggered on 32 bit big endian machines at 32 bpp in the pattern realignment. In this case just return early as the result is an identity.
Signed-off-by: Zsolt Kajtar soci@c64.rulez.org Signed-off-by: Helge Deller deller@gmx.de Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES - Returning early in the default branch (`drivers/video/fbdev/core/fb_fillrect.h:94`) keeps `pixel_to_pat()` from reaching the big-endian realignment block at `drivers/video/fbdev/core/fb_fillrect.h:97-99`, eliminating the undefined `pattern >> bpp` shift that UBSAN reports when `bpp == BITS_PER_LONG` (e.g., 32 bpp on 32-bit BE). The skipped logic was an identity operation in that case, so correctness is preserved. - The old undefined shift was triggered during ordinary rectangle fills (`drivers/video/fbdev/core/fb_fillrect.h:266`) on big-endian framebuffers, causing sanitizer aborts and risking miscompilation even without UBSAN, so this is a real bug fix with direct user impact. - The change is tightly scoped, has no dependencies, and leaves little- endian paths and sub-word `bpp` handling untouched, keeping regression risk very low while restoring defined behavior.
Next steps: 1. If feasible, rebuild a BE configuration with UBSAN to confirm the warning is gone.
drivers/video/fbdev/core/fb_fillrect.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/video/fbdev/core/fb_fillrect.h b/drivers/video/fbdev/core/fb_fillrect.h index 66042e534de77..f366670a53af8 100644 --- a/drivers/video/fbdev/core/fb_fillrect.h +++ b/drivers/video/fbdev/core/fb_fillrect.h @@ -92,8 +92,7 @@ static unsigned long pixel_to_pat(int bpp, u32 color) pattern = pattern | pattern << bpp; break; default: - pattern = color; - break; + return color; } #ifndef __LITTLE_ENDIAN pattern <<= (BITS_PER_LONG % bpp);