]>
Commit | Line | Data |
---|---|---|
75196731 JP |
1 | From 88c6429e4babcb00eb4d324089e4a6916d0a62aa Mon Sep 17 00:00:00 2001 |
2 | From: Robert Beckett <bob.beckett@collabora.com> | |
3 | Date: Wed, 26 Apr 2023 13:28:40 +0100 | |
4 | Subject: [PATCH] panfrost: fix scanout buffer alloc | |
5 | ||
6 | Use ro->bo_map to alloc scanout. | |
7 | This fixes leaking the scanout. | |
8 | ||
9 | Fixes: ad4d7ca83324 ("kmsro: Fix renderonly_scanout BO aliasing") | |
10 | Signed-off-by: Robert Beckett <bob.beckett@collabora.com> | |
11 | Cc: mesa-stable | |
12 | --- | |
13 | .../winsys/panfrost/drm/panfrost_drm_winsys.c | 25 +++++++++++-------- | |
14 | 1 file changed, 14 insertions(+), 11 deletions(-) | |
15 | ||
16 | diff --git a/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c b/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c | |
17 | index b5ec50d49ef0e..2710217a5b44e 100644 | |
18 | --- a/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c | |
19 | +++ b/src/gallium/winsys/panfrost/drm/panfrost_drm_winsys.c | |
20 | @@ -63,26 +63,32 @@ panfrost_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc, | |
21 | }; | |
22 | struct drm_mode_destroy_dumb destroy_dumb = {0}; | |
23 | ||
24 | - /* Align width to end up with a buffer that's aligned on 64 bytes. */ | |
25 | - | |
26 | - struct renderonly_scanout *scanout = CALLOC_STRUCT(renderonly_scanout); | |
27 | - if (!scanout) | |
28 | - return NULL; | |
29 | - | |
30 | /* create dumb buffer at scanout GPU */ | |
31 | int err = drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb); | |
32 | if (err < 0) { | |
33 | fprintf(stderr, "DRM_IOCTL_MODE_CREATE_DUMB failed: %s\n", | |
34 | strerror(errno)); | |
35 | - goto free_scanout; | |
36 | + return NULL; | |
37 | } | |
38 | ||
39 | if (create_dumb.pitch % 64) | |
40 | goto free_dumb; | |
41 | ||
42 | + struct renderonly_scanout *scanout; | |
43 | + | |
44 | + simple_mtx_lock(&ro->bo_map_lock); | |
45 | + scanout = util_sparse_array_get(&ro->bo_map, create_dumb.handle); | |
46 | + simple_mtx_unlock(&ro->bo_map_lock); | |
47 | + | |
48 | + if (!scanout) | |
49 | + goto free_dumb; | |
50 | + | |
51 | scanout->handle = create_dumb.handle; | |
52 | scanout->stride = create_dumb.pitch; | |
53 | ||
54 | + assert(p_atomic_read(&scanout->refcnt) == 0); | |
55 | + p_atomic_set(&scanout->refcnt, 1); | |
56 | + | |
57 | if (!out_handle) | |
58 | return scanout; | |
59 | ||
60 | @@ -101,12 +107,9 @@ panfrost_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc, | |
61 | return scanout; | |
62 | ||
63 | free_dumb: | |
64 | - destroy_dumb.handle = scanout->handle; | |
65 | + destroy_dumb.handle = create_dumb.handle; | |
66 | drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb); | |
67 | ||
68 | -free_scanout: | |
69 | - FREE(scanout); | |
70 | - | |
71 | return NULL; | |
72 | } | |
73 | ||
74 | -- | |
75 | GitLab | |
76 |