2022-07-20 14:08:41

by Danilo Krummrich

[permalink] [raw]
Subject: [PATCH RESEND 0/2] drm/virtio: use drm managed resources

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


2022-07-20 14:08:49

by Danilo Krummrich

[permalink] [raw]
Subject: [PATCH RESEND 2/2] drm/virtio: kms: use drm managed resources

Allocate driver structures with drm managed resource allocators in order
to cleanup/simplify the drm driver .release callback.

Signed-off-by: Danilo Krummrich <[email protected]>
---
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

2022-07-20 15:28:31

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH RESEND 2/2] drm/virtio: kms: use drm managed resources

Hi Danilo,

On Wed, Jul 20, 2022 at 04:02:14PM +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 <[email protected]>

This patch is already applied to drm-misc (drm-misc-next) as
90caf42527a40d09e0eed9fcbca08d757f4fd493

Sam