-
Notifications
You must be signed in to change notification settings - Fork 8.3k
samples: subsys: input: draw_touch_events: fix overflow in clear_screen loop #98719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples: subsys: input: draw_touch_events: fix overflow in clear_screen loop #98719
Conversation
02ce530 to
916696c
Compare
|
@CharlesDias - can you link a bug report to this issue? It's required for all bug fixes post RC2. |
916696c to
f109857
Compare
|
Hi, @fabiobaltieri, @faxe1008, and @cfriedt. I've changed this fix to DRAFT because, although this modification seems to have resolved the problem, I suspect the root cause may be something else. I am currently investigating further. I apologize for the inconvenience! |
8a8fc8b
f109857 to
8a8fc8b
Compare
8a8fc8b to
763ff2b
Compare
|
After further investigation, I found that the BUS FAULT was caused by the clear_screen loop writing past the framebuffer. When CROSS_DIM does not evenly divide the panel WIDTH/HEIGHT, the last tile on the right/bottom extends beyond the framebuffer row/column. Backtrace Solution:
This guarantees we never copy past the framebuffer boundaries for tiles at the right/bottom edges. Additional fix (pixel format) Solution (pixel format) |
|
This solution was validated in:
|
When CROSS_DIM doesn’t evenly divide the panel WIDTH/HEIGHT, the last tile on the right/bottom edge can extend past the display bounds. Fix by clipping the edge tiles. Signed-off-by: Charles Dias <charlesdias.cd@outlook.com>
Set zephyr_lcd_controller pixel-format to PANEL_PIXEL_FORMAT_ARGB_8888 to match the driver configuration. Signed-off-by: Charles Dias <charlesdias.cd@outlook.com>
763ff2b to
1a18019
Compare
|
|
I discovered now this PR and had a look at it. I know it is now merged but am wondering if the fix is actually done at the right place here. Having the application not trying to do invalid stuff is indeed correct, but that doesn't seem suffisant I think and the driver (LTDC) should have been blocking such memcpy as well in the first place. Looking at the diff, it seems that display_write return value isn't check in this sample so, shouldn't fixes be more like:
This draw_touch_events is just a sample, I think the 3rd point is very important here. |
|
I'm going to open a new PR in order to add display API return value check as well as protect the LTDC driver memcpy. |
Hi @avolmat-st. Thanks for your inputs! If needed, I can test your new PR on my STM32U5G9J-DK1 board. Please let me know. Thank you! |
Thanks @CharlesDias, I've just raised the PR #99166 which tackles this point. Could you recheck your side with your setup, and also for the test purpose only revert your fix commit in the sample in order to ensure that the LTDC driver is properly protecting this case ? |
Hi @avolmat-st , below is the message log regarding your suggested test. Since we got an error, the application was finished. |
So this is happening if the sample is not fixed right (aka your patch is reverted) ? If so, then this is good I think and shows that the LTDC is able to catch incorrect write call. That is the purpose of my patch. Thanks for the check. |
Exactly! When I revert my patch, the LTDC gets the issue. |



Problem: On STM32U5G9J-DK1 + st_lcd_dsi_mb1835, the sample could BUS FAULT with SCREEN_WIDTH_TO_CROSS_DIM=25 and show only a horizontal line with 20.
Root cause: The tile buffer BPP is derived from the devicetree pixel format (e.g., RGB888 = 3 BPP), but the driver may be using a different current pixel format.Fix: Explicitly set the driver pixel format to the DT-selected format at init.EDIT:
The
clear_screenloop used fixed-size tiles (CROSS_DIM). When WIDTH/HEIGHT aren’t multiples of CROSS_DIM, the right/bottom tiles exceeded the panel bounds, causing the driver’s row copy (memcpy) to write past the framebuffer and fault.Fix: clip only the edge tiles
Prevents out-of-bounds writes on edge tiles.
Related with:
document_4915927358348723745.mp4
Fixes #98922