From patchwork Thu Jul 14 13:00:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12917943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D03FCC433EF for ; Thu, 14 Jul 2022 13:00:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C59D510E489; Thu, 14 Jul 2022 13:00:39 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 73FA410ED9A for ; Thu, 14 Jul 2022 13:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657803635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f5+OHAHK2VLcrnL1KSJdq9/Govt0hy/raOewuyTrtrI=; b=MvJpAR9iQM//nnTRErmgfQnkm90O0WZEgXU3PJw96PXCuD1VJEkRdnZU68LdH/8Sc1sgjT xSm+72iTZ4SV6kSN3Tl7+sMsTSn/oayIjDBTZuyoE99wIWUr3hCk4z3QmyUl1hXnlZUm8d RohnxYmj9FRoRt5vgKr7ObTHFNHx3+Y= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-524-RdV1AZkXP-W163Xv-BWaVw-1; Thu, 14 Jul 2022 09:00:34 -0400 X-MC-Unique: RdV1AZkXP-W163Xv-BWaVw-1 Received: by mail-ed1-f72.google.com with SMTP id m13-20020a056402430d00b0043ac2f27d83so1478518edc.20 for ; Thu, 14 Jul 2022 06:00:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f5+OHAHK2VLcrnL1KSJdq9/Govt0hy/raOewuyTrtrI=; b=qG/tMUF5j2Ts2C4/MJOdH7fIxEd2cHmkDWKBUXE2sfk7cFgdmXzqzFDf6lIUyV+xPZ jJtYfcIps7r8QqHKL0Dif2cyDHdOb86PB65FTwMTTkk356mTZeTR88u1qdOIuA8kk2GL lOkSepMNYteNxm5nVWPcNOWmYl2X8SaBSciQrODU7LSV3I9H5U94M0K91B9OjtlqBSy1 AWJ70qa9TEogh4Ojh6IvmMHD6Zo0SpDWBOs4IoRO0KmYbBQ4pVkocdRWGBxh2tbOCUGi XH6KQhm44hmjzRTEtHImg7ehONTUiZ1P5CXqWtSGOsbHg/cxSIlszGgkGwz4gTMkPuPX 4VcA== X-Gm-Message-State: AJIora9RlZad+o5ZXqckNzuMzhueDHc/tKT3tttVqaC7t/AdC0Cg6VD8 1XzaORMRmI7g3xWnh/Yj6umbp/FIpa0IdfO6jcuaVajB1DzdL6FWE2phj2dZONMm4MdYP1IxJjO PS3XkjjdhGcD3Lhi70rDJwdWiyOnh X-Received: by 2002:a17:907:1b25:b0:6da:8206:fc56 with SMTP id mp37-20020a1709071b2500b006da8206fc56mr8627156ejc.81.1657803633107; Thu, 14 Jul 2022 06:00:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vkP+Ryg2/TaLqA61ZrbhfntjLs/5u4V31Ija64DGclgSFfjLRVcA3qAMSo+XslbGnUdCIcjA== X-Received: by 2002:a17:907:1b25:b0:6da:8206:fc56 with SMTP id mp37-20020a1709071b2500b006da8206fc56mr8627134ejc.81.1657803632961; Thu, 14 Jul 2022 06:00:32 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id zk9-20020a17090733c900b0072ecef772acsm694237ejb.2.2022.07.14.06.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 06:00:31 -0700 (PDT) From: Danilo Krummrich To: airlied@linux.ie, daniel@ffwll.ch, kraxel@redhat.com Subject: [PATCH 1/2] drm/virtio: plane: use drm managed resources Date: Thu, 14 Jul 2022 15:00:27 +0200 Message-Id: <20220714130028.2127858-2-dakr@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220714130028.2127858-1-dakr@redhat.com> References: <20220714130028.2127858-1-dakr@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dakr@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use drm managed resource allocation (drmm_universal_plane_alloc()) in order to cleanup/simplify drm plane .destroy callback. Signed-off-by: Danilo Krummrich --- 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); } From patchwork Thu Jul 14 13:00:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12917944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABD38C43334 for ; Thu, 14 Jul 2022 13:00:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CFC3D10ED9A; Thu, 14 Jul 2022 13:00:43 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 42EC210E73D for ; Thu, 14 Jul 2022 13:00:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657803640; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X16iBV7KhZ9Ln6lEGuQir3iZX0VSxdQjWbZR3Ippd7s=; b=U4HDFOc+5AQ25CW6I3V1+Ylia4s/d3YttR5obHCzCmGv8hRGGsf3gkanDzQM1yH3zAHO9X 4rMrFaDcfjQ5fCTf7y0fz3Z19f2xduubmGJ3XUrrgJVcV/4oYPdarp+ciQtQMIJctCJIqV nY7HRfEIQTFRoTvOd7Wrz40erer1S4I= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-457-wEsedtpTOWeFPWYlN0RqCQ-1; Thu, 14 Jul 2022 09:00:36 -0400 X-MC-Unique: wEsedtpTOWeFPWYlN0RqCQ-1 Received: by mail-ed1-f72.google.com with SMTP id m10-20020a056402510a00b0043a93d807ffso1466774edd.12 for ; Thu, 14 Jul 2022 06:00:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X16iBV7KhZ9Ln6lEGuQir3iZX0VSxdQjWbZR3Ippd7s=; b=vu+eDJ0heMiH/Z9egNW2PKVHsVk7JAVCrkNaB0vXraII0WfEDaLTmotZEFLeGPbgVq 8+Lp2CBJKawqsVureEWU5wmnO2ZqPLYHKI3XxRsRLlzAEi1UugggTT2Wn2QVdr51DpPn sNvnSKjo0C4/KwOFPo88S3MFQH063r698H7PGFqZTGIqTLDCH+m2m87VFg/P126P7gxe JCHpXln5jM6pz0XQW9ix30Y4wPhFruU/kX5av4v/Twyk7gMJwJZNZpfIrg6DCvyU01E/ 2RivEZgZrJRpvumfZta4FZgAOygr+h2uLSA/C3v/tNisKS5T+xbXnGAWZ4fwwj2R3WP+ c20A== X-Gm-Message-State: AJIora+Ldk/tSoGy8bPEyj85AkQHFWxt3jyf6VPHJDg13+FGEF4CsSQB hFiTrdvhOnCF21zqUf+LbL5LwZSqplAkM6GWCjfEDcP8FVcoZIHZTfYJC3s4xVblD4rUQqBkNs9 X07ZkHwFezhCheHJUgsB3udsRpiub X-Received: by 2002:a17:906:6a26:b0:72e:cee5:d1b0 with SMTP id qw38-20020a1709066a2600b0072ecee5d1b0mr5451196ejc.404.1657803635445; Thu, 14 Jul 2022 06:00:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v85WghBi+OK8f1leK61CfSKKhJ1e/q/FFkhJ0V6008dxPsF5cUEPomwzP1oAuhcv+e0UGMJg== X-Received: by 2002:a17:906:6a26:b0:72e:cee5:d1b0 with SMTP id qw38-20020a1709066a2600b0072ecee5d1b0mr5451176ejc.404.1657803635237; Thu, 14 Jul 2022 06:00:35 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id zk9-20020a17090733c900b0072ecef772acsm694237ejb.2.2022.07.14.06.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 06:00:34 -0700 (PDT) From: Danilo Krummrich To: airlied@linux.ie, daniel@ffwll.ch, kraxel@redhat.com Subject: [PATCH 2/2] drm/virtio: kms: use drm managed resources Date: Thu, 14 Jul 2022 15:00:28 +0200 Message-Id: <20220714130028.2127858-3-dakr@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220714130028.2127858-1-dakr@redhat.com> References: <20220714130028.2127858-1-dakr@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dakr@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Allocate driver structures with drm managed resource allocators in order to cleanup/simplify the drm driver .release callback. Signed-off-by: Danilo Krummrich Reviewed-by: Daniel Vetter --- 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 #include +#include #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)