Skip to content

Commit b648d8e

Browse files
committed
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 <buxiasen@xiaomi.com>
1 parent a3ee39d commit b648d8e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

examples/fb/fb_main.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state)
198198
int ret;
199199
uintptr_t buf_offset;
200200
struct fb_planeinfo_s pinfo;
201+
FAR void *fbmem;
201202

202203
memset(&pinfo, 0, sizeof(pinfo));
203204
pinfo.display = state->pinfo.display + 1;
@@ -207,6 +208,17 @@ static int fb_init_mem2(FAR struct fb_state_s *state)
207208
return EXIT_FAILURE;
208209
}
209210

211+
fbmem = mmap(NULL, pinfo.fblen, PROT_READ | PROT_WRITE,
212+
MAP_SHARED | MAP_FILE, state->fd, 0);
213+
214+
if (fbmem == MAP_FAILED)
215+
{
216+
int errcode = errno;
217+
fprintf(stderr, "ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n",
218+
errcode);
219+
return EXIT_FAILURE;
220+
}
221+
210222
/* Check bpp */
211223

212224
if (pinfo.bpp != state->pinfo.bpp)
@@ -219,7 +231,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state)
219231
* It needs to be divisible by pinfo.stride
220232
*/
221233

222-
buf_offset = pinfo.fbmem - state->fbmem;
234+
buf_offset = fbmem - state->fbmem;
223235

224236
if ((buf_offset % state->pinfo.stride) != 0)
225237
{
@@ -236,7 +248,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state)
236248
/* Use consecutive fbmem2. */
237249

238250
state->mem2_yoffset = state->vinfo.yres;
239-
state->fbmem2 = pinfo.fbmem + state->mem2_yoffset * pinfo.stride;
251+
state->fbmem2 = fbmem + state->mem2_yoffset * pinfo.stride;
240252
printf("Use consecutive fbmem2 = %p, yoffset = %" PRIu32"\n",
241253
state->fbmem2, state->mem2_yoffset);
242254
}
@@ -245,7 +257,7 @@ static int fb_init_mem2(FAR struct fb_state_s *state)
245257
/* Use non-consecutive fbmem2. */
246258

247259
state->mem2_yoffset = buf_offset / state->pinfo.stride;
248-
state->fbmem2 = pinfo.fbmem;
260+
state->fbmem2 = fbmem;
249261
printf("Use non-consecutive fbmem2 = %p, yoffset = %" PRIu32"\n",
250262
state->fbmem2, state->mem2_yoffset);
251263
}

0 commit comments

Comments
 (0)