From patchwork Wed Jul 13 08:54:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12916305 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 06DA9C433EF for ; Wed, 13 Jul 2022 08:55:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A2C198855; Wed, 13 Jul 2022 08:55:11 +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 2004098852 for ; Wed, 13 Jul 2022 08:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657702507; 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=WV1sbMysUWTQnUXeMzoIvswvu0vFM2B1lJ+VzkW+y6k=; b=apvMl/8SnwKLYiPHVD4F3EhbsZSZJSrU2/aLeAZz6kMRVxWqL8nAcnN5jA+/Kko5w5A2f7 lgw3IAfN4ilPAQiadpBbYIOTFKJTNybO92QiZWKrnguON2RV8/ugVcFPNkunEnAt1edGRv vCEqKSLaET1lOAeSm4K/Y+5P+GsxA/E= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-403-VUJOlpKYOzCfAPv1weQRDA-1; Wed, 13 Jul 2022 04:55:06 -0400 X-MC-Unique: VUJOlpKYOzCfAPv1weQRDA-1 Received: by mail-ed1-f71.google.com with SMTP id w15-20020a056402268f00b0043ac600a6bcso6882354edd.6 for ; Wed, 13 Jul 2022 01:55:05 -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=WV1sbMysUWTQnUXeMzoIvswvu0vFM2B1lJ+VzkW+y6k=; b=lMegvx6a2eoqhLz48ilJqjk6OCFs5q/WgVgjuuDK3weyU8aatSjJC9iQ2n2I8apgAj gekrjgpbMFw6yb3zn896t5gsGdcbSt6eruSukxR/OlJY2tPw03cMKZ4pp/dYR6YiJxIg IHcGZcw4e9wmE0I+30Y72fxVNjLRyW1T+2WewFQjrCPEs8s9l01EkxAIP0h3vI1mdx47 8UBdKIbxhTtwsFhdEUEO5u/dQjt38BSXrC+0Z0Hinu5XxXmDnrW9FCKOdfXv9a9hbfut 33H2DhDOiPE5VKTJSemjYGMhqTP3/X9pp1T+TFOBJfQGQ2nn/UXC3WerodV8sUE6gnoK Ym7A== X-Gm-Message-State: AJIora9DJOj7QCKffD6YdC+3A4KuQC3fLiiZpBViMi64aV+qkwTl9PZv AoM7uzgmyhXrOBb0OuaxVZ/WMPVU+PB0Q+L/W22TpApR+1T9Tzmx/q3yUYQ8edeRdMRgZPZjvM3 nlvpASp3mXUxroxTM2B9Clk64IyWG X-Received: by 2002:a17:907:7631:b0:72b:3a31:6cb8 with SMTP id jy17-20020a170907763100b0072b3a316cb8mr2299320ejc.372.1657702504862; Wed, 13 Jul 2022 01:55:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vHJQ1hmybqbUFHi9JfLGHPMl0bUlQL3+VPHCXCzTLWDo10p5guo24wdgNWCe9I5IOJ7jM9Pg== X-Received: by 2002:a17:907:7631:b0:72b:3a31:6cb8 with SMTP id jy17-20020a170907763100b0072b3a316cb8mr2299307ejc.372.1657702504715; Wed, 13 Jul 2022 01:55:04 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id e2-20020a056402088200b0042dcbc3f302sm7547655edy.36.2022.07.13.01.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:55:04 -0700 (PDT) From: Danilo Krummrich To: emma@anholt.net, mripard@kernel.org, daniel@ffwll.ch, airlied@linux.ie Subject: [PATCH 1/3] drm/vc4: plane: use drm managed resources Date: Wed, 13 Jul 2022 10:54:58 +0200 Message-Id: <20220713085500.1970589-2-dakr@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220713085500.1970589-1-dakr@redhat.com> References: <20220713085500.1970589-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 the plane object with drmm_universal_plane_alloc() in order to tie the release action to the underlying struct drm_device, where all the userspace visible stuff is attached to, rather than to struct device. This can prevent potential use-after free issues on driver unload or EPROBE_DEFERRED backoff. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_plane.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index 1e866dc00ac3..0d88de31aa9c 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -1469,7 +1469,6 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev, struct vc4_plane *vc4_plane; u32 formats[ARRAY_SIZE(hvs_formats)]; int num_formats = 0; - int ret = 0; unsigned i; static const uint64_t modifiers[] = { DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED, @@ -1480,11 +1479,6 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev, DRM_FORMAT_MOD_INVALID }; - vc4_plane = devm_kzalloc(dev->dev, sizeof(*vc4_plane), - GFP_KERNEL); - if (!vc4_plane) - return ERR_PTR(-ENOMEM); - for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) { if (!hvs_formats[i].hvs5_only || vc4->is_vc5) { formats[num_formats] = hvs_formats[i].drm; @@ -1492,13 +1486,14 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev, } } + vc4_plane = drmm_universal_plane_alloc(dev, struct vc4_plane, base, 0, + &vc4_plane_funcs, formats, + num_formats, modifiers, type, + NULL); + if (!vc4_plane) + return ERR_CAST(vc4_plane); + plane = &vc4_plane->base; - ret = drm_universal_plane_init(dev, plane, 0, - &vc4_plane_funcs, - formats, num_formats, - modifiers, type, NULL); - if (ret) - return ERR_PTR(ret); if (vc4->is_vc5) drm_plane_helper_add(plane, &vc5_plane_helper_funcs); From patchwork Wed Jul 13 08:54:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12916307 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 18472CCA479 for ; Wed, 13 Jul 2022 08:55:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD8B198859; Wed, 13 Jul 2022 08:55:14 +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 0200F98854 for ; Wed, 13 Jul 2022 08:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657702510; 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=H3fERHzEDfrpIpAaHxv/FCy1Dds4VbBEuXgTRXd5v5g=; b=G1JkPohvy5emCHZrHAUHoznzO7PM8VOssQbMHiDGjW4d0Ii4ElhvB8af19gQPdeupc5IUA Iouob4HbM5myRQwpcIa9dqvGxt9BzluNSwzZuQMQheIMaCZJ5+jBNIYBgDPm9D3yHmOVMP thfzJ17Ml1FHuVn+I6gUf5hp8KfDAJ0= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-CtOZd0NRM4GDkRNkk5z8Mw-1; Wed, 13 Jul 2022 04:55:07 -0400 X-MC-Unique: CtOZd0NRM4GDkRNkk5z8Mw-1 Received: by mail-ed1-f71.google.com with SMTP id f9-20020a056402354900b0043a902b7452so7885310edd.13 for ; Wed, 13 Jul 2022 01:55:06 -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=H3fERHzEDfrpIpAaHxv/FCy1Dds4VbBEuXgTRXd5v5g=; b=FVx+wqHgzVylitKZFMbni7KtTdRXotOhYHgwazQ816DWNi7HThT8Fc3cm7bYXc9TPP 7Z0Y4I/12qXxJrusVGR+uNhnE/wz15XOUOf7/5AXlQesUSVCGmXjO+mc+aOWNyxs3Uw2 KS91i5TrQ3wSi0OdugQA0dsGRQi/AQlxu3Ecb+0s6LpHHWP7db/ta037ImcxTZOUiMnZ Wxv0DwY+wMuOMHFsh7hss6TPRUuLgFDOV7c2RLkuHCg4m8YMpUC95dCaGHyffUwnNIix dUjymgUMibnX+5gwL4PLCkm04iWOwClkVHagE6tZjd4azlp5sL0ieHzFFtz+cg058ISL TbYA== X-Gm-Message-State: AJIora+NlF+B1AD5ndbC8S5q+Lyy8Qz+b3FiAhW0Mf6IZFm8OsGLgnor V4Fruvhidewonxyc86DoljIljfoE4ydIhxGHuBSVwn3FmzgikNt+eNy5ABz7rNCCh8VoqzI8/p9 TfFKrscn1cvJYQo4gXoTHRiwRvdrq X-Received: by 2002:a17:907:7ba2:b0:72b:57da:a76e with SMTP id ne34-20020a1709077ba200b0072b57daa76emr2335171ejc.210.1657702505820; Wed, 13 Jul 2022 01:55:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uksIFx91JCqDk9omGQxTIKHtiTQi4JvUWD17uzFSAXXgmV3IwYsfa6uUC48C2qiTpru10riw== X-Received: by 2002:a17:907:7ba2:b0:72b:57da:a76e with SMTP id ne34-20020a1709077ba200b0072b57daa76emr2335162ejc.210.1657702505630; Wed, 13 Jul 2022 01:55:05 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id e2-20020a056402088200b0042dcbc3f302sm7547655edy.36.2022.07.13.01.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:55:05 -0700 (PDT) From: Danilo Krummrich To: emma@anholt.net, mripard@kernel.org, daniel@ffwll.ch, airlied@linux.ie Subject: [PATCH 2/3] drm/vc4: crtc: use drm managed resources Date: Wed, 13 Jul 2022 10:54:59 +0200 Message-Id: <20220713085500.1970589-3-dakr@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220713085500.1970589-1-dakr@redhat.com> References: <20220713085500.1970589-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 the crtc objects with drmm_kzalloc() in order to tie the release action to the underlying struct drm_device, where all the userspace visible stuff is attached to, rather than to struct device. This can prevent potential use-after free issues on driver unload or EPROBE_DEFERRED backoff. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_crtc.c | 2 +- drivers/gpu/drm/vc4/vc4_txp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c index 9355213dc883..4b0c61cc3265 100644 --- a/drivers/gpu/drm/vc4/vc4_crtc.c +++ b/drivers/gpu/drm/vc4/vc4_crtc.c @@ -1273,7 +1273,7 @@ static int vc4_crtc_bind(struct device *dev, struct device *master, void *data) struct drm_plane *destroy_plane, *temp; int ret; - vc4_crtc = devm_kzalloc(dev, sizeof(*vc4_crtc), GFP_KERNEL); + vc4_crtc = drmm_kzalloc(drm, sizeof(*vc4_crtc), GFP_KERNEL); if (!vc4_crtc) return -ENOMEM; crtc = &vc4_crtc->base; diff --git a/drivers/gpu/drm/vc4/vc4_txp.c b/drivers/gpu/drm/vc4/vc4_txp.c index 3579d487402e..ae2193fe3b29 100644 --- a/drivers/gpu/drm/vc4/vc4_txp.c +++ b/drivers/gpu/drm/vc4/vc4_txp.c @@ -479,7 +479,7 @@ static int vc4_txp_bind(struct device *dev, struct device *master, void *data) if (irq < 0) return irq; - txp = devm_kzalloc(dev, sizeof(*txp), GFP_KERNEL); + txp = drmm_kzalloc(drm, sizeof(*txp), GFP_KERNEL); if (!txp) return -ENOMEM; vc4_crtc = &txp->base; From patchwork Wed Jul 13 08:55:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12916306 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 6979FC43334 for ; Wed, 13 Jul 2022 08:55:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4AFFE98858; Wed, 13 Jul 2022 08:55:14 +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 36F2C98856 for ; Wed, 13 Jul 2022 08:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657702509; 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=fcVRbXz26cc5X8XJxCtVsg7MRei/k/v/fZBuSA3XpBc=; b=A/i7d2xg6I+guo1Th0TGloy6J0NWl8oKGcTF55zXXNCc/Spnsu41y+UV1w8S+yB415YbPz I/5OGlfwdrJcQe/TEpRstQVwzHG4XnCPgSYxUbzjsZL9vTkZojc7PvDf82n0xHABsBvaNP ne7scohIhjR3rohETpocjCudbaQawKw= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-6Vbi36RbOsme2Bn2elrnAA-1; Wed, 13 Jul 2022 04:55:08 -0400 X-MC-Unique: 6Vbi36RbOsme2Bn2elrnAA-1 Received: by mail-ed1-f70.google.com with SMTP id j6-20020a05640211c600b0043a8ea2c138so7879416edw.2 for ; Wed, 13 Jul 2022 01:55:07 -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=fcVRbXz26cc5X8XJxCtVsg7MRei/k/v/fZBuSA3XpBc=; b=dXxy1fC4EDK4qdVnjoWepoRlXjeBpY0j24VBigxfrn8TYa9IanXS7DWz1KfWki7Pcn o4eNusipXxaIq8Puhmo81Iang5tChSmZ17UsB743Ez+eUS1nRToWAGXsBhQvW+JP3GDm HKBL9RdocvDv0F1SRE7AokJgZKV1f5J9nGJgJK/TL79y7EUAkcpW0dRn0Lhplx66MHFF NBMKBolurZYDmZ5HY3mSRr7mK8Sheo8z0CPfPVNmhf+HuIJpKKaYT2r+UmEKnA2ZHBWh cyjlLw7caynWQAfaJA9VST7uCOQ0h07VZPW6xl0bkzE4+lsGGjP96JdTrg1vzXxMFu4L otzQ== X-Gm-Message-State: AJIora+Y+sc1VW6tGR6PBpSSKOhhfQqst+czNpryQ1ez5R8q3oUxAw4L CGYwy6PrXJt3RbyEmCxAkpeYj//bX1LwghCWL2W9mxBUIt73HklN8ZR3mjTG6nrjzbuZ9acXrMJ FsrDaG1w8IRPgnB9px7v6gzikZB3A X-Received: by 2002:a17:907:72d2:b0:72b:d238:4e81 with SMTP id du18-20020a17090772d200b0072bd2384e81mr1153070ejc.104.1657702506759; Wed, 13 Jul 2022 01:55:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uoCj1NHIejTvVs44x4SYoVeNxil/sudDW06Xq1k+Q+zM7RVtGQZQIK/xwAFNGifNgvc+vypQ== X-Received: by 2002:a17:907:72d2:b0:72b:d238:4e81 with SMTP id du18-20020a17090772d200b0072bd2384e81mr1153057ejc.104.1657702506523; Wed, 13 Jul 2022 01:55:06 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id e2-20020a056402088200b0042dcbc3f302sm7547655edy.36.2022.07.13.01.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 01:55:06 -0700 (PDT) From: Danilo Krummrich To: emma@anholt.net, mripard@kernel.org, daniel@ffwll.ch, airlied@linux.ie Subject: [PATCH 3/3] drm/vc4: encoder: use drm managed resources Date: Wed, 13 Jul 2022 10:55:00 +0200 Message-Id: <20220713085500.1970589-4-dakr@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220713085500.1970589-1-dakr@redhat.com> References: <20220713085500.1970589-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 the encoder objects with drmm_simple_encoder_alloc() in order to tie the release action to the underlying struct drm_device, where all the userspace visible stuff is attached to, rather than to struct device. This can prevent potential use-after free issues on driver unload or EPROBE_DEFERRED backoff. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/vc4/vc4_dpi.c | 11 ++++++----- drivers/gpu/drm/vc4/vc4_dsi.c | 10 +++++----- drivers/gpu/drm/vc4/vc4_hdmi.c | 10 ++++++---- drivers/gpu/drm/vc4/vc4_vec.c | 11 ++++++----- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_dpi.c b/drivers/gpu/drm/vc4/vc4_dpi.c index c180eb60bee8..7f1703a42060 100644 --- a/drivers/gpu/drm/vc4/vc4_dpi.c +++ b/drivers/gpu/drm/vc4/vc4_dpi.c @@ -258,10 +258,12 @@ static int vc4_dpi_bind(struct device *dev, struct device *master, void *data) if (!dpi) return -ENOMEM; - vc4_dpi_encoder = devm_kzalloc(dev, sizeof(*vc4_dpi_encoder), - GFP_KERNEL); - if (!vc4_dpi_encoder) - return -ENOMEM; + vc4_dpi_encoder = drmm_simple_encoder_alloc(drm, struct vc4_dpi_encoder, + base.base, + DRM_MODE_ENCODER_DPI); + if (IS_ERR(vc4_dpi_encoder)) + return PTR_ERR(vc4_dpi_encoder); + vc4_dpi_encoder->base.type = VC4_ENCODER_TYPE_DPI; vc4_dpi_encoder->dpi = dpi; dpi->encoder = &vc4_dpi_encoder->base.base; @@ -299,7 +301,6 @@ static int vc4_dpi_bind(struct device *dev, struct device *master, void *data) if (ret) DRM_ERROR("Failed to turn on core clock: %d\n", ret); - drm_simple_encoder_init(drm, dpi->encoder, DRM_MODE_ENCODER_DPI); drm_encoder_helper_add(dpi->encoder, &vc4_dpi_encoder_helper_funcs); ret = vc4_dpi_init_bridge(dpi); diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c index 98308a17e4ed..8ca3b73e26dc 100644 --- a/drivers/gpu/drm/vc4/vc4_dsi.c +++ b/drivers/gpu/drm/vc4/vc4_dsi.c @@ -1498,10 +1498,11 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data) dsi->variant = of_device_get_match_data(dev); - vc4_dsi_encoder = devm_kzalloc(dev, sizeof(*vc4_dsi_encoder), - GFP_KERNEL); - if (!vc4_dsi_encoder) - return -ENOMEM; + vc4_dsi_encoder = drmm_simple_encoder_alloc(drm, struct vc4_dsi_encoder, + base.base, + DRM_MODE_ENCODER_DSI); + if (IS_ERR(vc4_dsi_encoder)) + return PTR_ERR(vc4_dsi_encoder); INIT_LIST_HEAD(&dsi->bridge_chain); vc4_dsi_encoder->base.type = VC4_ENCODER_TYPE_DSI1; @@ -1614,7 +1615,6 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data) if (ret) return ret; - drm_simple_encoder_init(drm, dsi->encoder, DRM_MODE_ENCODER_DSI); drm_encoder_helper_add(dsi->encoder, &vc4_dsi_encoder_helper_funcs); ret = drm_bridge_attach(dsi->encoder, dsi->bridge, NULL, 0); diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index ce9d16666d91..4657b09649f7 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -2834,9 +2834,12 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) struct device_node *ddc_node; int ret; - vc4_hdmi = devm_kzalloc(dev, sizeof(*vc4_hdmi), GFP_KERNEL); - if (!vc4_hdmi) - return -ENOMEM; + vc4_hdmi = drmm_simple_encoder_alloc(drm, struct vc4_hdmi, + encoder.base, + DRM_MODE_ENCODER_DSI); + if (IS_ERR(vc4_hdmi)) + return PTR_ERR(vc4_hdmi); + mutex_init(&vc4_hdmi->mutex); spin_lock_init(&vc4_hdmi->hw_lock); INIT_DELAYED_WORK(&vc4_hdmi->scrambling_work, vc4_hdmi_scrambling_wq); @@ -2921,7 +2924,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) clk_prepare_enable(vc4_hdmi->pixel_bvb_clock); } - drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_TMDS); drm_encoder_helper_add(encoder, &vc4_hdmi_encoder_helper_funcs); ret = vc4_hdmi_connector_init(drm, vc4_hdmi); diff --git a/drivers/gpu/drm/vc4/vc4_vec.c b/drivers/gpu/drm/vc4/vc4_vec.c index 11fc3d6f66b1..d6466f1ef490 100644 --- a/drivers/gpu/drm/vc4/vc4_vec.c +++ b/drivers/gpu/drm/vc4/vc4_vec.c @@ -546,10 +546,12 @@ static int vc4_vec_bind(struct device *dev, struct device *master, void *data) if (!vec) return -ENOMEM; - vc4_vec_encoder = devm_kzalloc(dev, sizeof(*vc4_vec_encoder), - GFP_KERNEL); - if (!vc4_vec_encoder) - return -ENOMEM; + vc4_vec_encoder = drmm_simple_encoder_alloc(drm, struct vc4_vec_encoder, + base.base, + DRM_MODE_ENCODER_TVDAC); + if (IS_ERR(vc4_vec_encoder)) + return PTR_ERR(vc4_vec_encoder); + vc4_vec_encoder->base.type = VC4_ENCODER_TYPE_VEC; vc4_vec_encoder->vec = vec; vec->encoder = &vc4_vec_encoder->base.base; @@ -574,7 +576,6 @@ static int vc4_vec_bind(struct device *dev, struct device *master, void *data) pm_runtime_enable(dev); - drm_simple_encoder_init(drm, vec->encoder, DRM_MODE_ENCODER_TVDAC); drm_encoder_helper_add(vec->encoder, &vc4_vec_encoder_helper_funcs); vec->connector = vc4_vec_connector_init(drm, vec);