From 298a9eb536dc3469b1f2558e9cc3aac6ef6823cb Mon Sep 17 00:00:00 2001 From: buxiasen Date: Sun, 16 Feb 2025 00:19:45 +0800 Subject: [PATCH] fb: fix no mmap with get_pinfo, kernel build with data abort When BUILD_KERNEL, will case userspace access the kernel address and abort. Signed-off-by: buxiasen --- examples/fb/fb_main.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/fb/fb_main.c b/examples/fb/fb_main.c index 0eccf4b74e2..bd7d457e1c7 100644 --- a/examples/fb/fb_main.c +++ b/examples/fb/fb_main.c @@ -198,6 +198,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state) int ret; uintptr_t buf_offset; struct fb_planeinfo_s pinfo; + FAR void *fbmem; memset(&pinfo, 0, sizeof(pinfo)); pinfo.display = state->pinfo.display + 1; @@ -207,6 +208,17 @@ static int fb_init_mem2(FAR struct fb_state_s *state) return EXIT_FAILURE; } + fbmem = mmap(NULL, pinfo.fblen, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_FILE, state->fd, 0); + + if (fbmem == MAP_FAILED) + { + int errcode = errno; + fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n", + errcode); + return EXIT_FAILURE; + } + /* Check bpp */ if (pinfo.bpp != state->pinfo.bpp) @@ -219,7 +231,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state) * It needs to be divisible by pinfo.stride */ - buf_offset = pinfo.fbmem - state->fbmem; + buf_offset = fbmem - state->fbmem; if ((buf_offset % state->pinfo.stride) != 0) { @@ -236,7 +248,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state) /* Use consecutive fbmem2. */ state->mem2_yoffset = state->vinfo.yres; - state->fbmem2 = pinfo.fbmem + state->mem2_yoffset * pinfo.stride; + state->fbmem2 = fbmem + state->mem2_yoffset * pinfo.stride; printf("Use consecutive fbmem2 = %p, yoffset = %" PRIu32"\n", state->fbmem2, state->mem2_yoffset); } @@ -245,7 +257,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state) /* Use non-consecutive fbmem2. */ state->mem2_yoffset = buf_offset / state->pinfo.stride; - state->fbmem2 = pinfo.fbmem; + state->fbmem2 = fbmem; printf("Use non-consecutive fbmem2 = %p, yoffset = %" PRIu32"\n", state->fbmem2, state->mem2_yoffset); }