From patchwork Fri Aug 19 21:20:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949238 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 39CA4C32771 for ; Fri, 19 Aug 2022 21:20:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1EB6810E469; Fri, 19 Aug 2022 21:20:44 +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 4FB1010E11C for ; Fri, 19 Aug 2022 21:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944029; 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=69RvVGMWC6PWcztw+ehBzvKOoAq86yIaOh4KmWH1rn8=; b=SVhtS8uVhAfEP+qtYYsOOkpdL05WJzJstd3GlwqYaUvmyMBcwEVWJ/Lh1plPpmg33/ypDO c25/L+CnNgT5FI5Xb7rIU/heXkoNFu6q/dPxO7sH2sbzxA+KYI2jwppBOy2n5Od4a7uM7Z ze3pcihQCdAKDffMbll0sNAib81gzwE= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-262-pVJ6-I6UMzCP4NfwNvApRw-1; Fri, 19 Aug 2022 17:20:20 -0400 X-MC-Unique: pVJ6-I6UMzCP4NfwNvApRw-1 Received: by mail-ej1-f70.google.com with SMTP id qf23-20020a1709077f1700b007308a195618so1904706ejc.7 for ; Fri, 19 Aug 2022 14:20:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=69RvVGMWC6PWcztw+ehBzvKOoAq86yIaOh4KmWH1rn8=; b=Qd1o7gzKcCYZNVa8+Y71Av5fBzwui1aNJ/qxwhZhtnUlOuWvIr3/kfCSj5HwPV5dh0 MN1YwJo2WwOzryfu7P8DPHygKdLrIA1MdW5AJnNyfofiUsJXMOTwupiRWIvKRCJ19//g cwJY8aTsCBRqHhHUsu9ieTq5rAjA7ZltSX+j/Bdsz8J3vSJqpNp5AfGuevrZYd2WLpzE 7mTMIlyTJIimYCurTQa7lYTa4Ix1+YZhKadIfbIT4myJaueUbyD1IzKL1lMXXvzMmv8e YDytSbv77CKaAtGNfIuoRZKVRa6a2131fS6sydJ07l59HhEJFETEHcizHW9/RSfA7SEH +J4w== X-Gm-Message-State: ACgBeo2P587syhWdN5bINmma9hY08Td3dcnsJFOh/1tGOJI3VVc4vJDY QumpajCYMPShno9YysJh0Q+OISFEUN/NHENAais33Y9ILF/V2OBWjUXj1BmOb+GcxOYz44qD6t+ pEWqiwbHLuD4OgzxRA5mmTGABb5OO X-Received: by 2002:a05:6402:1d4e:b0:43d:9822:b4d1 with SMTP id dz14-20020a0564021d4e00b0043d9822b4d1mr7554032edb.212.1660944019758; Fri, 19 Aug 2022 14:20:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR5dFXgAXxrRicMIg3tcN2kRGkCFPbbgLp6c8l7TyVrDiXaHWuT6VnRsLgQQrd2FZHWq8dN9SQ== X-Received: by 2002:a05:6402:1d4e:b0:43d:9822:b4d1 with SMTP id dz14-20020a0564021d4e00b0043d9822b4d1mr7554018edb.212.1660944019625; Fri, 19 Aug 2022 14:20:19 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id y14-20020a1709063a8e00b0073a644ef803sm2777029ejd.101.2022.08.19.14.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:20:19 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 1/8] drm/arm/malidp: use drmm_* to allocate driver structures Date: Fri, 19 Aug 2022 23:20:08 +0200 Message-Id: <20220819212015.556220-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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 resources to allocate driver structures and get rid of the deprecated drm_dev_alloc() call and replace it with devm_drm_dev_alloc(). This also serves as preparation to get rid of drm_device->dev_private and to fix use-after-free issues on driver unload. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 20 +++++++------------- drivers/gpu/drm/arm/malidp_drv.h | 1 + 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 1d0b0c54ccc7..41c80e905991 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -716,11 +717,13 @@ static int malidp_bind(struct device *dev) int ret = 0, i; u32 version, out_depth = 0; - malidp = devm_kzalloc(dev, sizeof(*malidp), GFP_KERNEL); - if (!malidp) - return -ENOMEM; + malidp = devm_drm_dev_alloc(dev, &malidp_driver, typeof(*malidp), base); + if (IS_ERR(malidp)) + return PTR_ERR(malidp); + + drm = &malidp->base; - hwdev = devm_kzalloc(dev, sizeof(*hwdev), GFP_KERNEL); + hwdev = drmm_kzalloc(drm, sizeof(*hwdev), GFP_KERNEL); if (!hwdev) return -ENOMEM; @@ -753,12 +756,6 @@ static int malidp_bind(struct device *dev) if (ret && ret != -ENODEV) return ret; - drm = drm_dev_alloc(&malidp_driver, dev); - if (IS_ERR(drm)) { - ret = PTR_ERR(drm); - goto alloc_fail; - } - drm->dev_private = malidp; dev_set_drvdata(dev, drm); @@ -887,8 +884,6 @@ static int malidp_bind(struct device *dev) malidp_runtime_pm_suspend(dev); drm->dev_private = NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); -alloc_fail: of_reserved_mem_device_release(dev); return ret; @@ -917,7 +912,6 @@ static void malidp_unbind(struct device *dev) malidp_runtime_pm_suspend(dev); drm->dev_private = NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); of_reserved_mem_device_release(dev); } diff --git a/drivers/gpu/drm/arm/malidp_drv.h b/drivers/gpu/drm/arm/malidp_drv.h index cdfddfabf2d1..00be369b28f1 100644 --- a/drivers/gpu/drm/arm/malidp_drv.h +++ b/drivers/gpu/drm/arm/malidp_drv.h @@ -29,6 +29,7 @@ struct malidp_error_stats { }; struct malidp_drm { + struct drm_device base; struct malidp_hw_device *dev; struct drm_crtc crtc; struct drm_writeback_connector mw_connector; From patchwork Fri Aug 19 21:20:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949237 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 EBC75C32772 for ; Fri, 19 Aug 2022 21:20:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6BA8B10E11C; Fri, 19 Aug 2022 21:20:37 +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 82C7210E11C for ; Fri, 19 Aug 2022 21:20:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944025; 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=+Ijy3Q7tFZuVJZh+APF9uvbAJEvF3VUDq7eKTxt/Smo=; b=XVTRAq90ATzr32ak0xyZ+HCMrOJn3dEP6CzEiH2JS/klNMn2wIj29iHjHszUlCdTdQUUx9 dTR3RnuRYSJ+HK6v6u76iVNmKS90t2a0f2aO/yZxBY6OXlmkMhVu5x74lFYAGK8sZW0Ua3 1j5kAejg6HGlHALToZ8mjAZwVDkulIk= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-615-Qp_PkpfvPLiI0ggfKXMTWA-1; Fri, 19 Aug 2022 17:20:23 -0400 X-MC-Unique: Qp_PkpfvPLiI0ggfKXMTWA-1 Received: by mail-ed1-f72.google.com with SMTP id h8-20020a05640250c800b0044642d29d35so1522555edb.18 for ; Fri, 19 Aug 2022 14:20:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=+Ijy3Q7tFZuVJZh+APF9uvbAJEvF3VUDq7eKTxt/Smo=; b=op0myy0DXLJK4D8ZblV0yh8o1Ko188mFVEW81FCNMTSIzCcA0cCXOyi79nkoCRcC6F J2TlxyUFUpXguKG6e/0C74OMgm3x59KFkaFP2PPpbrnDNORDs8JBVGNt+jh5M4klhqck XvgtGjknOFHViacll3Ku+8oYctWLM1+o8IZ6bhru3azyzr2pHhGgn9aBI5P0BxCzu+3D ATNVIDzv4xo2vG6YqeiiVou4QmLZD/xUhxImIOUWOkhoAm8KXAUxSpcXqAyt7fRjU0m4 3J9eqtXiHoy1X/wkunTFNfHelnQ4hu7Rver55ndaXvevGZSGezQ+xNn5PB6utVmMpWBS uKBg== X-Gm-Message-State: ACgBeo09t+BV5wdf7fipv1YvdBidLAuvjyt4mL02azcab0GFlBhYfa/X 2Eef9jr6/gZIolZpyTw5g34BjtS2Q0WVWStkZjdivOlOR1mVtVeFb2OCFjqZSWeXkPBMf8RcF6G G1j0cfaDTC1KH+tUyUOyoMrKbsam3 X-Received: by 2002:a17:907:87b0:b0:738:e618:99ca with SMTP id qv48-20020a17090787b000b00738e61899camr5989903ejc.357.1660944021168; Fri, 19 Aug 2022 14:20:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6z4Ex52kL2FtWsdGrWFLD8NI6e02JpvhcJ1HBSFgvKohvS3cj5ru16G7msAzbRDqudRQU0QQ== X-Received: by 2002:a17:907:87b0:b0:738:e618:99ca with SMTP id qv48-20020a17090787b000b00738e61899camr5989893ejc.357.1660944020982; Fri, 19 Aug 2022 14:20:20 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id y14-20020a1709063a8e00b0073a644ef803sm2777029ejd.101.2022.08.19.14.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:20:20 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 2/8] drm/arm/malidp: replace drm->dev_private with drm_to_malidp() Date: Fri, 19 Aug 2022 23:20:09 +0200 Message-Id: <20220819212015.556220-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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" Using drm_device->dev_private is deprecated. Since we've switched to devm_drm_dev_alloc(), struct drm_device is now embedded in struct malidp_drm, hence we can use container_of() to get the struct drm_device instance instead. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_crtc.c | 2 +- drivers/gpu/drm/arm/malidp_drv.c | 29 +++++++++++++---------------- drivers/gpu/drm/arm/malidp_drv.h | 1 + drivers/gpu/drm/arm/malidp_hw.c | 10 +++++----- drivers/gpu/drm/arm/malidp_mw.c | 6 +++--- drivers/gpu/drm/arm/malidp_planes.c | 4 ++-- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c index 962730772b2f..34ad7e1cd2b8 100644 --- a/drivers/gpu/drm/arm/malidp_crtc.c +++ b/drivers/gpu/drm/arm/malidp_crtc.c @@ -526,7 +526,7 @@ static const struct drm_crtc_funcs malidp_crtc_funcs = { int malidp_crtc_init(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_plane *primary = NULL, *plane; int ret; diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 41c80e905991..678c5b0d8014 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -169,7 +169,7 @@ static void malidp_atomic_commit_se_config(struct drm_crtc *crtc, */ static int malidp_set_and_wait_config_valid(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; int ret; @@ -190,7 +190,7 @@ static int malidp_set_and_wait_config_valid(struct drm_device *drm) static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state) { struct drm_device *drm = state->dev; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); int loop = 5; malidp->event = malidp->crtc.state->event; @@ -231,7 +231,7 @@ static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state) static void malidp_atomic_commit_tail(struct drm_atomic_state *state) { struct drm_device *drm = state->dev; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_crtc *crtc; struct drm_crtc_state *old_crtc_state; int i; @@ -393,7 +393,7 @@ static const struct drm_mode_config_funcs malidp_mode_config_funcs = { static int malidp_init(struct drm_device *drm) { int ret; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; drm_mode_config_init(drm); @@ -429,7 +429,7 @@ static int malidp_irq_init(struct platform_device *pdev) { int irq_de, irq_se, ret = 0; struct drm_device *drm = dev_get_drvdata(&pdev->dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; /* fetch the interrupts from DT */ @@ -463,7 +463,7 @@ static int malidp_dumb_create(struct drm_file *file_priv, struct drm_device *drm, struct drm_mode_create_dumb *args) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); /* allocate for the worst case scenario, i.e. rotated buffers */ u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1); @@ -509,7 +509,7 @@ static void malidp_error_stats_dump(const char *prefix, static int malidp_show_stats(struct seq_file *m, void *arg) { struct drm_device *drm = m->private; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); unsigned long irqflags; struct malidp_error_stats de_errors, se_errors; @@ -532,7 +532,7 @@ static ssize_t malidp_debugfs_write(struct file *file, const char __user *ubuf, { struct seq_file *m = file->private_data; struct drm_device *drm = m->private; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); unsigned long irqflags; spin_lock_irqsave(&malidp->errors_lock, irqflags); @@ -553,7 +553,7 @@ static const struct file_operations malidp_debugfs_fops = { static void malidp_debugfs_init(struct drm_minor *minor) { - struct malidp_drm *malidp = minor->dev->dev_private; + struct malidp_drm *malidp = drm_to_malidp(minor->dev); malidp_error_stats_init(&malidp->de_errors); malidp_error_stats_init(&malidp->se_errors); @@ -653,7 +653,7 @@ static ssize_t core_id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); return snprintf(buf, PAGE_SIZE, "%08x\n", malidp->core_id); } @@ -671,7 +671,7 @@ ATTRIBUTE_GROUPS(mali_dp); static int malidp_runtime_pm_suspend(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; /* we can only suspend if the hardware is in config mode */ @@ -690,7 +690,7 @@ static int malidp_runtime_pm_suspend(struct device *dev) static int malidp_runtime_pm_resume(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; clk_prepare_enable(hwdev->pclk); @@ -756,7 +756,6 @@ static int malidp_bind(struct device *dev) if (ret && ret != -ENODEV) return ret; - drm->dev_private = malidp; dev_set_drvdata(dev, drm); /* Enable power management */ @@ -882,7 +881,6 @@ static int malidp_bind(struct device *dev) pm_runtime_disable(dev); else malidp_runtime_pm_suspend(dev); - drm->dev_private = NULL; dev_set_drvdata(dev, NULL); of_reserved_mem_device_release(dev); @@ -892,7 +890,7 @@ static int malidp_bind(struct device *dev) static void malidp_unbind(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; drm_dev_unregister(drm); @@ -910,7 +908,6 @@ static void malidp_unbind(struct device *dev) pm_runtime_disable(dev); else malidp_runtime_pm_suspend(dev); - drm->dev_private = NULL; dev_set_drvdata(dev, NULL); of_reserved_mem_device_release(dev); } diff --git a/drivers/gpu/drm/arm/malidp_drv.h b/drivers/gpu/drm/arm/malidp_drv.h index 00be369b28f1..bc0387876dea 100644 --- a/drivers/gpu/drm/arm/malidp_drv.h +++ b/drivers/gpu/drm/arm/malidp_drv.h @@ -45,6 +45,7 @@ struct malidp_drm { #endif }; +#define drm_to_malidp(x) container_of(x, struct malidp_drm, base) #define crtc_to_malidp_device(x) container_of(x, struct malidp_drm, crtc) struct malidp_plane { diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_hw.c index e9de542f9b7c..9b845d3f34e1 100644 --- a/drivers/gpu/drm/arm/malidp_hw.c +++ b/drivers/gpu/drm/arm/malidp_hw.c @@ -1168,7 +1168,7 @@ static void malidp_hw_clear_irq(struct malidp_hw_device *hwdev, u8 block, u32 ir static irqreturn_t malidp_de_irq(int irq, void *arg) { struct drm_device *drm = arg; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev; struct malidp_hw *hw; const struct malidp_irq_map *de; @@ -1226,7 +1226,7 @@ static irqreturn_t malidp_de_irq(int irq, void *arg) static irqreturn_t malidp_de_irq_thread_handler(int irq, void *arg) { struct drm_device *drm = arg; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); wake_up(&malidp->wq); @@ -1252,7 +1252,7 @@ void malidp_de_irq_hw_init(struct malidp_hw_device *hwdev) int malidp_de_irq_init(struct drm_device *drm, int irq) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; int ret; @@ -1286,7 +1286,7 @@ void malidp_de_irq_fini(struct malidp_hw_device *hwdev) static irqreturn_t malidp_se_irq(int irq, void *arg) { struct drm_device *drm = arg; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; struct malidp_hw *hw = hwdev->hw; const struct malidp_irq_map *se = &hw->map.se_irq_map; @@ -1363,7 +1363,7 @@ static irqreturn_t malidp_se_irq_thread_handler(int irq, void *arg) int malidp_se_irq_init(struct drm_device *drm, int irq) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; int ret; diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c index ef76d0e6ee2f..626709bec6f5 100644 --- a/drivers/gpu/drm/arm/malidp_mw.c +++ b/drivers/gpu/drm/arm/malidp_mw.c @@ -129,7 +129,7 @@ malidp_mw_encoder_atomic_check(struct drm_encoder *encoder, struct drm_connector_state *conn_state) { struct malidp_mw_connector_state *mw_state = to_mw_state(conn_state); - struct malidp_drm *malidp = encoder->dev->dev_private; + struct malidp_drm *malidp = drm_to_malidp(encoder->dev); struct drm_framebuffer *fb; int i, n_planes; @@ -207,7 +207,7 @@ static u32 *get_writeback_formats(struct malidp_drm *malidp, int *n_formats) int malidp_mw_connector_init(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); u32 *formats; int ret, n_formats; @@ -236,7 +236,7 @@ int malidp_mw_connector_init(struct drm_device *drm) void malidp_mw_atomic_commit(struct drm_device *drm, struct drm_atomic_state *old_state) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_writeback_connector *mw_conn = &malidp->mw_connector; struct drm_connector_state *conn_state = mw_conn->base.state; struct malidp_hw_device *hwdev = malidp->dev; diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 45f5e35e7f24..815d9199752f 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -151,7 +151,7 @@ bool malidp_format_mod_supported(struct drm_device *drm, { const struct drm_format_info *info; const u64 *modifiers; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); const struct malidp_hw_regmap *map = &malidp->dev->hw->map; if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) @@ -931,7 +931,7 @@ static const uint64_t linear_only_modifiers[] = { int malidp_de_planes_init(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); const struct malidp_hw_regmap *map = &malidp->dev->hw->map; struct malidp_plane *plane = NULL; enum drm_plane_type plane_type; From patchwork Fri Aug 19 21:24:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949240 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 CB536C32771 for ; Fri, 19 Aug 2022 21:24:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E3AE10E485; Fri, 19 Aug 2022 21:24:58 +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 9378410E6D3 for ; Fri, 19 Aug 2022 21:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944290; 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=qabemuj06WeoMtZf9HrAveZ66zZ44DWBaH/ByyW71MM=; b=Xj+KSjmSjtJDFRCgN4FuEo4C3D9J2+Umu9CZtKAgMscHo2lZ8WAz4XDoHQeQYaTId4uNl4 J/2EhWEbugllOlOIJFFC5iMVfzrKMZTiktSmimmMfoDvOV7SOf5ToW2jR8z8qJaGpPiWbe TzsqkdVUxsGqRlJareFYmiKI9OE3cRA= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-183-LOJkvoyIMuetbzj2jF6jlQ-1; Fri, 19 Aug 2022 17:24:49 -0400 X-MC-Unique: LOJkvoyIMuetbzj2jF6jlQ-1 Received: by mail-ed1-f70.google.com with SMTP id j19-20020a05640211d300b0043ddce5c23aso3344686edw.14 for ; Fri, 19 Aug 2022 14:24:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=qabemuj06WeoMtZf9HrAveZ66zZ44DWBaH/ByyW71MM=; b=tzMms/a1l4MUkfK00HlpCuLb4GL3f3xx5YlbU25NQlAcInSfcsAT3EBB85ZB7gZPvw f6i0A2QVhDN+a4v6+GR3oqCdc3WZf63gqrNpf6YsFlEw9Ko6JFFzoL2eHatZROIAXRkE YTKphaVgHWFjl/QqCJif7BCxDuSeC9xDklYUu4la3auJ4lgxRr80ZN6hZVqanTs1tPSj R7E8IZtmTmOnEUjWwbxGQK+QT6W5F9gStl3MoSigEGR7rZ5Lt8ZfRxxh61v/rzn1mvyV rcjDq44BozqDwzB+fSGbNsMXxAwPDEo0VVKOc4aSsVn8puh3ADGd6OQpCxKXRsXd/qrH /4/Q== X-Gm-Message-State: ACgBeo1/2+ivMPBgLy5G0ejKyZPdTcirK3uSJcTXYpz6eF2jE9led1p9 S/+5SazoXZiHJyB6Sck0h73aYjqK9CfcHrQ0smdmDfYja+0KtTBxDPLYay000tONMwvYkQ2vzrV N+W0G5zVVxJeKInF3AtB5AF+riOK2 X-Received: by 2002:a17:907:72d1:b0:730:a0c4:2aaa with SMTP id du17-20020a17090772d100b00730a0c42aaamr5757442ejc.560.1660944288439; Fri, 19 Aug 2022 14:24:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5+OgT12yPU20ztpomqJKCst6cahhGUss/gNkPlFCza36i5yJPP9m5o6KfAuZAYV46c1N0Q1A== X-Received: by 2002:a17:907:72d1:b0:730:a0c4:2aaa with SMTP id du17-20020a17090772d100b00730a0c42aaamr5757428ejc.560.1660944288245; Fri, 19 Aug 2022 14:24:48 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id k21-20020a170906579500b0072fa24c2ecbsm2842999ejq.94.2022.08.19.14.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:24:47 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 3/8] drm/arm/malidp: crtc: use drmm_crtc_init_with_planes() Date: Fri, 19 Aug 2022 23:24:40 +0200 Message-Id: <20220819212445.559790-1-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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 drmm_crtc_init_with_planes() instead of drm_crtc_init_with_planes() to get rid of the explicit destroy hook in struct drm_plane_funcs. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_crtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c index 34ad7e1cd2b8..dc01c43f6193 100644 --- a/drivers/gpu/drm/arm/malidp_crtc.c +++ b/drivers/gpu/drm/arm/malidp_crtc.c @@ -514,7 +514,6 @@ static void malidp_crtc_disable_vblank(struct drm_crtc *crtc) } static const struct drm_crtc_funcs malidp_crtc_funcs = { - .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .reset = malidp_crtc_reset, @@ -548,8 +547,8 @@ int malidp_crtc_init(struct drm_device *drm) return -EINVAL; } - ret = drm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, - &malidp_crtc_funcs, NULL); + ret = drmm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, + &malidp_crtc_funcs, NULL); if (ret) return ret; From patchwork Fri Aug 19 21:24:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12953925 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 18679C00140 for ; Wed, 24 Aug 2022 19:17:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 993D511AB67; Wed, 24 Aug 2022 19:17:31 +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 ECB0110E6D3 for ; Fri, 19 Aug 2022 21:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944292; 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=eULzbfmfnyT2d1MeKBaP6Ap3rVDOs/VsOBler4qqAmU=; b=XyeTVGzcokJ7yV8i5ohYpHWycFIjR/cBBg6GV7gKZVyTzPXoRcBu9dXY0Ze77i/iJs1Nhd OcnRTABwlTFoYao38vu5M4rnAzHMcA9LSQGi0t3HFGGFssarfQBBMcPm6ybMuvROtxI7pc rgrC8BAbJ2pKOQah+vtxY/QekXUjqwA= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-288-LP1M9hNRNFiTwNSX_b9PJQ-1; Fri, 19 Aug 2022 17:24:51 -0400 X-MC-Unique: LP1M9hNRNFiTwNSX_b9PJQ-1 Received: by mail-ed1-f71.google.com with SMTP id r12-20020a05640251cc00b00440647ec649so3399947edd.21 for ; Fri, 19 Aug 2022 14:24:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=eULzbfmfnyT2d1MeKBaP6Ap3rVDOs/VsOBler4qqAmU=; b=gtzKyRsHEaXBQMbhwmn0p/0S6Ci/lpJyMPO5nhb7vKJYu4u1mWVk/KFYOHp0DzJM8P AWgHI/SwTQmdoAgV5yOd55XpQd3A1v4GvO5vK+eOQ8mJ8mgdXCJItuvA6QcpDaJgx/6S OrsX+2T42XVD/ynKXDqJF5DBqplH4hf0ncp8EeP2YHu26bpMo/SEQdLfr8p+g4ubY+FQ Z16V0pjdIUAqLBENlj53MjoIzP3rTXnL44h0MWo3byAaXuOSlWIMyjJ566K+2tOXZXaO LlE8AM76zD3MNeoZWEaY8kEXP7QqnDtY/ht0NUtzfAiQUDdPIc2IAlp0xdGRe7s5p+EU e9zQ== X-Gm-Message-State: ACgBeo0UPzv2shZmUo9uAsg0FPVD1KAvelo8jaYWuaFg15VnlLo6pqWI 65CYdbNGCOh4kf/N0Sn7L/AekFcPj/uh0LW42r3nYnNrgXuc2+o8bBwv6UPFT36PT4JkbJ3fiiy sNzVzXKKOl1hEV9kJGkCSY1H9Dd/+ X-Received: by 2002:a17:907:2724:b0:730:da23:5b60 with SMTP id d4-20020a170907272400b00730da235b60mr5944565ejl.43.1660944289772; Fri, 19 Aug 2022 14:24:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR5B90eHkyeTMFNC1i1+2xlqmaYUYa8XOKjU4q8gW3qKpLANgXl3OH3z13tEU4BMI6rGHaZNcQ== X-Received: by 2002:a17:907:2724:b0:730:da23:5b60 with SMTP id d4-20020a170907272400b00730da235b60mr5944561ejl.43.1660944289613; Fri, 19 Aug 2022 14:24:49 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id k21-20020a170906579500b0072fa24c2ecbsm2842999ejq.94.2022.08.19.14.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:24:49 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 4/8] drm/arm/malidp: plane: use drm managed resources Date: Fri, 19 Aug 2022 23:24:41 +0200 Message-Id: <20220819212445.559790-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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 get rid of the explicit destroy hook in struct drm_plane_funcs. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_planes.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 815d9199752f..34547edf1ee3 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -68,14 +68,6 @@ /* readahead for partial-frame prefetch */ #define MALIDP_MMU_PREFETCH_READAHEAD 8 -static void malidp_de_plane_destroy(struct drm_plane *plane) -{ - struct malidp_plane *mp = to_malidp_plane(plane); - - drm_plane_cleanup(plane); - kfree(mp); -} - /* * Replicate what the default ->reset hook does: free the state pointer and * allocate a new empty object. We just need enough space to store @@ -260,7 +252,6 @@ static bool malidp_format_mod_supported_per_plane(struct drm_plane *plane, static const struct drm_plane_funcs malidp_de_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, - .destroy = malidp_de_plane_destroy, .reset = malidp_plane_reset, .atomic_duplicate_state = malidp_duplicate_plane_state, .atomic_destroy_state = malidp_destroy_plane_state, @@ -972,12 +963,6 @@ int malidp_de_planes_init(struct drm_device *drm) for (i = 0; i < map->n_layers; i++) { u8 id = map->layers[i].id; - plane = kzalloc(sizeof(*plane), GFP_KERNEL); - if (!plane) { - ret = -ENOMEM; - goto cleanup; - } - /* build the list of DRM supported formats based on the map */ for (n = 0, j = 0; j < map->n_pixel_formats; j++) { if ((map->pixel_formats[j].layer & id) == id) @@ -990,13 +975,14 @@ int malidp_de_planes_init(struct drm_device *drm) /* * All the layers except smart layer supports AFBC modifiers. */ - ret = drm_universal_plane_init(drm, &plane->base, crtcs, - &malidp_de_plane_funcs, formats, n, - (id == DE_SMART) ? linear_only_modifiers : modifiers, - plane_type, NULL); - - if (ret < 0) + plane = drmm_universal_plane_alloc(drm, struct malidp_plane, base, + crtcs, &malidp_de_plane_funcs, formats, n, + (id == DE_SMART) ? linear_only_modifiers : + modifiers, plane_type, NULL); + if (IS_ERR(plane)) { + ret = PTR_ERR(plane); goto cleanup; + } drm_plane_helper_add(&plane->base, &malidp_de_plane_helper_funcs); From patchwork Fri Aug 19 21:24:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949242 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 17FB5C32771 for ; Fri, 19 Aug 2022 21:25:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5843B10E773; Fri, 19 Aug 2022 21:25:11 +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 8208D10E485 for ; Fri, 19 Aug 2022 21:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944293; 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=ZNisDhpi4BOnPBk5Q4gtZJ5EEe/qIg6dIjsLwDYtTko=; b=f907O9qvpuSF7XPNCviJRj0WUMeDO5GOS3gRM5ksbCI4WR87QeEvhBrltWpxWmAD1Z/B5/ uvxE+jq9EoxKu3Wd/ipA9RctzNdbo3Hb2jW2FRxnMUXDXFM4mTmEop/1ZWmpayHP33/DYC Z4NYcXZqNqoLGo4KkdXQbOnzIGWTtPo= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-364-8I3H7G9mOiyD2XuGH5SRkA-1; Fri, 19 Aug 2022 17:24:52 -0400 X-MC-Unique: 8I3H7G9mOiyD2XuGH5SRkA-1 Received: by mail-ej1-f72.google.com with SMTP id sc31-20020a1709078a1f00b0073096c2b4e1so1951527ejc.22 for ; Fri, 19 Aug 2022 14:24:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ZNisDhpi4BOnPBk5Q4gtZJ5EEe/qIg6dIjsLwDYtTko=; b=WvneZEQDQ1rx1x/5DvxAe/jS9GAkSRoGKtiqgekvPO1McG6YvCLD+HFuoD5Yw9CdcV 6qFmK96kMeQABd3BkxS5CHvgZY6GT9OQEayyWsyvKrG3uo8NA0Uoe6HBvAibo90LIYFa XwY5F7exgwZnx/iwZ660O+Og6rDjcEdlz6FwzXvpohXGq3uTrpNweuAAVNbiZ4cQI/qE qHRdzxSv2Fuw2TAx5YUBDh9HCV30J/uastdrPLshau2X1g2YiDzU+ZSoe1+6UHt2eKEK TCUfvjESULu08/NK8IIDnpG9dnhmXGGn+swh7wo7qliIg8f/MsPnbHF/fvMRXEi2mIDX BiPQ== X-Gm-Message-State: ACgBeo2kd1Hm287c7h0LHy8yo2ImZxKD03YnMJ/tr/VEk0Ggw58gXet8 AIay1GOIcrWzeE/sNLgUCyfxDceVxbTXZ7sS6zfZpOKRchwg2pmFS+x8ZDaEOMLpBcG4hrWpQuJ hirTdTGanYKrDDlQc7XrF9lKPH4C6 X-Received: by 2002:a05:6402:c45:b0:442:c549:8e6b with SMTP id cs5-20020a0564020c4500b00442c5498e6bmr7454930edb.123.1660944291637; Fri, 19 Aug 2022 14:24:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR49IKZ4pGTeuQlGM57eBuT/of7Y2qxJpRK+S8Nj2BgkCRrujKKcPSdvM66LTG6G1UhdU+EVxA== X-Received: by 2002:a05:6402:c45:b0:442:c549:8e6b with SMTP id cs5-20020a0564020c4500b00442c5498e6bmr7454914edb.123.1660944291440; Fri, 19 Aug 2022 14:24:51 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id k21-20020a170906579500b0072fa24c2ecbsm2842999ejq.94.2022.08.19.14.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:24:50 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 5/8] drm/arm/malidp: use drm_dev_unplug() Date: Fri, 19 Aug 2022 23:24:42 +0200 Message-Id: <20220819212445.559790-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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" When the driver is unbound, there might still be users in userspace having an open fd and are calling into the driver. While this is fine for drm managed resources, it is not for resources bound to the device/driver lifecycle, e.g. clocks or MMIO mappings. To prevent use-after-free issues we need to protect those resources with drm_dev_enter() and drm_dev_exit(). This does only work if we indicate that the drm device was unplugged, hence use drm_dev_unplug() instead of drm_dev_unregister(). Protecting the particular resources with drm_dev_enter()/drm_dev_exit() is handled by subsequent patches. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 678c5b0d8014..aedd30f5f451 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -893,7 +893,7 @@ static void malidp_unbind(struct device *dev) struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; - drm_dev_unregister(drm); + drm_dev_unplug(drm); drm_kms_helper_poll_fini(drm); pm_runtime_get_sync(dev); drm_atomic_helper_shutdown(drm); From patchwork Fri Aug 19 21:24:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949241 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 D447BC32771 for ; Fri, 19 Aug 2022 21:25:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D940C10E6D3; Fri, 19 Aug 2022 21:25:09 +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 4FD3410E485 for ; Fri, 19 Aug 2022 21:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944295; 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=xSUtWAzK0ahA+zp/L7/UclMHTS5yPU+3r+RqIP2CU10=; b=UfFksivwZiNIZHt5OWJ3WOakYkDz+QfRK63Y4MmEZNaUNEqFvx4K5PMA//a77lZtA7ISHY r3/p6/YMS+j0If3XXu6FYJtTi9yEBb6D2L+hM9yo/E9BZn+nyDwj6KSK1aiGFpDTPBcjgO kf2z9V1fYg+vuNP2+P2PhTLWCXU5xqE= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-596-rLHdpjx9MCKngVbiGsGbfA-1; Fri, 19 Aug 2022 17:24:54 -0400 X-MC-Unique: rLHdpjx9MCKngVbiGsGbfA-1 Received: by mail-ed1-f69.google.com with SMTP id i5-20020a05640242c500b0043e50334109so3358408edc.1 for ; Fri, 19 Aug 2022 14:24:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=xSUtWAzK0ahA+zp/L7/UclMHTS5yPU+3r+RqIP2CU10=; b=XI/DvWoXRxcbX2AwrjSV062coBXTPwhl0fkrAUoUSuvSAAFNToUM1cufw3kQgneWqH 63JZpZ/5YuiNX5NidfDKgDgGCYu9CEr2PbuumIMx8hy5kYZFh0fAzid6wbgb7wV86SFa dp6h7PV1TD/MrE01BelBAhcWk6nuKadtaOULxbP8n+RFB9KziqT+6EVLANyVoDzNm2cy TtIs/Cn58XSe/cQk2fluV7SVtdcbxexDNnA2bt+LJBujs6deohby3lsV3bOOxkZgV3+r bSsYYtER0jKyFPGKWxuUoGF+xWbrXwlCkga5Ln5dghQ0xHdHI9QL/W2mXbzzXGi7bcPS Fbzg== X-Gm-Message-State: ACgBeo0ejeQY62s+fgTgU1Qolt7VtURVHG7+nibXyQ3cPqD9/cKtN1Ty au/wOw3PdEC83RqOOCEXqFqJLqFIMor5o01BjJDxSS0+lW0FxvYGo3rCHO8rwTQGZaFonVMIrZl YRfw3isc9kd42WDLTNZlretDCVBJk X-Received: by 2002:a17:907:2c64:b0:730:defe:a419 with SMTP id ib4-20020a1709072c6400b00730defea419mr5801922ejc.680.1660944292904; Fri, 19 Aug 2022 14:24:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6oYyJVdeZhoxUxsoyFexqgp6rNALbs/+7bSlswTqyu+9Ql2HoaivzZUuTjOC23Kgx1o/fEZg== X-Received: by 2002:a17:907:2c64:b0:730:defe:a419 with SMTP id ib4-20020a1709072c6400b00730defea419mr5801915ejc.680.1660944292766; Fri, 19 Aug 2022 14:24:52 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id k21-20020a170906579500b0072fa24c2ecbsm2842999ejq.94.2022.08.19.14.24.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:24:52 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 6/8] drm/arm/malidp: plane: protect device resources after removal Date: Fri, 19 Aug 2022 23:24:43 +0200 Message-Id: <20220819212445.559790-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user didn't close it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_planes.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 34547edf1ee3..d2ea60549454 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -790,9 +790,12 @@ static void malidp_de_plane_update(struct drm_plane *plane, u16 pixel_alpha = new_state->pixel_blend_mode; u8 plane_alpha = new_state->alpha >> 8; u32 src_w, src_h, dest_w, dest_h, val; - int i; + int i, idx; struct drm_framebuffer *fb = plane->state->fb; + if (!drm_dev_enter(plane->dev, &idx)) + return; + mp = to_malidp_plane(plane); /* @@ -897,16 +900,24 @@ static void malidp_de_plane_update(struct drm_plane *plane, malidp_hw_write(mp->hwdev, val, mp->layer->base + MALIDP_LAYER_CONTROL); + + drm_dev_exit(idx); } static void malidp_de_plane_disable(struct drm_plane *plane, struct drm_atomic_state *state) { struct malidp_plane *mp = to_malidp_plane(plane); + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; malidp_hw_clearbits(mp->hwdev, LAYER_ENABLE | LAYER_FLOWCFG(LAYER_FLOWCFG_MASK), mp->layer->base + MALIDP_LAYER_CONTROL); + + drm_dev_exit(idx); } static const struct drm_plane_helper_funcs malidp_de_plane_helper_funcs = { From patchwork Fri Aug 19 21:25:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12953926 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 7C251C00140 for ; Wed, 24 Aug 2022 19:17:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E72710FC48; Wed, 24 Aug 2022 19:17:35 +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 0CE6210E7D9 for ; Fri, 19 Aug 2022 21:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944345; 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=9kBxkoMSoocenFWS5QnFTVJk53upsFpOoCTaLoDSzmI=; b=TFcajZ3DRsXroElhqrketEQBeuLZzla0/xcxjdsXhnfLcFI9zhZ+2nF/C1VFXorwIQ/3ui 2CJpsDdgWZDbJrGDAc7NEp7XXs0oRYOkdo6aSVqswRw56xqnffQWVGRtXUmQdswdxP35cL PqS+4G1rTtsWDplQ5IVTiOwSK8uoZPg= 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-665-Qq3KE4bTOmyrvNhCBmrfFQ-1; Fri, 19 Aug 2022 17:25:44 -0400 X-MC-Unique: Qq3KE4bTOmyrvNhCBmrfFQ-1 Received: by mail-ed1-f71.google.com with SMTP id o2-20020a056402438200b0043d552deb2aso3341750edc.0 for ; Fri, 19 Aug 2022 14:25:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=9kBxkoMSoocenFWS5QnFTVJk53upsFpOoCTaLoDSzmI=; b=MsKLWv5KUc6ObK+ga6pYEXgGYBqVp6i6v1F5OErE9EcGvTXkP7cm61NayD1XbmiNqk TewXvEH8rILbdBuZdXQboF8ZWp73ZwIMo1c1mYI0yXbYYNLYXEPgNuN8Wvl5dFGu5sw0 8a7ygc1nbMhTVQUSDZIRyXJOKqBl80eF76hfsJgoG9biPNR0kfAfXVtw5ip0cYGVMZXR f0Mal/t3lAMNdhTBwUojUZjPkDt4xYZJflfFZ3B+PFAuzI2h21/60xBiWW/CeuvpTJMa P8gR+vYfQVi7WqEB/ZhEoNzu2F5TDt+TKq6GuDENEH3hh0xm+JCjNoVjf8hk0KfmZ6Nw vlBw== X-Gm-Message-State: ACgBeo3CxbdDZ2EdU05y9hoFsxWRhI+zlCpHV5/usp7oZnhe9Ns6TWcc 1gYxu0zr5WFBonr5Zu0727B5vGdQ4zm4VEc1TVEi8o8v7euXrRYfD9q3ktik0d7Ta9JBjkoYO4z Gz0uq07FR2x3JADFXaCD1VO8Frge4 X-Received: by 2002:a05:6402:50cc:b0:43e:6860:58fc with SMTP id h12-20020a05640250cc00b0043e686058fcmr7476993edb.243.1660944342981; Fri, 19 Aug 2022 14:25:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+1euniUCHg7ze4TUzUMROSIcVgRyqCPA59DKYxuvVfH4krbl50afSwL5v7W/5t2MI7qbKbQ== X-Received: by 2002:a05:6402:50cc:b0:43e:6860:58fc with SMTP id h12-20020a05640250cc00b0043e686058fcmr7476979edb.243.1660944342824; Fri, 19 Aug 2022 14:25:42 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id ej19-20020a056402369300b00445f1fa531bsm3650681edb.25.2022.08.19.14.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:25:42 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 7/8] drm/arm/malidp: crtc: protect device resources after removal Date: Fri, 19 Aug 2022 23:25:37 +0200 Message-Id: <20220819212538.559902-1-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user didn't close it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_crtc.c | 41 +++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c index dc01c43f6193..fa95278abae6 100644 --- a/drivers/gpu/drm/arm/malidp_crtc.c +++ b/drivers/gpu/drm/arm/malidp_crtc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ static enum drm_mode_status malidp_crtc_mode_valid(struct drm_crtc *crtc, { struct malidp_drm *malidp = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; + int idx; /* * check that the hardware can drive the required clock rate, @@ -34,6 +36,9 @@ static enum drm_mode_status malidp_crtc_mode_valid(struct drm_crtc *crtc, */ long rate, req_rate = mode->crtc_clock * 1000; + if (!drm_dev_enter(&malidp->base, &idx)) + return MODE_NOCLOCK; + if (req_rate) { rate = clk_round_rate(hwdev->pxlclk, req_rate); if (rate != req_rate) { @@ -43,6 +48,8 @@ static enum drm_mode_status malidp_crtc_mode_valid(struct drm_crtc *crtc, } } + drm_dev_exit(idx); + return MODE_OK; } @@ -53,6 +60,10 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc, struct malidp_hw_device *hwdev = malidp->dev; struct videomode vm; int err = pm_runtime_get_sync(crtc->dev->dev); + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; if (err < 0) { DRM_DEBUG_DRIVER("Failed to enable runtime power management: %d\n", err); @@ -68,6 +79,8 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc, hwdev->hw->modeset(hwdev, &vm); hwdev->hw->leave_config_mode(hwdev); drm_crtc_vblank_on(crtc); + + drm_dev_exit(idx); } static void malidp_crtc_atomic_disable(struct drm_crtc *crtc, @@ -77,7 +90,10 @@ static void malidp_crtc_atomic_disable(struct drm_crtc *crtc, crtc); struct malidp_drm *malidp = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; - int err; + int err, idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; /* always disable planes on the CRTC that is being turned off */ drm_atomic_helper_disable_planes_on_crtc(old_state, false); @@ -91,6 +107,8 @@ static void malidp_crtc_atomic_disable(struct drm_crtc *crtc, if (err < 0) { DRM_DEBUG_DRIVER("Failed to disable runtime power management: %d\n", err); } + + drm_dev_exit(idx); } static const struct gamma_curve_segment { @@ -260,7 +278,10 @@ static int malidp_crtc_atomic_check_scaling(struct drm_crtc *crtc, u32 h_upscale_factor = 0; /* U16.16 */ u32 v_upscale_factor = 0; /* U16.16 */ u8 scaling = cs->scaled_planes_mask; - int ret; + int idx, ret; + + if (!drm_dev_enter(&malidp->base, &idx)) + return -ENODEV; if (!scaling) { s->scale_enable = false; @@ -334,6 +355,9 @@ static int malidp_crtc_atomic_check_scaling(struct drm_crtc *crtc, ret = hwdev->hw->se_calc_mclk(hwdev, s, &vm); if (ret < 0) return -EINVAL; + + drm_dev_exit(idx); + return 0; } @@ -498,9 +522,16 @@ static int malidp_crtc_enable_vblank(struct drm_crtc *crtc) { struct malidp_drm *malidp = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return -ENODEV; malidp_hw_enable_irq(hwdev, MALIDP_DE_BLOCK, hwdev->hw->map.de_irq_map.vsync_irq); + + drm_dev_exit(idx); + return 0; } @@ -508,9 +539,15 @@ static void malidp_crtc_disable_vblank(struct drm_crtc *crtc) { struct malidp_drm *malidp = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK, hwdev->hw->map.de_irq_map.vsync_irq); + + drm_dev_exit(idx); } static const struct drm_crtc_funcs malidp_crtc_funcs = { From patchwork Fri Aug 19 21:25:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949243 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 16841C3F6B0 for ; Fri, 19 Aug 2022 21:25:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9965810E715; Fri, 19 Aug 2022 21:25:57 +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 4402D10E7D9 for ; Fri, 19 Aug 2022 21:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944346; 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=hPqOotGSruHudwMIkA2GhgTM0KbwtUxu9NgLFadghJM=; b=FOn9avGsHkKZW9f+FpWmjsfVLqwpcdzlObFuNTnG6/6yc6UbDBaSzaBI4FGk8jvQpEPIPZ N1evTumBYpteTTEnPEodEE/+hN29DLUTWxjLRULlmKF9AepsRTFH+rWBLhHKz8KqoPcKMr BP+lrvfEHKgxrZYp6rdAGLxiyiz4THo= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-271-ccrVPavkPj2i2496ceKECg-1; Fri, 19 Aug 2022 17:25:45 -0400 X-MC-Unique: ccrVPavkPj2i2496ceKECg-1 Received: by mail-ej1-f72.google.com with SMTP id hv19-20020a17090760d300b00730d0a018a6so1948477ejc.21 for ; Fri, 19 Aug 2022 14:25:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=hPqOotGSruHudwMIkA2GhgTM0KbwtUxu9NgLFadghJM=; b=H9JL/E2NJvM02pprWoFmMFZDpGW+MSCcYXRoXW21/IsRNvN4+KGZwP1uGeeIhBAlsZ igtLEbK0Q3Yj/yJU2WKitL35b/H2lsQh5LzNX2R21phQBZ2wleQBnUqZXLtj8q47UC3+ mtoIxeeBqA85PIO4tYpcbVSh6cUXCngyfpo5FWSSYkBtLr0hMLsXusI17qxaqfFtXl6u mAB+TuJMCiNgjzGdxIogQRvAGLvUMWZLHQjXxlRk8bzMrp0LAxfLHhKYMuNZDIUyIS74 xKGGjo9acB63nDTF8Vg95Lnr+YFEvqGgfloecAd86LkbffGz3gGaB67HaOCOHtYo1fkt AGTg== X-Gm-Message-State: ACgBeo3qRW8ag3RbghVmPHJTYyD4MQ/wMzHaWGrVgjZj9z+ij2K1bBua Ty0mw9nHKXNOk2dwYPYa1W05r7KRCvh86r7oMtlXGb4sQ8e9CjsOt4QokAuTeK0l3lyddC1sD2a Zj6gGBD7NFQWasq3Q2BvSS82nfvdT X-Received: by 2002:a05:6402:415:b0:446:230d:2b82 with SMTP id q21-20020a056402041500b00446230d2b82mr5875886edv.200.1660944344405; Fri, 19 Aug 2022 14:25:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7HPGxg5GCr3oNRoWkMSOYoQXdCy3r5Rh15bVdNO88lO8+SW2gzGUe5OSb4mGaG4wbSWPX8tw== X-Received: by 2002:a05:6402:415:b0:446:230d:2b82 with SMTP id q21-20020a056402041500b00446230d2b82mr5875877edv.200.1660944344223; Fri, 19 Aug 2022 14:25:44 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id ej19-20020a056402369300b00445f1fa531bsm3650681edb.25.2022.08.19.14.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 14:25:43 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 8/8] drm/arm/malidp: drv: protect device resources after removal Date: Fri, 19 Aug 2022 23:25:38 +0200 Message-Id: <20220819212538.559902-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819212015.556220-1-dakr@redhat.com> References: <20220819212015.556220-1-dakr@redhat.com> MIME-Version: 1.0 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" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user didn't close it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index aedd30f5f451..8bb8e8d14461 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -234,9 +234,12 @@ static void malidp_atomic_commit_tail(struct drm_atomic_state *state) struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_crtc *crtc; struct drm_crtc_state *old_crtc_state; - int i; + int i, idx; bool fence_cookie = dma_fence_begin_signalling(); + if (!drm_dev_enter(drm, &idx)) + return; + pm_runtime_get_sync(drm->dev); /* @@ -267,6 +270,8 @@ static void malidp_atomic_commit_tail(struct drm_atomic_state *state) pm_runtime_put(drm->dev); drm_atomic_helper_cleanup_planes(drm, state); + + drm_dev_exit(idx); } static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = {