If use -P option without -s option, we meet Segmentation fault error when modetest is terminated. Check whether dev.mode.bo is NULL.
Signed-off-by: Joonyoung Shim jy0922.shim@samsung.com --- tests/modetest/modetest.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 5f46efd..b59f6b5 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -1113,6 +1113,12 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co dev->mode.fb_id = fb_id; }
+static void clear_mode(struct device *dev) +{ + if (dev->mode.bo) + bo_destroy(dev->mode.bo); +} + static void set_planes(struct device *dev, struct plane_arg *p, unsigned int count) { unsigned int i; @@ -1636,7 +1642,8 @@ int main(int argc, char **argv) if (test_cursor) clear_cursors(&dev);
- bo_destroy(dev.mode.bo); + if (count) + clear_mode(&dev); }
free_resources(dev.resources);
It's proper to remove added framebuffer before destroy buffer.
Signed-off-by: Joonyoung Shim jy0922.shim@samsung.com --- tests/modetest/modetest.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index b59f6b5..6377459 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -1055,6 +1055,7 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co
dev->mode.width = 0; dev->mode.height = 0; + dev->mode.fb_id = -1;
for (i = 0; i < count; i++) { struct pipe_arg *pipe = &pipes[i]; @@ -1115,6 +1116,8 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co
static void clear_mode(struct device *dev) { + if (dev->mode.fb_id != -1) + drmModeRmFB(dev->fd, dev->mode.fb_id); if (dev->mode.bo) bo_destroy(dev->mode.bo); } @@ -1255,6 +1258,7 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned drmHandleEvent(dev->fd, &evctx); }
+ drmModeRmFB(dev->fd, other_fb_id); bo_destroy(other_bo); }
This patch needs to destroy and to remove buffer and framebuffer properly from error path of set_mode and test_page_flip.
Signed-off-by: Joonyoung Shim jy0922.shim@samsung.com --- tests/modetest/modetest.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 6377459..eec4fd8 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -1074,6 +1074,8 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co if (bo == NULL) return;
+ dev->mode.bo = bo; + ret = drmModeAddFB2(dev->fd, dev->mode.width, dev->mode.height, pipes[0].fourcc, handles, pitches, offsets, &fb_id, 0); if (ret) { @@ -1082,6 +1084,8 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co return; }
+ dev->mode.fb_id = fb_id; + x = 0; for (i = 0; i < count; i++) { struct pipe_arg *pipe = &pipes[i]; @@ -1109,9 +1113,6 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co return; } } - - dev->mode.bo = bo; - dev->mode.fb_id = fb_id; }
static void clear_mode(struct device *dev) @@ -1192,7 +1193,7 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned &other_fb_id, 0); if (ret) { fprintf(stderr, "failed to add fb: %s\n", strerror(errno)); - return; + goto err; }
for (i = 0; i < count; i++) { @@ -1206,7 +1207,7 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned pipe); if (ret) { fprintf(stderr, "failed to page flip: %s\n", strerror(errno)); - return; + goto err_rmfb; } gettimeofday(&pipe->start, NULL); pipe->swap_count = 0; @@ -1258,7 +1259,9 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned drmHandleEvent(dev->fd, &evctx); }
+err_rmfb: drmModeRmFB(dev->fd, other_fb_id); +err: bo_destroy(other_bo); }
Currently, we are missing to destroy buffer and to remove framebuffer of planes when terminates modetest.
Signed-off-by: Joonyoung Shim jy0922.shim@samsung.com --- tests/modetest/modetest.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index eec4fd8..56d49b0 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -730,6 +730,7 @@ struct plane_arg { uint32_t w, h; double scale; unsigned int fb_id; + struct bo *bo; char format_str[5]; /* need to leave room for terminating \0 */ unsigned int fourcc; }; @@ -1012,6 +1013,8 @@ static int set_plane(struct device *dev, struct plane_arg *p) if (plane_bo == NULL) return -1;
+ p->bo = plane_bo; + /* just use single plane format for now.. */ if (drmModeAddFB2(dev->fd, p->w, p->h, p->fourcc, handles, pitches, offsets, &p->fb_id, plane_flags)) { @@ -1133,6 +1136,18 @@ static void set_planes(struct device *dev, struct plane_arg *p, unsigned int cou return; }
+static void clear_planes(struct device *dev, struct plane_arg *p, unsigned int count) +{ + unsigned int i; + + for (i = 0; i < count; i++) { + if (p[i].fb_id != -1) + drmModeRmFB(dev->fd, p[i].fb_id); + if (p[i].bo) + bo_destroy(p[i].bo); + } +} + static void set_cursors(struct device *dev, struct pipe_arg *pipes, unsigned int count) { uint32_t handles[4], pitches[4], offsets[4] = {0}; /* we only use [0] */ @@ -1517,6 +1532,7 @@ int main(int argc, char **argv) if (parse_plane(&plane_args[plane_count], optarg) < 0) usage(argv[0]);
+ plane_args[plane_count].fb_id = -1; plane_count++; break; case 'p': @@ -1649,6 +1665,9 @@ int main(int argc, char **argv) if (test_cursor) clear_cursors(&dev);
+ if (plane_count) + clear_planes(&dev, plane_args, plane_count); + if (count) clear_mode(&dev); }
Currently, we are missing to destroy buffer of cursor when terminates modetest.
Signed-off-by: Joonyoung Shim jy0922.shim@samsung.com --- tests/modetest/modetest.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 56d49b0..758d86c 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -110,6 +110,7 @@ struct device {
unsigned int fb_id; struct bo *bo; + struct bo *cursor_bo; } mode; };
@@ -1167,6 +1168,8 @@ static void set_cursors(struct device *dev, struct pipe_arg *pipes, unsigned int if (bo == NULL) return;
+ dev->mode.cursor_bo = bo; + for (i = 0; i < count; i++) { struct pipe_arg *pipe = &pipes[i]; ret = cursor_init(dev->fd, handles[0], @@ -1186,6 +1189,9 @@ static void set_cursors(struct device *dev, struct pipe_arg *pipes, unsigned int static void clear_cursors(struct device *dev) { cursor_stop(); + + if (dev->mode.cursor_bo) + bo_destroy(dev->mode.cursor_bo); }
static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned int count)
dri-devel@lists.freedesktop.org