* [PATCH 0/2] drm/virtio: use drm managed resources
@ 2022-07-14 13:00 Danilo Krummrich
2022-07-14 13:00 ` [PATCH 1/2] drm/virtio: plane: " Danilo Krummrich
2022-07-14 13:00 ` [PATCH 2/2] drm/virtio: kms: " Danilo Krummrich
0 siblings, 2 replies; 4+ messages in thread
From: Danilo Krummrich @ 2022-07-14 13:00 UTC (permalink / raw)
To: airlied, daniel, kraxel; +Cc: dri-devel, linux-kernel, Danilo Krummrich
This patch series converts plain memory allocations for driver structures and
planes to drm managed allocations in order to cleanup/simply the corresponding
release/destroy callbacks.
Danilo Krummrich (2):
drm/virtio: plane: use drm managed resources
drm/virtio: kms: use drm managed resources
drivers/gpu/drm/virtio/virtgpu_kms.c | 16 ++++++--------
drivers/gpu/drm/virtio/virtgpu_plane.c | 30 +++++++-------------------
2 files changed, 15 insertions(+), 31 deletions(-)
--
2.36.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] drm/virtio: plane: use drm managed resources
2022-07-14 13:00 [PATCH 0/2] drm/virtio: use drm managed resources Danilo Krummrich
@ 2022-07-14 13:00 ` Danilo Krummrich
2022-07-14 13:00 ` [PATCH 2/2] drm/virtio: kms: " Danilo Krummrich
1 sibling, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2022-07-14 13:00 UTC (permalink / raw)
To: airlied, daniel, kraxel; +Cc: dri-devel, linux-kernel, Danilo Krummrich
Use drm managed resource allocation (drmm_universal_plane_alloc()) in
order to cleanup/simplify drm plane .destroy callback.
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
---
drivers/gpu/drm/virtio/virtgpu_plane.c | 30 +++++++-------------------
1 file changed, 8 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index 6d3cc9e238a4..3008551d6a05 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -67,16 +67,10 @@ uint32_t virtio_gpu_translate_format(uint32_t drm_fourcc)
return format;
}
-static void virtio_gpu_plane_destroy(struct drm_plane *plane)
-{
- drm_plane_cleanup(plane);
- kfree(plane);
-}
-
static const struct drm_plane_funcs virtio_gpu_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane,
- .destroy = virtio_gpu_plane_destroy,
+ .destroy = drm_plane_cleanup,
.reset = drm_atomic_helper_plane_reset,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
@@ -379,11 +373,7 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
const struct drm_plane_helper_funcs *funcs;
struct drm_plane *plane;
const uint32_t *formats;
- int ret, nformats;
-
- plane = kzalloc(sizeof(*plane), GFP_KERNEL);
- if (!plane)
- return ERR_PTR(-ENOMEM);
+ int nformats;
if (type == DRM_PLANE_TYPE_CURSOR) {
formats = virtio_gpu_cursor_formats;
@@ -394,17 +384,13 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
nformats = ARRAY_SIZE(virtio_gpu_formats);
funcs = &virtio_gpu_primary_helper_funcs;
}
- ret = drm_universal_plane_init(dev, plane, 1 << index,
- &virtio_gpu_plane_funcs,
- formats, nformats,
- NULL, type, NULL);
- if (ret)
- goto err_plane_init;
+
+ plane = drmm_universal_plane_alloc(dev, struct drm_plane, dev,
+ 1 << index, &virtio_gpu_plane_funcs,
+ formats, nformats, NULL, type, NULL);
+ if (IS_ERR(plane))
+ return plane;
drm_plane_helper_add(plane, funcs);
return plane;
-
-err_plane_init:
- kfree(plane);
- return ERR_PTR(ret);
}
--
2.36.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] drm/virtio: kms: use drm managed resources
2022-07-14 13:00 [PATCH 0/2] drm/virtio: use drm managed resources Danilo Krummrich
2022-07-14 13:00 ` [PATCH 1/2] drm/virtio: plane: " Danilo Krummrich
@ 2022-07-14 13:00 ` Danilo Krummrich
2022-08-11 16:16 ` Daniel Vetter
1 sibling, 1 reply; 4+ messages in thread
From: Danilo Krummrich @ 2022-07-14 13:00 UTC (permalink / raw)
To: airlied, daniel, kraxel; +Cc: dri-devel, linux-kernel, Danilo Krummrich
Allocate driver structures with drm managed resource allocators in order
to cleanup/simplify the drm driver .release callback.
Signed-off-by: Danilo Krummrich <dakr@redhat.com>
---
drivers/gpu/drm/virtio/virtgpu_kms.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
index 3313b92db531..63ebe63ef409 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -28,6 +28,7 @@
#include <linux/virtio_ring.h>
#include <drm/drm_file.h>
+#include <drm/drm_managed.h>
#include "virtgpu_drv.h"
@@ -66,10 +67,11 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
{
int i, ret;
bool invalid_capset_id = false;
+ struct drm_device *drm = vgdev->ddev;
- vgdev->capsets = kcalloc(num_capsets,
- sizeof(struct virtio_gpu_drv_capset),
- GFP_KERNEL);
+ vgdev->capsets = drmm_kcalloc(drm, num_capsets,
+ sizeof(struct virtio_gpu_drv_capset),
+ GFP_KERNEL);
if (!vgdev->capsets) {
DRM_ERROR("failed to allocate cap sets\n");
return;
@@ -94,7 +96,7 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
if (ret == 0 || invalid_capset_id) {
spin_lock(&vgdev->display_info_lock);
- kfree(vgdev->capsets);
+ drmm_kfree(drm, vgdev->capsets);
vgdev->capsets = NULL;
spin_unlock(&vgdev->display_info_lock);
return;
@@ -126,7 +128,7 @@ int virtio_gpu_init(struct drm_device *dev)
if (!virtio_has_feature(dev_to_virtio(dev->dev), VIRTIO_F_VERSION_1))
return -ENODEV;
- vgdev = kzalloc(sizeof(struct virtio_gpu_device), GFP_KERNEL);
+ vgdev = drmm_kzalloc(dev, sizeof(struct virtio_gpu_device), GFP_KERNEL);
if (!vgdev)
return -ENOMEM;
@@ -257,7 +259,6 @@ int virtio_gpu_init(struct drm_device *dev)
vgdev->vdev->config->del_vqs(vgdev->vdev);
err_vqs:
dev->dev_private = NULL;
- kfree(vgdev);
return ret;
}
@@ -296,9 +297,6 @@ void virtio_gpu_release(struct drm_device *dev)
if (vgdev->has_host_visible)
drm_mm_takedown(&vgdev->host_visible_mm);
-
- kfree(vgdev->capsets);
- kfree(vgdev);
}
int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
--
2.36.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] drm/virtio: kms: use drm managed resources
2022-07-14 13:00 ` [PATCH 2/2] drm/virtio: kms: " Danilo Krummrich
@ 2022-08-11 16:16 ` Daniel Vetter
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2022-08-11 16:16 UTC (permalink / raw)
To: Danilo Krummrich; +Cc: airlied, daniel, kraxel, dri-devel, linux-kernel
On Thu, Jul 14, 2022 at 03:00:28PM +0200, Danilo Krummrich wrote:
> Allocate driver structures with drm managed resource allocators in order
> to cleanup/simplify the drm driver .release callback.
>
> Signed-off-by: Danilo Krummrich <dakr@redhat.com>
On both patches:
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
I'm assuming you have commits rights or know someone who does :-)
-Daniel
> ---
> drivers/gpu/drm/virtio/virtgpu_kms.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 3313b92db531..63ebe63ef409 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -28,6 +28,7 @@
> #include <linux/virtio_ring.h>
>
> #include <drm/drm_file.h>
> +#include <drm/drm_managed.h>
>
> #include "virtgpu_drv.h"
>
> @@ -66,10 +67,11 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
> {
> int i, ret;
> bool invalid_capset_id = false;
> + struct drm_device *drm = vgdev->ddev;
>
> - vgdev->capsets = kcalloc(num_capsets,
> - sizeof(struct virtio_gpu_drv_capset),
> - GFP_KERNEL);
> + vgdev->capsets = drmm_kcalloc(drm, num_capsets,
> + sizeof(struct virtio_gpu_drv_capset),
> + GFP_KERNEL);
> if (!vgdev->capsets) {
> DRM_ERROR("failed to allocate cap sets\n");
> return;
> @@ -94,7 +96,7 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
>
> if (ret == 0 || invalid_capset_id) {
> spin_lock(&vgdev->display_info_lock);
> - kfree(vgdev->capsets);
> + drmm_kfree(drm, vgdev->capsets);
> vgdev->capsets = NULL;
> spin_unlock(&vgdev->display_info_lock);
> return;
> @@ -126,7 +128,7 @@ int virtio_gpu_init(struct drm_device *dev)
> if (!virtio_has_feature(dev_to_virtio(dev->dev), VIRTIO_F_VERSION_1))
> return -ENODEV;
>
> - vgdev = kzalloc(sizeof(struct virtio_gpu_device), GFP_KERNEL);
> + vgdev = drmm_kzalloc(dev, sizeof(struct virtio_gpu_device), GFP_KERNEL);
> if (!vgdev)
> return -ENOMEM;
>
> @@ -257,7 +259,6 @@ int virtio_gpu_init(struct drm_device *dev)
> vgdev->vdev->config->del_vqs(vgdev->vdev);
> err_vqs:
> dev->dev_private = NULL;
> - kfree(vgdev);
> return ret;
> }
>
> @@ -296,9 +297,6 @@ void virtio_gpu_release(struct drm_device *dev)
>
> if (vgdev->has_host_visible)
> drm_mm_takedown(&vgdev->host_visible_mm);
> -
> - kfree(vgdev->capsets);
> - kfree(vgdev);
> }
>
> int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
> --
> 2.36.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-11 16:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 13:00 [PATCH 0/2] drm/virtio: use drm managed resources Danilo Krummrich
2022-07-14 13:00 ` [PATCH 1/2] drm/virtio: plane: " Danilo Krummrich
2022-07-14 13:00 ` [PATCH 2/2] drm/virtio: kms: " Danilo Krummrich
2022-08-11 16:16 ` Daniel Vetter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).