From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93DF5C32773 for ; Fri, 19 Aug 2022 21:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352235AbiHSVUn (ORCPT ); Fri, 19 Aug 2022 17:20:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352423AbiHSVUZ (ORCPT ); Fri, 19 Aug 2022 17:20:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C36C9104454 for ; Fri, 19 Aug 2022 14:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944022; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=69RvVGMWC6PWcztw+ehBzvKOoAq86yIaOh4KmWH1rn8=; b=TMuOF4XlXWqPB4mKpztfrLnlsMoGOoRC7cdxanDLErbyBLOYRyNc28HdSyyWMCI1JvCX3f +Y70wZLgUfvi/iouh4wEWaWWebt++PXTQ4Dv6WVRrpluGCRBUyAIMG+rl+zY5c19fT9e00 fRtD5C7DXTQmt8G2nc5YQaq6udV9WGc= 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-632-gusxv841PEO29FuaEP8B-Q-1; Fri, 19 Aug 2022 17:20:20 -0400 X-MC-Unique: gusxv841PEO29FuaEP8B-Q-1 Received: by mail-ej1-f69.google.com with SMTP id hr32-20020a1709073fa000b00730a39f36ddso1897939ejc.5 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=UbxcYHxIhcUi4FhZxJSc0DalAjV2ETcL5TJzMjtBucD19jW65Q/RoBYGZoTg/YWEEp B2ERKyeEohZp0Arv1SbtwB5jrgw2C/SDkzoK3uAIb79qJ7N+LyS7bgRsbquHsstS2ilu 7D4ScvcPwi1LBv7FPMgNOoYokIt0p6B7BqI0n7Li9pidBOUpS8UK+gvns+Ioni++9FX0 0JdKdVv33B0Yhj+9ul/XwIBfgBCgGpLoufbFCHBgcRIiUMlzlY3n0uQnYFKcIFqjdhFo Cjn7HJ5qut4ShxYISdJBqUACECVGTt5Jp1DASB+yAMcNPa/+28/yaCNy2Gj7q6b6BrBO Oybw== X-Gm-Message-State: ACgBeo0+YTWJnqXPCho5/7BgfPXzF/bdUB+jzWnrYbQNj+loBm+PGyWi WXoKLQuKgVjuVo1rLahrdyNEo0ahtZJKjf423VIJOC4t7luetSgtIqAnR0h+3zuIC/RovnVjSVe RzDcMV8I5HIrWTXlw2/4MDZRP X-Received: by 2002:a05:6402:1d4e:b0:43d:9822:b4d1 with SMTP id dz14-20020a0564021d4e00b0043d9822b4d1mr7554030edb.212.1660944019757; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D 0, i; u32 version, out_depth =3D 0; =20 - malidp =3D devm_kzalloc(dev, sizeof(*malidp), GFP_KERNEL); - if (!malidp) - return -ENOMEM; + malidp =3D devm_drm_dev_alloc(dev, &malidp_driver, typeof(*malidp), base); + if (IS_ERR(malidp)) + return PTR_ERR(malidp); + + drm =3D &malidp->base; =20 - hwdev =3D devm_kzalloc(dev, sizeof(*hwdev), GFP_KERNEL); + hwdev =3D drmm_kzalloc(drm, sizeof(*hwdev), GFP_KERNEL); if (!hwdev) return -ENOMEM; =20 @@ -753,12 +756,6 @@ static int malidp_bind(struct device *dev) if (ret && ret !=3D -ENODEV) return ret; =20 - drm =3D drm_dev_alloc(&malidp_driver, dev); - if (IS_ERR(drm)) { - ret =3D PTR_ERR(drm); - goto alloc_fail; - } - drm->dev_private =3D malidp; dev_set_drvdata(dev, drm); =20 @@ -887,8 +884,6 @@ static int malidp_bind(struct device *dev) malidp_runtime_pm_suspend(dev); drm->dev_private =3D NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); -alloc_fail: of_reserved_mem_device_release(dev); =20 return ret; @@ -917,7 +912,6 @@ static void malidp_unbind(struct device *dev) malidp_runtime_pm_suspend(dev); drm->dev_private =3D NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); of_reserved_mem_device_release(dev); } =20 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 { }; =20 struct malidp_drm { + struct drm_device base; struct malidp_hw_device *dev; struct drm_crtc crtc; struct drm_writeback_connector mw_connector; --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76923C32771 for ; Fri, 19 Aug 2022 21:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352273AbiHSVUr (ORCPT ); Fri, 19 Aug 2022 17:20:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352455AbiHSVU2 (ORCPT ); Fri, 19 Aug 2022 17:20:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD29104748 for ; Fri, 19 Aug 2022 14:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Ijy3Q7tFZuVJZh+APF9uvbAJEvF3VUDq7eKTxt/Smo=; b=XRKQSGgH5e62x1DGWWxsWzzXRlBFxXeMR01ajrqaXg7EIoRFJ5/up9VLbjGgJQQenEg9m+ jiRLVXial6iAw7FNIIr/Fb8MM6aLv3GPMa9ieU47h3QrCe0N450R1UFlkpt7mMj4FXisIF Hkd0aZD7RwSw30OiG8vxviD4D06SHGE= 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-617-7ywnwAO1PUi6i0_1oQGuIw-1; Fri, 19 Aug 2022 17:20:23 -0400 X-MC-Unique: 7ywnwAO1PUi6i0_1oQGuIw-1 Received: by mail-ej1-f70.google.com with SMTP id sa33-20020a1709076d2100b0073101bdd612so1911410ejc.14 for ; Fri, 19 Aug 2022 14:20:23 -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=3zV/0iD7dYs77BVIS+q8BTcfZSBP52MfQ+JnkMC+3TtM9/EpB26Bd89KxOfeykJQ18 C1wA9L68BGUxEtYSONOYfz9EfPb5icJVVah94cG55WsM+aLZyKCMnhjnhyKjpBKoNx9X rzKSaYe1dmSTE3wdjK1ASEsB848PMo9ygipU2dUl5KYgK6FJXtflQxwxtcXNQwUuKXtE rFiXPahzhxXTJ4f7T1ckII5w9kr6pbwnKh1BFCYwsBMUAd9mcSO6l6YSgtVAAmGR6+ZR PP2WPo3ymlSTAGGE87YWVAyOUVHpPniFzdPSSZWh5YAYEJAv+/iIOKxpOoypNnWsNO6B TBdA== X-Gm-Message-State: ACgBeo2YLu1CEG0QixkoEbLaYSgyYZC2vEDoIXszeiUOJRKNQjdhn35Z aKBVonc2xd+pl/QFLdwmRND/G5ku9ZRj3pNpPoXN49hUr/25D1NLBWN5RuUHyHYMocftY95jULF Ecd4ajzQX5oWgbSTNT0WP7Lur X-Received: by 2002:a17:907:87b0:b0:738:e618:99ca with SMTP id qv48-20020a17090787b000b00738e61899camr5989900ejc.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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 = =3D { =20 int malidp_crtc_init(struct drm_device *drm) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct drm_plane *primary =3D NULL, *plane; int ret; =20 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_c= rtc *crtc, */ static int malidp_set_and_wait_config_valid(struct drm_device *drm) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; int ret; =20 @@ -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 =3D state->dev; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); int loop =3D 5; =20 malidp->event =3D malidp->crtc.state->event; @@ -231,7 +231,7 @@ static void malidp_atomic_commit_hw_done(struct drm_ato= mic_state *state) static void malidp_atomic_commit_tail(struct drm_atomic_state *state) { struct drm_device *drm =3D state->dev; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D 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_c= onfig_funcs =3D { static int malidp_init(struct drm_device *drm) { int ret; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 drm_mode_config_init(drm); @@ -429,7 +429,7 @@ static int malidp_irq_init(struct platform_device *pdev) { int irq_de, irq_se, ret =3D 0; struct drm_device *drm =3D dev_get_drvdata(&pdev->dev); - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 /* fetch the interrupts from DT */ @@ -463,7 +463,7 @@ static int malidp_dumb_create(struct drm_file *file_pri= v, struct drm_device *drm, struct drm_mode_create_dumb *args) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); /* allocate for the worst case scenario, i.e. rotated buffers */ u8 alignment =3D malidp_hw_get_pitch_align(malidp->dev, 1); =20 @@ -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 =3D m->private; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); unsigned long irqflags; struct malidp_error_stats de_errors, se_errors; =20 @@ -532,7 +532,7 @@ static ssize_t malidp_debugfs_write(struct file *file, = const char __user *ubuf, { struct seq_file *m =3D file->private_data; struct drm_device *drm =3D m->private; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); unsigned long irqflags; =20 spin_lock_irqsave(&malidp->errors_lock, irqflags); @@ -553,7 +553,7 @@ static const struct file_operations malidp_debugfs_fops= =3D { =20 static void malidp_debugfs_init(struct drm_minor *minor) { - struct malidp_drm *malidp =3D minor->dev->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(minor->dev); =20 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 =3D dev_get_drvdata(dev); - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); =20 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 =3D dev_get_drvdata(dev); - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 /* 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 =3D dev_get_drvdata(dev); - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 clk_prepare_enable(hwdev->pclk); @@ -756,7 +756,6 @@ static int malidp_bind(struct device *dev) if (ret && ret !=3D -ENODEV) return ret; =20 - drm->dev_private =3D malidp; dev_set_drvdata(dev, drm); =20 /* 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 =3D NULL; dev_set_drvdata(dev, NULL); of_reserved_mem_device_release(dev); =20 @@ -892,7 +890,7 @@ static int malidp_bind(struct device *dev) static void malidp_unbind(struct device *dev) { struct drm_device *drm =3D dev_get_drvdata(dev); - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 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 =3D 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 }; =20 +#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) =20 struct malidp_plane { diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_h= w.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_devi= ce *hwdev, u8 block, u32 ir static irqreturn_t malidp_de_irq(int irq, void *arg) { struct drm_device *drm =3D arg; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D 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 =3D arg; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); =20 wake_up(&malidp->wq); =20 @@ -1252,7 +1252,7 @@ void malidp_de_irq_hw_init(struct malidp_hw_device *h= wdev) =20 int malidp_de_irq_init(struct drm_device *drm, int irq) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; int ret; =20 @@ -1286,7 +1286,7 @@ void malidp_de_irq_fini(struct malidp_hw_device *hwde= v) static irqreturn_t malidp_se_irq(int irq, void *arg) { struct drm_device *drm =3D arg; - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; struct malidp_hw *hw =3D hwdev->hw; const struct malidp_irq_map *se =3D &hw->map.se_irq_map; @@ -1363,7 +1363,7 @@ static irqreturn_t malidp_se_irq_thread_handler(int i= rq, void *arg) =20 int malidp_se_irq_init(struct drm_device *drm, int irq) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; int ret; =20 diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_m= w.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 *enco= der, struct drm_connector_state *conn_state) { struct malidp_mw_connector_state *mw_state =3D to_mw_state(conn_state); - struct malidp_drm *malidp =3D encoder->dev->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(encoder->dev); struct drm_framebuffer *fb; int i, n_planes; =20 @@ -207,7 +207,7 @@ static u32 *get_writeback_formats(struct malidp_drm *ma= lidp, int *n_formats) =20 int malidp_mw_connector_init(struct drm_device *drm) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); u32 *formats; int ret, n_formats; =20 @@ -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 =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); struct drm_writeback_connector *mw_conn =3D &malidp->mw_connector; struct drm_connector_state *conn_state =3D mw_conn->base.state; struct malidp_hw_device *hwdev =3D malidp->dev; diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/mali= dp_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 =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); const struct malidp_hw_regmap *map =3D &malidp->dev->hw->map; =20 if (WARN_ON(modifier =3D=3D DRM_FORMAT_MOD_INVALID)) @@ -931,7 +931,7 @@ static const uint64_t linear_only_modifiers[] =3D { =20 int malidp_de_planes_init(struct drm_device *drm) { - struct malidp_drm *malidp =3D drm->dev_private; + struct malidp_drm *malidp =3D drm_to_malidp(drm); const struct malidp_hw_regmap *map =3D &malidp->dev->hw->map; struct malidp_plane *plane =3D NULL; enum drm_plane_type plane_type; --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B265FC32771 for ; Fri, 19 Aug 2022 21:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352477AbiHSVZA (ORCPT ); Fri, 19 Aug 2022 17:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352444AbiHSVYx (ORCPT ); Fri, 19 Aug 2022 17:24:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5FE0D2E8E for ; Fri, 19 Aug 2022 14:24:52 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qabemuj06WeoMtZf9HrAveZ66zZ44DWBaH/ByyW71MM=; b=T9dzB60bVFvUBnKxcBQZaFD5HOPpwslEQE4cS+fSmrnoUhM9O1zKHIqzRt8kHKGJ6pHH55 ngMl3D/vg3vPSN7MMDzihflmQISjlHNgdZyGGygvhIFL/8v8x11QGnXjnp2QnJ6Oi/8/5G XoFL0+pgk3JzdiuTBqVZB9Hvw0SkxXc= 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-586-bBFjS5fDPNunh1vOWumKiQ-1; Fri, 19 Aug 2022 17:24:49 -0400 X-MC-Unique: bBFjS5fDPNunh1vOWumKiQ-1 Received: by mail-ed1-f72.google.com with SMTP id o2-20020a056402438200b0043d552deb2aso3340891edc.0 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=OdzZGdLaX0Uar1uC0FCyQNDiW21QmHx1RvqDwuDBXIjEIl9ng7ekhM97lc8pYiYVZk 8Ia8imwjzU6/TxjKC2CEWr/f+B01oEN+0m+9RXPQHx/nKgvkX0KfRkjLWcL/hCT/A17Y Eh4/gKyVduKIvy2kqPMI9Sa43WWfLJ2uMwi3tg/1KccMwBPQ2bgG/77YJtSI08L9oXA9 YXyByDW3QZaahv9418rAREla1yNV9X7H+JA4nIHqRY5sPvBdts+RsdypwUZtP0dWMKQ+ JkVRpa5/gXhOmGuJL+8+30MsxtLa+wG9v5Mf82+adC+N0+zhh7Hftp+lY7t31Bq77nf1 U13Q== X-Gm-Message-State: ACgBeo3/WJjBZDcsfP2hIfyjQjN6OOCppdFtv1VLytLlvsgcrvT+l7un jQSAX0hLVM+nQb4Gy3EQsvIFh1ptR7hj4cipDlApqWLOahOj+XVvQLZq7DT96WTmJ4hcGtozCJq rT45uvJPNti5324O4J4kZ9sEE X-Received: by 2002:a17:907:72d1:b0:730:a0c4:2aaa with SMTP id du17-20020a17090772d100b00730a0c42aaamr5757438ejc.560.1660944288436; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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) } =20 static const struct drm_crtc_funcs malidp_crtc_funcs =3D { - .destroy =3D drm_crtc_cleanup, .set_config =3D drm_atomic_helper_set_config, .page_flip =3D drm_atomic_helper_page_flip, .reset =3D malidp_crtc_reset, @@ -548,8 +547,8 @@ int malidp_crtc_init(struct drm_device *drm) return -EINVAL; } =20 - ret =3D drm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, - &malidp_crtc_funcs, NULL); + ret =3D drmm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, + &malidp_crtc_funcs, NULL); if (ret) return ret; =20 --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3488C32772 for ; Fri, 19 Aug 2022 21:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352458AbiHSVY4 (ORCPT ); Fri, 19 Aug 2022 17:24:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352445AbiHSVYx (ORCPT ); Fri, 19 Aug 2022 17:24:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD86BD2B3B for ; Fri, 19 Aug 2022 14:24:52 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eULzbfmfnyT2d1MeKBaP6Ap3rVDOs/VsOBler4qqAmU=; b=SrosXC7gQuq3jQccXZYmw5CGQqeeKr7DDjj3jU9e7lzO8vL7IinQ3Sb+t4r3wVss+AK1F4 hU7ZMJfSvrjdn7hcHtBfd1AibroQphGaQHlVqOx0MhsfWQl3aUsJrRphFhnOQr5BzQs+PO oByqL77dKAVLwAt6jO2JopXAPQymC0A= 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-61-w0MmXmGlMECu_gZHGRHUiw-1; Fri, 19 Aug 2022 17:24:50 -0400 X-MC-Unique: w0MmXmGlMECu_gZHGRHUiw-1 Received: by mail-ej1-f70.google.com with SMTP id hs4-20020a1709073e8400b0073d66965277so9618ejc.6 for ; Fri, 19 Aug 2022 14:24:50 -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=ZBDDhc1mVZBEtL9ZO7GDAxkfG5nOQL0NerPas6kizeica6DBQ/DKV2YDmoAq7yrRgA NFfQtVCBhheVV0VIiB6sEsrsNrVMWxuENC3MWl20gm1lduJ33FMXhDA8gORtbloJdsGi KEPRz/2jFUpKkSCRN+uVYfAoWQ9RrFxIkaKqjz3JUezrT5CkuI1J5sehrKTiZd523Uzn 7+dv3TmQO9UPqWE1JeJH1+iwgwTm9bqYhf5QiU4Ml4R/drvLkHdpSoQ0yM8O5/+dwwAO CHbvpM7l+5ww6YKJ+xXdIYL8GZgY1z719hNzkePWicWSsC0fkPtNKIDQoFnEWDqmOvmO U3IA== X-Gm-Message-State: ACgBeo30I5yV4bVoknWeCKgxaiXzbrIeDb+xYg9/uNgFDCGRnM5xM7/J FEJTs+5fIOSBMMi7gVFUk0e3UgkSPpV/RZTmS0wfr53S+hQQP7/jdITiJwXbrlT/4LB6r11eD9V nM8ueYvYNZgT8WndJGcwyvBb6 X-Received: by 2002:a17:907:2724:b0:730:da23:5b60 with SMTP id d4-20020a170907272400b00730da235b60mr5944566ejl.43.1660944289773; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/mali= dp_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 =20 -static void malidp_de_plane_destroy(struct drm_plane *plane) -{ - struct malidp_plane *mp =3D 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(struc= t drm_plane *plane, static const struct drm_plane_funcs malidp_de_plane_funcs =3D { .update_plane =3D drm_atomic_helper_update_plane, .disable_plane =3D drm_atomic_helper_disable_plane, - .destroy =3D malidp_de_plane_destroy, .reset =3D malidp_plane_reset, .atomic_duplicate_state =3D malidp_duplicate_plane_state, .atomic_destroy_state =3D malidp_destroy_plane_state, @@ -972,12 +963,6 @@ int malidp_de_planes_init(struct drm_device *drm) for (i =3D 0; i < map->n_layers; i++) { u8 id =3D map->layers[i].id; =20 - plane =3D kzalloc(sizeof(*plane), GFP_KERNEL); - if (!plane) { - ret =3D -ENOMEM; - goto cleanup; - } - /* build the list of DRM supported formats based on the map */ for (n =3D 0, j =3D 0; j < map->n_pixel_formats; j++) { if ((map->pixel_formats[j].layer & id) =3D=3D id) @@ -990,13 +975,14 @@ int malidp_de_planes_init(struct drm_device *drm) /* * All the layers except smart layer supports AFBC modifiers. */ - ret =3D drm_universal_plane_init(drm, &plane->base, crtcs, - &malidp_de_plane_funcs, formats, n, - (id =3D=3D DE_SMART) ? linear_only_modifiers : modifiers, - plane_type, NULL); - - if (ret < 0) + plane =3D drmm_universal_plane_alloc(drm, struct malidp_plane, base, + crtcs, &malidp_de_plane_funcs, formats, n, + (id =3D=3D DE_SMART) ? linear_only_modifiers : + modifiers, plane_type, NULL); + if (IS_ERR(plane)) { + ret =3D PTR_ERR(plane); goto cleanup; + } =20 drm_plane_helper_add(&plane->base, &malidp_de_plane_helper_funcs); --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1F71C32771 for ; Fri, 19 Aug 2022 21:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352478AbiHSVZG (ORCPT ); Fri, 19 Aug 2022 17:25:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352452AbiHSVY4 (ORCPT ); Fri, 19 Aug 2022 17:24:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F918E2C67 for ; Fri, 19 Aug 2022 14:24:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZNisDhpi4BOnPBk5Q4gtZJ5EEe/qIg6dIjsLwDYtTko=; b=VUjI9ajBhinWVDcJ4FDZfm3la+NYyQZdypNEIdpNp8xaaFviHV08kKUUhSZ8qo92JGWSNN nFMp6sKACIsYgi1w2UUc5oTfYplC0EcRK7h44J+ppCzih57XXpGKhg1oeXr7mUv6CSObKM +cXg4H4X3/d6v7tdPNkKtNRSsPy98q0= 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-193-L087EfdmNSKkIVX_zNaOpw-1; Fri, 19 Aug 2022 17:24:52 -0400 X-MC-Unique: L087EfdmNSKkIVX_zNaOpw-1 Received: by mail-ej1-f72.google.com with SMTP id qk37-20020a1709077fa500b00730c2d975a0so1908042ejc.13 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=Fp02hnGRseZ478mMiVGEIu9+Mp16IBp6Nrr3lMByrKjZmKHpcm/JffPn7f34Q7rKQm +N+rsiLZS51Y8mg7vGIjJIdBmPG5eqwQ7ue/cET1ONGpZmTlZy9Y+DLPaHJ21Y85+SS7 ePFyTvov/+7hBFlS/51zP7QmKMIlQh6WZCRYiInjGF6ZsiNj2rEDtGeyjzOiFd3hZBnm x01pubGDIA0CglIKHMLtgXa4RP9C1deUcNfdhEFxB9EJ2M6BOJVQksCCs3bJFW5t+JkO tnxI7v8d8erCssRtvoCIo4N3Quv46SiKpEeRm0arc8tjNgvxztKvTOVwT9nOcBiZq1Le c1Ww== X-Gm-Message-State: ACgBeo0KTsUZ7wzgsjxnyA4AMtjf4lk25mwyT8IwXfHVVB+dn/NwbgLR UuUX06IYmQ/+RncNE+4I6+03w//oxW78Yv4dyhpAkpVRDwlMHwOqx17yXdB62Tejky8wAKlStXN n8942i+tN5ZHyU4gmDVAkeb/H X-Received: by 2002:a05:6402:c45:b0:442:c549:8e6b with SMTP id cs5-20020a0564020c4500b00442c5498e6bmr7454923edb.123.1660944291636; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 - drm_dev_unregister(drm); + drm_dev_unplug(drm); drm_kms_helper_poll_fini(drm); pm_runtime_get_sync(dev); drm_atomic_helper_shutdown(drm); --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCE97C32773 for ; Fri, 19 Aug 2022 21:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352514AbiHSVZM (ORCPT ); Fri, 19 Aug 2022 17:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352472AbiHSVY6 (ORCPT ); Fri, 19 Aug 2022 17:24:58 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE0FE97E4 for ; Fri, 19 Aug 2022 14:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660944296; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xSUtWAzK0ahA+zp/L7/UclMHTS5yPU+3r+RqIP2CU10=; b=IuKXgDWG3hDFsxzgrgkI+ypdX9aJ2S/a4v6wg4Lh+P0D8ZA8j+NaOJs4/qPw5kaOnx6YRx piIoV/Gqv+pJMVYt2WB40cGf+Ts05L2GaFChVVnIuPWM+lyvWkpjhIUtwQivS2gXao+HSf Z4UIRVy3xWLB8cpE4D4U1DdqC66ERRU= 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-145-IymWYWntOhiZUO8xK9caNQ-1; Fri, 19 Aug 2022 17:24:54 -0400 X-MC-Unique: IymWYWntOhiZUO8xK9caNQ-1 Received: by mail-ed1-f72.google.com with SMTP id b6-20020a056402278600b0043e686058feso3347590ede.10 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=oO0QzOrh/N/pS1jEANevYkFA8Iu3lpsF/gZ7i33IgpV8FMk899yziv5KcXna4QMMG/ LeNkleEt+irNWB2ofTCIGnVJ7MDcPHj44JI2h4ZHEAPcqmLw4jhTsnHnIAK57r4EtJhv cAoGoJZT2wCKpTF8l20DOpzGRh+mTwxnxXn1g8g0bM8y1wGvjwNfAB6QpBRrrJ+bSbwy 64b7wE1ozafE+xLQD00FjldoFNNVXkCquFrrm7G5KZztsoqEIO+LMN1zsNyanFyfpxB1 zgF4TOzEtIGV2hbKtxSlQdBEew0l88S6sxVJHI50AgTtf1kME3bOnqRhqTOotvysSIOH zvLg== X-Gm-Message-State: ACgBeo3ZdsoVXDIshA29KTc1OgPyDIZx8p/vgzNiQ6PqvB5jm8HHqlp5 CLlXJSOyJ5DA5g2/CRx6VAN+qrkgTpsCKoQf5hcuBpJLn+a6pxrE+RucxuvUlzCmBzGGX7hT7FG F3+1NWuAHyU9PqT55EV4ON1DS X-Received: by 2002:a17:907:2c64:b0:730:defe:a419 with SMTP id ib4-20020a1709072c6400b00730defea419mr5801923ejc.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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" (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/mali= dp_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 *p= lane, u16 pixel_alpha =3D new_state->pixel_blend_mode; u8 plane_alpha =3D new_state->alpha >> 8; u32 src_w, src_h, dest_w, dest_h, val; - int i; + int i, idx; struct drm_framebuffer *fb =3D plane->state->fb; =20 + if (!drm_dev_enter(plane->dev, &idx)) + return; + mp =3D to_malidp_plane(plane); =20 /* @@ -897,16 +900,24 @@ static void malidp_de_plane_update(struct drm_plane *= plane, =20 malidp_hw_write(mp->hwdev, val, mp->layer->base + MALIDP_LAYER_CONTROL); + + drm_dev_exit(idx); } =20 static void malidp_de_plane_disable(struct drm_plane *plane, struct drm_atomic_state *state) { struct malidp_plane *mp =3D to_malidp_plane(plane); + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; =20 malidp_hw_clearbits(mp->hwdev, LAYER_ENABLE | LAYER_FLOWCFG(LAYER_FLOWCFG_MASK), mp->layer->base + MALIDP_LAYER_CONTROL); + + drm_dev_exit(idx); } =20 static const struct drm_plane_helper_funcs malidp_de_plane_helper_funcs = =3D { --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1BC9C32771 for ; Fri, 19 Aug 2022 21:25:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352492AbiHSVZ5 (ORCPT ); Fri, 19 Aug 2022 17:25:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352501AbiHSVZr (ORCPT ); Fri, 19 Aug 2022 17:25:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53BE310775A for ; Fri, 19 Aug 2022 14:25:46 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9kBxkoMSoocenFWS5QnFTVJk53upsFpOoCTaLoDSzmI=; b=Lk0sXJRa8oaslcqH/PnAG3SfitapT6lDxp2BR7kVyT7J9tqmihQZmq9ArypAsD9NbF540r Pzpinsyl1XkR+w3aCUNzGCayrO9lkHHcWGej6pjI+fu8vDTS5tRuvLCY3e/+QrVDnuDi2R PY3kYl1SUI0SPi5yA6Huh6hVf8H7fw0= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-306-vVR-UmmiP0yQiv5tJSuosQ-1; Fri, 19 Aug 2022 17:25:44 -0400 X-MC-Unique: vVR-UmmiP0yQiv5tJSuosQ-1 Received: by mail-ej1-f71.google.com with SMTP id js11-20020a17090797cb00b00730d73eac83so1910234ejc.19 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=LhjfTqWg0L7t0OBr9ozdT3bgViiqGa1ukwd1ovv2vLeMky1tMV7aRHqW6yOAVjGn4H 8J9wfq6RAxvh3PEgDKLC1tiZ2NdD5F0sS9gN2JvNAJsNnco6vfNnyRd81E0OGZ2HL60w GwCUxZJSylJP1nsGMfLGuHYjw0JMnEeOeyO9CsXQA6CViricLWxuLSaA/uLyNaj746pJ 9OOMXfyjChnaJowGNLz6IkhvWZd/JSZ7ZQjGcUjxJWaLrR28Z1SZ0YCvYmtBhJ/zAs2e TDR5M94AJjq1cF6pQrndSTS3Qa4GfKqQu5XTwlNlY+ecNaUK92vAFwz122mNyOvynhH4 OrSw== X-Gm-Message-State: ACgBeo2TOmf5D42MYp+Z6DFasgljaq1gt3WTX2N9QntXoIMRCxmGvGrH CuLM/lTTAGyp3a1D6J6et+bxVpM6rz/2e0h7awmNcM9JRS/QpT9vxQ4S939/CzMM8q2GlL0B28z I1HxNFmwiwOlz8NH6PmPqEf6O X-Received: by 2002:a05:6402:50cc:b0:43e:6860:58fc with SMTP id h12-20020a05640250cc00b0043e686058fcmr7476994edb.243.1660944342982; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" (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 =3D crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev =3D malidp->dev; + int idx; =20 /* * 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 =3D mode->crtc_clock * 1000; =20 + if (!drm_dev_enter(&malidp->base, &idx)) + return MODE_NOCLOCK; + if (req_rate) { rate =3D clk_round_rate(hwdev->pxlclk, req_rate); if (rate !=3D req_rate) { @@ -43,6 +48,8 @@ static enum drm_mode_status malidp_crtc_mode_valid(struct= drm_crtc *crtc, } } =20 + drm_dev_exit(idx); + return MODE_OK; } =20 @@ -53,6 +60,10 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *c= rtc, struct malidp_hw_device *hwdev =3D malidp->dev; struct videomode vm; int err =3D pm_runtime_get_sync(crtc->dev->dev); + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; =20 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 *cr= tc, hwdev->hw->modeset(hwdev, &vm); hwdev->hw->leave_config_mode(hwdev); drm_crtc_vblank_on(crtc); + + drm_dev_exit(idx); } =20 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 =3D crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev =3D malidp->dev; - int err; + int err, idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; =20 /* 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); } =20 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 =3D 0; /* U16.16 */ u32 v_upscale_factor =3D 0; /* U16.16 */ u8 scaling =3D cs->scaled_planes_mask; - int ret; + int idx, ret; + + if (!drm_dev_enter(&malidp->base, &idx)) + return -ENODEV; =20 if (!scaling) { s->scale_enable =3D false; @@ -334,6 +355,9 @@ static int malidp_crtc_atomic_check_scaling(struct drm_= crtc *crtc, ret =3D hwdev->hw->se_calc_mclk(hwdev, s, &vm); if (ret < 0) return -EINVAL; + + drm_dev_exit(idx); + return 0; } =20 @@ -498,9 +522,16 @@ static int malidp_crtc_enable_vblank(struct drm_crtc *= crtc) { struct malidp_drm *malidp =3D crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev =3D malidp->dev; + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return -ENODEV; =20 malidp_hw_enable_irq(hwdev, MALIDP_DE_BLOCK, hwdev->hw->map.de_irq_map.vsync_irq); + + drm_dev_exit(idx); + return 0; } =20 @@ -508,9 +539,15 @@ static void malidp_crtc_disable_vblank(struct drm_crtc= *crtc) { struct malidp_drm *malidp =3D crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev =3D malidp->dev; + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; =20 malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK, hwdev->hw->map.de_irq_map.vsync_irq); + + drm_dev_exit(idx); } =20 static const struct drm_crtc_funcs malidp_crtc_funcs =3D { --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 842D8C32771 for ; Fri, 19 Aug 2022 21:26:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352496AbiHSVZ7 (ORCPT ); Fri, 19 Aug 2022 17:25:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352509AbiHSVZs (ORCPT ); Fri, 19 Aug 2022 17:25:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EE6FE01F3 for ; Fri, 19 Aug 2022 14:25:47 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hPqOotGSruHudwMIkA2GhgTM0KbwtUxu9NgLFadghJM=; b=MK8In+sXMZ4Gh0dictTovY1JQKfrHOoIueKwswZqzt+kZCUda36NWT21hPU1NvW/6EyA1L Gdsz6MrRvuWpJ2xWMgz8cGWH6YP8WZ2oosFjb63yr7d2YOomxuesR+pKvi2HbZ1cN81x89 cFJ17Rib80tYndToDi0YeiSZ1/8YSmQ= 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-271-m3nZTMmGPtOg63VuGxxrQw-1; Fri, 19 Aug 2022 17:25:45 -0400 X-MC-Unique: m3nZTMmGPtOg63VuGxxrQw-1 Received: by mail-ed1-f69.google.com with SMTP id y16-20020a056402359000b0043db5186943so3351648edc.3 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=cusrC6vKx5Vby6hUz3tj0BIIBMJo6isbdU/ik2Uc7IptMh7jXTwVnREQEHxAx2bORH 5IJlXWQSBcKj25yFdB/O7H4zTBGmOdFr/eQF/4CjLbLjlbFItiWRM9UTM4IBa3KBiHKf dTwNw2R4QZ5oj4ylJggiBaRxIztTIb0ahDtg9Th4b5b48SPCNeKyAFPOshybLMJ0pdBT xprEjDQSsEb6n+klHF8SaFAF8Tnui5mqxY3va55R8E+DwIf3P2OVO6Ct1nBtDyuZxjGU bZ336Q9jfYVJ7p9X2fOh5fEYZOMRDVwEtDppgRjWTkPkEiWHGQp696VaKn2wr6pI2R6y ynuA== X-Gm-Message-State: ACgBeo0DSbwMnJNEFTqmwXWuK4LJOzLj9Z8Z2Ji14yz8lQQ8kflJDh65 c7il5WljfV5+gYIm0h1JX0RGwIg63JGpJ6fuYuiqFnEULihNk9MM4pg6mFxIpn0m7FdNlHlQfrm P/elPJ0Iwbitk0WMG5gQ1Syma X-Received: by 2002:a05:6402:415:b0:446:230d:2b82 with SMTP id q21-20020a056402041500b00446230d2b82mr5875891edv.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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" (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_atomi= c_state *state) struct malidp_drm *malidp =3D drm_to_malidp(drm); struct drm_crtc *crtc; struct drm_crtc_state *old_crtc_state; - int i; + int i, idx; bool fence_cookie =3D dma_fence_begin_signalling(); =20 + if (!drm_dev_enter(drm, &idx)) + return; + pm_runtime_get_sync(drm->dev); =20 /* @@ -267,6 +270,8 @@ static void malidp_atomic_commit_tail(struct drm_atomic= _state *state) pm_runtime_put(drm->dev); =20 drm_atomic_helper_cleanup_planes(drm, state); + + drm_dev_exit(idx); } =20 static const struct drm_mode_config_helper_funcs malidp_mode_config_helper= s =3D { --=20 2.37.2