This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new df9fe43cc fb: fix no mmap with get_pinfo, kernel build with data abort
df9fe43cc is described below

commit df9fe43cc9586946ff24d883d273488b7264a67e
Author: buxiasen <[email protected]>
AuthorDate: Sun Feb 16 00:19:45 2025 +0800

    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 <[email protected]>
---
 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 0eccf4b74..bd7d457e1 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);
     }

Reply via email to