From patchwork Mon Sep 5 15:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966263 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 E1B01ECAAD3 for ; Mon, 5 Sep 2022 15:19:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43AF810E41C; Mon, 5 Sep 2022 15:19:28 +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 2D14C10E41C for ; Mon, 5 Sep 2022 15:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391161; 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=E6kBxVrHQg5BpXAhB3aH8H20+QiJVQY6Tt1eoILmv9a2SwXJ7gPZxSy904ojlpay+Ri0nq LEfZ3I98OAXEOpB7/tjZFIVaioXZ7X+1VIAUyHclT0Und+PpRqOYXnpvmThjU69mq5fA/Z mA+oB8d/JenwetQbjxvsgzfdrc5q05s= 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-490-XB52ZKznPhmmmagOk18XHg-1; Mon, 05 Sep 2022 11:19:19 -0400 X-MC-Unique: XB52ZKznPhmmmagOk18XHg-1 Received: by mail-ej1-f72.google.com with SMTP id gn30-20020a1709070d1e00b0074144af99d1so2460346ejc.17 for ; Mon, 05 Sep 2022 08:19:19 -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 :subject:date; bh=69RvVGMWC6PWcztw+ehBzvKOoAq86yIaOh4KmWH1rn8=; b=RE40Q64/2BqQBmEknAsDJ8Vccgg/p7KoET/cxx9Ziz9AtNbW/ZbQx6qmc3gH73xXIT QnvnE3d2u8FpJxzkDGcL+N5Ls7EqFnXCb/vPkjdUMaZY3KdMdN/KQWndevM4CeeWzXaw GmmF5z31TCKIUDcGGIfMw34ZX6WFAonaU16YQ3VM52Pl4mQHuDidpgGVNKD0hNT9L/sA y7XrH+hq8Dh7yX2+X5lhuwjeWmYTdNyyRIq+/bXob/ymERzCM/o9E56hfPbGo6LFL53x udabisLJgaITaTrPdw4Yhsb3kibaJaML2fdEiqG0v8D8NeEU+WbxLt6csmtQNIEmQdyn KE9Q== X-Gm-Message-State: ACgBeo01feLLfkXhH5bkTC9U7P4Zh0yNdnKCdt5Q2Bz5nTu6jpQTroqS iQM++da8Oai+NXnr28oLbTL6NeSn4mJ5EH2PbsUErWpYM+Jy3AZkDlooPbHVFPstXklTnmT1yJ5 Mq7lmG29y+m9flDpHJ+pmcJJtd/cy X-Received: by 2002:a17:907:7628:b0:73d:e0eb:2e51 with SMTP id jy8-20020a170907762800b0073de0eb2e51mr33667194ejc.237.1662391158773; Mon, 05 Sep 2022 08:19:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR6kcCtmJ0UuqvCPq50MTZD4S71/b8ch7tlxDuf+WGjPZhKl45DuBotJUWEhskX/YbPZg45ZIg== X-Received: by 2002:a17:907:7628:b0:73d:e0eb:2e51 with SMTP id jy8-20020a170907762800b0073de0eb2e51mr33667181ejc.237.1662391158606; Mon, 05 Sep 2022 08:19:18 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id n12-20020aa7d04c000000b0044e702cd712sm2741485edo.41.2022.09.05.08.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:19:18 -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 RESEND drm-misc-next 1/8] drm/arm/malidp: use drmm_* to allocate driver structures Date: Mon, 5 Sep 2022 17:19:03 +0200 Message-Id: <20220905151910.98279-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966265 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 0444BECAAD5 for ; Mon, 5 Sep 2022 15:19:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E78DE10E63F; Mon, 5 Sep 2022 15:19:32 +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 06E0E10E411 for ; Mon, 5 Sep 2022 15:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391165; 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=cwl7L2kBfe/CdljFux4/w5cIW42Zyj1KZcCVbRvrlwTPe94YyYdt9NztN3Lc3Fb29f8XAp U5ydF/+Uh+TGHm95sL9X4EoTyruqgPZjXpddmM0w4ntmgTg7oCPTF3pxmFErHjX3jJyWhh N/AzsIr3buMRYRIsTfYk2OUytPinC4o= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-38--mChF-pDM9CV300ijuEjEQ-1; Mon, 05 Sep 2022 11:19:24 -0400 X-MC-Unique: -mChF-pDM9CV300ijuEjEQ-1 Received: by mail-ej1-f69.google.com with SMTP id qw34-20020a1709066a2200b00730ca5a94bfso2451933ejc.3 for ; Mon, 05 Sep 2022 08:19:24 -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 :subject:date; bh=+Ijy3Q7tFZuVJZh+APF9uvbAJEvF3VUDq7eKTxt/Smo=; b=iW69AdwUQRY1jubqdldo43jae7SoG+EJShIChfrdpjI0aQSdji+D5AYl681RlvlqMy 5b4OvoqLdihhUJ21YT3RKiIDzt8ZfOY8u+8AjAzFFZHN1+uqLveJxrjf5yLpC+9KQVTK bNg0aI+vSWSxz6qIAk/4bmKljVs5mZDgCSzKMTmub/vHBSc3MKJLNaHwxuF6fNOiFVQK K6Qj/mtXdGNLkE9125+GTEzA4JiJVPpGg4j3ADcgZN1iWN3lrsYylD+nPgf+QD9R7il4 MkSbEfDSI0J0ugvDZLW9sphi0NJoOlyEh2IiFEHE1T1CYxr4CgcyjnUxzJzI6ssEoFMi icoA== X-Gm-Message-State: ACgBeo3NxznFVZkLtON87pf9ju0ytXxznoo39hWQmEiPs8BXMHFHY2fD ktOYzaaqT9IjhZZNym556dR6ALR4mSpmX20AE7mY0dpKejmAWINGB5fXhfaBVI0sHwfa+JQshaM 7eMyRILlM7WlR58BbDG2UXofIa1b4 X-Received: by 2002:a17:907:c28:b0:73d:beb7:b9c2 with SMTP id ga40-20020a1709070c2800b0073dbeb7b9c2mr36050715ejc.336.1662391162417; Mon, 05 Sep 2022 08:19:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR5D6BD20Y7BO4BpAVZZV1+RjC8V4b8roXG6JtlVzadUiNGkMeZvUPWuLxdiCH3NIg5cMXFMaA== X-Received: by 2002:a17:907:c28:b0:73d:beb7:b9c2 with SMTP id ga40-20020a1709070c2800b0073dbeb7b9c2mr36050695ejc.336.1662391162125; Mon, 05 Sep 2022 08:19:22 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id c16-20020a170906925000b0073d9d887eddsm5177440ejx.56.2022.09.05.08.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:19:21 -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 RESEND drm-misc-next 2/8] drm/arm/malidp: replace drm->dev_private with drm_to_malidp() Date: Mon, 5 Sep 2022 17:19:04 +0200 Message-Id: <20220905151910.98279-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966266 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 A000FC54EE9 for ; Mon, 5 Sep 2022 15:19:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 916BE10E973; Mon, 5 Sep 2022 15:19:33 +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 D0F2F10E411 for ; Mon, 5 Sep 2022 15:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391166; 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=WzfgLsRL3Tx0NwiMPAPa0Rg4goexlOWqNcWJSobA8GE2z7U4C+tAqq0n9rXV0a3cZ+S5aF 4jeBbPAuLkXzezfSOz1ZvMLfVOg+ef4Izk4MGvK3YWAEs+hso7pzZDT2eBXy8z9mE3IihU oLiUu4Ehae0+mO82vZJbcsjePxbsaxU= 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-594-CGZn8M5dNEGHpRp4YsfeuA-1; Mon, 05 Sep 2022 11:19:24 -0400 X-MC-Unique: CGZn8M5dNEGHpRp4YsfeuA-1 Received: by mail-ed1-f71.google.com with SMTP id y12-20020a056402358c00b00448898f1c33so5916701edc.7 for ; Mon, 05 Sep 2022 08:19:24 -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 :subject:date; bh=qabemuj06WeoMtZf9HrAveZ66zZ44DWBaH/ByyW71MM=; b=MQKRHTOgTTcui/ZhqLVjGHKIw7q6ol9UwqpMUaZDH/uaa6zQMhNciJo7Hrz6Ga8gf2 EAAu6TstXez7QavAox1O6ekRkZT3E29eI9s86alMU86TznoYGpvTonM44JXbUNW2gKKy avxRl3ZAiIG/Skw3Y+/bMUtyRhwZesGfmp5BsYUBFUdOx09zlw26gqTXL9TuxE8bd9dK n+xVQGFNy3wfAdQXyFhevQtr5sw+ZnwADp7eKOYKkuxzis4iKcirMcF009/cx+82y6Ac k48/rP7t5bVLzahKvdXmjOus3FR5IW5ywV1TFO8zs3RWhxsaBaUnAnoUzymqzlolLh1Y Bbew== X-Gm-Message-State: ACgBeo0pnLsMN1yyqEoNLMXMOZ1ZYEvX90IlJmBr5OYbluoAQOEXWa+R MK6bIhhwa8o0SbUNQ26bcJOLdB5mgBrza1KdiGV/H9RRx8YNwJ/wdzHgjvwloHRDzgmBQuUP5fz 6ghSsF+cj+90AA3R2byQ+TLj6keVI X-Received: by 2002:a05:6402:1514:b0:448:312:368 with SMTP id f20-20020a056402151400b0044803120368mr39817456edw.263.1662391163637; Mon, 05 Sep 2022 08:19:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR7hAlooCdjVZ738aZDpf606K1bTFeilkcuJNs5qFARVCKKuEfZylLyTwJUVtjZG/kd1JMorOw== X-Received: by 2002:a05:6402:1514:b0:448:312:368 with SMTP id f20-20020a056402151400b0044803120368mr39817438edw.263.1662391163491; Mon, 05 Sep 2022 08:19:23 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id c16-20020a170906925000b0073d9d887eddsm5177440ejx.56.2022.09.05.08.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:19:22 -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 RESEND drm-misc-next 3/8] drm/arm/malidp: crtc: use drmm_crtc_init_with_planes() Date: Mon, 5 Sep 2022 17:19:05 +0200 Message-Id: <20220905151910.98279-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966267 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 7352BECAAD5 for ; Mon, 5 Sep 2022 15:19:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63EE810E60F; Mon, 5 Sep 2022 15:19:47 +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 09C5010E63F for ; Mon, 5 Sep 2022 15:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391169; 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=bBpUq1hy3OmudET57UjCfPy/DxGWGJDh8xg8FjBV4qo1IGL5JlMnkzELMoOrSd4ad35zXo tXyN6+He9CCjm1gqOU94YWc/yWFtMf9M59NPMMssE8Gbqmz5citsCVAXvkiK/fAkPb4HI8 F4BdrjXZU85A5qVnoAT7IRq0RVzo7PQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-642-4PseKyVpO4On-ufuro0wDQ-1; Mon, 05 Sep 2022 11:19:28 -0400 X-MC-Unique: 4PseKyVpO4On-ufuro0wDQ-1 Received: by mail-wm1-f71.google.com with SMTP id c66-20020a1c3545000000b003a5f6dd6a25so7580528wma.1 for ; Mon, 05 Sep 2022 08:19:28 -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 :subject:date; bh=eULzbfmfnyT2d1MeKBaP6Ap3rVDOs/VsOBler4qqAmU=; b=FMPsknC3wi0mL0oYB4ALuq5uHAo35Pql6pGVRyPE1S+q4mVzdByUK4TQCdIDilhC1O J2CkBG8ZYy5czINqC1qoNxpIHSSFM0l716awq9Q3Wff3+ohpxNRPeHVqP5iS8sY+21qx QOx41xMrZqvPlCJusrhzpwMRl4Y0Ned0b4f6vjae461qczTmZqOKJraXA6rf9THcqi/L m8VjiXj4RoHt3gGsCQSpbaNXnm+iCO2yF3OKIyGobB5NOrDkG+UPYjLhJgcPPKwvv90l NTgkMyWVcG6zkoPVYSmJxc5LicsHY8dfO8Ik04CpcJ3JNOg4XWBgDTrkcWFz5sRpgSQU GuLQ== X-Gm-Message-State: ACgBeo1suxpeW4vcIpkEwH2iqJS9gSoLrBE6WepWkYHN+IOYf1KHkg2w jBSRMhZGH6zg+nV5MtsRqj4jtfcITcQqp3VfmdYgQkrRZznUvTYzD9hqgTSdR4ovvwyexH0kS74 aRe3eb24jIdbbY/gZ5pnxMao+8uFY X-Received: by 2002:a05:600c:290a:b0:3a5:515d:4f69 with SMTP id i10-20020a05600c290a00b003a5515d4f69mr10953083wmd.127.1662391167195; Mon, 05 Sep 2022 08:19:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7xYW3E2/dKGrGQybWNRmjEQXRIlyGBB+beFjcq1u15evJ3hzay5dMZBpfGjmcYbVGnUOV1Pw== X-Received: by 2002:a05:600c:290a:b0:3a5:515d:4f69 with SMTP id i10-20020a05600c290a00b003a5515d4f69mr10953071wmd.127.1662391166968; Mon, 05 Sep 2022 08:19:26 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id t4-20020a05600001c400b00228aea99efcsm2209641wrx.14.2022.09.05.08.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:19:26 -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 RESEND drm-misc-next 4/8] drm/arm/malidp: plane: use drm managed resources Date: Mon, 5 Sep 2022 17:19:06 +0200 Message-Id: <20220905151910.98279-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:19:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966268 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 84A0CECAAD3 for ; Mon, 5 Sep 2022 15:19:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 89DC810E97B; Mon, 5 Sep 2022 15:19:49 +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 3746310E411 for ; Mon, 5 Sep 2022 15:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391170; 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=HO3nd7cUlZP6ZUsxTObt/Vwx/GJzKeaHqRBnoVY7z2P1RFQ1Qr2oLgqgt2wj+WpqWZTJno WsIFWtmaFvs2nkKODUHkD8z6wMOEAYXiNFeYZkbw1h7rDyUxkKZnWEyUWpYtxprWFMCCvz 79D+smlaPnsMGLih9ebAdsiVdMrPS7U= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-616-QFOXWAo-NYuLo6tDgNNveg-1; Mon, 05 Sep 2022 11:19:29 -0400 X-MC-Unique: QFOXWAo-NYuLo6tDgNNveg-1 Received: by mail-wm1-f69.google.com with SMTP id h133-20020a1c218b000000b003a5fa79008bso7568803wmh.5 for ; Mon, 05 Sep 2022 08:19:29 -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 :subject:date; bh=ZNisDhpi4BOnPBk5Q4gtZJ5EEe/qIg6dIjsLwDYtTko=; b=sLWnTkCbagaZhxb1kcdRDJ/FOv3w/C4FSRxmuRJeljrCSu4/Ohqn2v/Os+uKwW/i39 i68gf/1yKjGeMjwck4GWwdeFSzjVY9Cmuu7f9Cs4Lktq+gvMc3m7R2Hy1tBx7b+NKdC3 AksoKivJKckVsfbsiGm1Dm3yUHUAVzRYdSW0WvkhnuFkMsg4XhlyIyH2eGmp59P5OvKT mJWiATlhU2P48KYuEP1nU0ylT3G1JwkZmrbsCx8oA8YP/4faAsE2pi5MbIPDselWRoV+ vQ8oid21tBKxKPEbcRuxSynvTM1sHdZK5/ANOVEY6StNcGT+EseIE2VpP2ykiMEyJLM1 Ei4w== X-Gm-Message-State: ACgBeo1ZEre8Udi7fQsGJE3JiF/tbLU+BjccemSn9fHyA5LL3hmYQqem 99R40daXPV+f1xGC2SwuDi8F6zacFuLcA2I3dCnxK2mWQO6ZM4m+Quqgl7Zpwz+9clyQcLUz7gH BhyM7pXu8onLBqcd/2czAVEH7PsxL X-Received: by 2002:a5d:574a:0:b0:228:b90c:e5ee with SMTP id q10-20020a5d574a000000b00228b90ce5eemr1807460wrw.328.1662391168240; Mon, 05 Sep 2022 08:19:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR6eWxwVNqHxhAwNSWdaScWGMzVC83ybJupld88qShpGqLG4sQlF8ye4ahmYcqUVP9A/HW6EjQ== X-Received: by 2002:a5d:574a:0:b0:228:b90c:e5ee with SMTP id q10-20020a5d574a000000b00228b90ce5eemr1807443wrw.328.1662391168083; Mon, 05 Sep 2022 08:19:28 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id t4-20020a05600001c400b00228aea99efcsm2209641wrx.14.2022.09.05.08.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:19:27 -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 RESEND drm-misc-next 5/8] drm/arm/malidp: use drm_dev_unplug() Date: Mon, 5 Sep 2022 17:19:07 +0200 Message-Id: <20220905151910.98279-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:19: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: 12966269 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 A20C9ECAAD5 for ; Mon, 5 Sep 2022 15:20:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC72210E853; Mon, 5 Sep 2022 15:20:01 +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 6FC6310E8A2 for ; Mon, 5 Sep 2022 15:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391173; 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=ErAfJEEyJtG9xWrjK4QNl1L5ArtjXorxjTN0F/Qns+FnZAsNPvPrmFcliUthi6b2cRtvys v83pbQmuVEZdtBqK1dJI0QMaLfAnJe/Bij2+JgfkOMnReKlo4G6KNQo2CGb2G0HA8tFCdO /1HGsk1SL7L0ZcVqhhbKsOlolDtcrSY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-43-PZ3T3njsPAuFavaAyOTvEg-1; Mon, 05 Sep 2022 11:19:32 -0400 X-MC-Unique: PZ3T3njsPAuFavaAyOTvEg-1 Received: by mail-wm1-f70.google.com with SMTP id f18-20020a05600c4e9200b003a5f81299caso5477003wmq.7 for ; Mon, 05 Sep 2022 08:19:32 -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 :subject:date; bh=xSUtWAzK0ahA+zp/L7/UclMHTS5yPU+3r+RqIP2CU10=; b=i2MLizD3N5QOhWf6czF/1VTNiYwewluMPjZjH6cx6/TfzDyFhU/7Rj+lHdsHmSf5jj Bzcd5RqQrrzk/CzqAavUBIkd0+lgopOpiq3+x3mzamHNXzm2wrLrmzHPsFXjBmGkjz81 urEF7jpfxriyzwJFoq1ghPrND7dTHcA80t9Jh+a1JRwPxNJ+0f0hgmxvWjzk1A5sprfF llTqZ6u8Tm1zMdt12VlH1W9vm0vDShzzp/TZDxpiIE4BLUZ2svC3Sq//YGg1PhCNI1Mq d7+/uZ8W9fXdbUuUIrMExiqUpoNx5vbE5SC3dZgNeJkM4y7oDcY8Jxe7KA/1Uad2zHyU A9Rg== X-Gm-Message-State: ACgBeo2EGDsF4a0eBmtF0oCATe/X79sXKNmf68qYCOyP8uQddDgnzOQ5 XUfDsGwTOiWl6WbkMWtWb3Y/sZvssCphdVOoDeQzJJG/NzrD7EnZkLp2B1vp1CCWnXqNH263a5G qAOfXuSJ+AOCPig0qMphZWXVNhTgR X-Received: by 2002:a5d:48c7:0:b0:228:62d5:2818 with SMTP id p7-20020a5d48c7000000b0022862d52818mr5341886wrs.13.1662391171542; Mon, 05 Sep 2022 08:19:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KG28G6zxF6nBeebEbFNRpsDbrJRMcxpQj5CeuggUPfErxOJ+G3x3zAgSIgPxcSWg6+XzDqQ== X-Received: by 2002:a5d:48c7:0:b0:228:62d5:2818 with SMTP id p7-20020a5d48c7000000b0022862d52818mr5341871wrs.13.1662391171390; Mon, 05 Sep 2022 08:19:31 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id j18-20020a5d4532000000b00220592005edsm9227024wra.85.2022.09.05.08.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:19:31 -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 RESEND drm-misc-next 6/8] drm/arm/malidp: plane: protect device resources after removal Date: Mon, 5 Sep 2022 17:19:08 +0200 Message-Id: <20220905151910.98279-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:20: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: 12966270 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 05862ECAAD3 for ; Mon, 5 Sep 2022 15:20:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0EE7C10E426; Mon, 5 Sep 2022 15:20:51 +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 DC2B110E41B for ; Mon, 5 Sep 2022 15:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391246; 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=Ym93OtH0ZaS4MDfuCQyYLeoLZhdqZ2BIofZ+hGpE3VJPU83rzlIRAX6K1WJkfq6iEFpCr9 iFRkKrr1/ZJ6F606twssKVv5MJEgRZYBXdg5FYoSnoH5SNW0ISw2hcjkFOd86CAs9Zr0T4 GoiaC2Sn2NDc7WzWgPF32mrifppxYK8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-198-F1LbeZZNN2GsBlfA-CDeAw-1; Mon, 05 Sep 2022 11:20:45 -0400 X-MC-Unique: F1LbeZZNN2GsBlfA-CDeAw-1 Received: by mail-wr1-f70.google.com with SMTP id s1-20020adf9781000000b002286cd81376so716627wrb.22 for ; Mon, 05 Sep 2022 08:20:44 -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 :subject:date; bh=9kBxkoMSoocenFWS5QnFTVJk53upsFpOoCTaLoDSzmI=; b=Qae+JVkMjp6Jwe5j3CXvoc1YQRCdpGqzXJR2dZ+d8NlWzyKABGA/V879V6nBjwyf3e ZWWaS9+eVKNzIOPTECMVB8A2unIgePk9TNfDbxudgKOHWDNM98RxQHLCFn+jkPSR2nIA eyJTOLG0G4a04686lpWS7LXspG1bvNtwEzhHBcKbTx2qcb5+blGPm/JbedHmhbTuzbHp 5bvUS6rhJLnnsihVNotw2p+Re9hrRfm20QknWooLJxjd0lBG8XtwpjT3s2N4rtP0u6FE Hd8qAU5XxTLqXQus75OqQtdZ2bI6XInaUqSyGgR6tVi6PllBTBoLUeZX4uWI+usIyXRt zUHg== X-Gm-Message-State: ACgBeo2xCLa4CVb/Qf1ITvJ89asUCSzTB7iipxpBjufAN+P6l8Ojoipl zudqZoIElwOJ7xEIJ7i0OtqKMfzXKrm/7DJ4/08REcuw22aXPUO/wKlke8fE478qa/8IgmrTad5 Tlq/HQtojCgzdKsWVRNd0pgAat840 X-Received: by 2002:a05:6000:118e:b0:228:9373:70ae with SMTP id g14-20020a056000118e00b00228937370aemr2737616wrx.467.1662391243882; Mon, 05 Sep 2022 08:20:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR57AZWTw36W89LbLt9c7lRycXE7G5TIWvzY7JI3W+d7SJ+dvNHGroLtZktX1idf6HX851gcKw== X-Received: by 2002:a05:6000:118e:b0:228:9373:70ae with SMTP id g14-20020a056000118e00b00228937370aemr2737601wrx.467.1662391243671; Mon, 05 Sep 2022 08:20:43 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id m5-20020adff385000000b00228c792aaaasm1383446wro.100.2022.09.05.08.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:20: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 RESEND drm-misc-next 7/8] drm/arm/malidp: crtc: protect device resources after removal Date: Mon, 5 Sep 2022 17:20:40 +0200 Message-Id: <20220905152041.98451-1-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 Mon Sep 5 15:20: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: 12966271 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 3C2ABECAAD5 for ; Mon, 5 Sep 2022 15:20:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4A61510EA22; Mon, 5 Sep 2022 15:20:52 +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 9EC8110E41B for ; Mon, 5 Sep 2022 15:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391246; 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=MGnZiADzzYFrKi2uPVMv5v6QgkAHDMj0sIUw/JjijoJQ5zFm9g5jM91IxUrAfx1tgdi4KU vusnRUsZ1XKpDzuW7tsAdqcfL9FJMPmF8VX7jdEU7EXTSYESkwkdGguVoBQcSCzoIe579F DwcMv+lH5fCFEiTqp57tafgvUM+UBVQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-607-1oemnaw1MsGR-TFc7CF9hA-1; Mon, 05 Sep 2022 11:20:45 -0400 X-MC-Unique: 1oemnaw1MsGR-TFc7CF9hA-1 Received: by mail-wm1-f72.google.com with SMTP id c64-20020a1c3543000000b003a61987ffb3so5481783wma.6 for ; Mon, 05 Sep 2022 08:20: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 :subject:date; bh=hPqOotGSruHudwMIkA2GhgTM0KbwtUxu9NgLFadghJM=; b=wqc96pRT/kg1owyEGN8w/3o8CAGxpWmIu9zqsB4F53XNT1lsOZul0JoP10wqm1DBRA Pc4meMmjj944Xv9F7s+sAufabqlEPeNdigNuUqPrtpxE7zvzOZkEV0GBwtz3/hI7n5ed RhCu8XqRLM/+ENHoW94WkUIV4SwHJbVbOJRHTBQdYUD+Y/OowljXwIcvi+lSTVng99nd hKAtcMWmk2pm4Aj/sl1ko19FvsTWDWTSNXkw656/2bDceg3j0elC2CANaBe1v6YQH59f QS7MSF2fAlnPh8CCxEddccfYSAXmPc9En5sMM6E8BTm3ozO7SdxJelKJ4KXyWXFX4JM8 n/+g== X-Gm-Message-State: ACgBeo0GTNYKBBaDdecOIk67TpNa3xeoRabZjhNCXrrLFbt7yk6OLAa6 3YRS7uwEgZzPs/HKf4rN7X66+X5E0/+LOw5Y59fza+Aym+GuW7h6uHtL34sqCXyy9hLkiiemurH xozM5REiEO9QWY+yJuwxvJILzjiwA X-Received: by 2002:a05:600c:1c0f:b0:3a5:4d6b:a883 with SMTP id j15-20020a05600c1c0f00b003a54d6ba883mr11252458wms.45.1662391244721; Mon, 05 Sep 2022 08:20:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7nVSVriafKyRymiV7fyQtuEeLvMSSb3JbyLOA78o+7ULCvGCL0DCvbENDPzt7s804RJJ3wAg== X-Received: by 2002:a05:600c:1c0f:b0:3a5:4d6b:a883 with SMTP id j15-20020a05600c1c0f00b003a54d6ba883mr11252445wms.45.1662391244580; Mon, 05 Sep 2022 08:20:44 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id m5-20020adff385000000b00228c792aaaasm1383446wro.100.2022.09.05.08.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:20:44 -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 RESEND drm-misc-next 8/8] drm/arm/malidp: drv: protect device resources after removal Date: Mon, 5 Sep 2022 17:20:41 +0200 Message-Id: <20220905152041.98451-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905151910.98279-1-dakr@redhat.com> References: <20220905151910.98279-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 = {