From nobody Tue May 7 18:09:39 2024 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 C3E3BC433F5 for ; Sat, 1 Oct 2022 16:40:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229661AbiJAQkC (ORCPT ); Sat, 1 Oct 2022 12:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbiJAQj6 (ORCPT ); Sat, 1 Oct 2022 12:39: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 1056F22BEE for ; Sat, 1 Oct 2022 09:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642395; 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=TF2idh4cfIfrFOF9EVS0R3ai/ZWpJhhFk/BXprIYCn4=; b=aro/Xyfz8vBLbISXXh6t9Qp5NJQiTpmYtsEXzVZfKvJa7bHAYFGrpqyP4Wg1qCFxTy7R8j JTSgw25rFBBKLVnWiuRlvq4Ijl35W9yS83u8ZUihH7BB5trrHUxh6LyhgYnp7GmLCjY4nu sRdv1UyHe6DTQ/HETZlDFi+u5SZjZd4= 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-157-XGEoWS_HOGmUg73vbP35YA-1; Sat, 01 Oct 2022 12:39:54 -0400 X-MC-Unique: XGEoWS_HOGmUg73vbP35YA-1 Received: by mail-ed1-f71.google.com with SMTP id v11-20020a056402348b00b004516e0b7eedso5743563edc.8 for ; Sat, 01 Oct 2022 09:39: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 :subject:date; bh=TF2idh4cfIfrFOF9EVS0R3ai/ZWpJhhFk/BXprIYCn4=; b=srhDU42aYd7g64QxwFvLTSUkS/cEJNaMxlTVIX4yLV3vj6IWmGqySUW1z/hoOoxjgr SmgCNCVK+j/cs/kOV6z2fPCqUpwu41hQgy52yKuL+2iWWNec5QpYQyO72+dP6M8a0WMb qBLEiYZVp+V4J1REaSAJiFSOtpSoiFTNlszCJoc2gu05X3qS5VCao7J2PCgiWZfLhYkX cDR0fLah6LoWuu//2nfzYk9Rxro/+CPZ6nTG0NGyKaZiBF9Yk3KHY1/xPjvxm0xKNX/r 7mcMdhUZn8BmaG76w2fKemQkIyK/Qrx/Try5vkXf8qsBoi+9JH9h0mFFrmz2okLreQHq M+UQ== X-Gm-Message-State: ACrzQf2DWmuzZ8LBXKYaL3ofm4Kxf0W0TQiBL9Jw6KcIkIovHv6RNfcJ TjLIdxjpR8X01ipyJZuInhTL8O5Hx6LdR3UJl0/kOIzZJYTDRp37nOi9mdtZHQFhEAOkrgr+xtq Tpao21g2qgIFHb5lLQrcwsegu X-Received: by 2002:a17:907:7f13:b0:782:9f6f:edbc with SMTP id qf19-20020a1709077f1300b007829f6fedbcmr10285484ejc.544.1664642393319; Sat, 01 Oct 2022 09:39:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4YiWo0W/l5+cQbA+w/X6w8Td19k+zzcWJMDh5uRvB8+XjnLfEvERBP2DIzt/cps2Y5Dr7exw== X-Received: by 2002:a17:907:7f13:b0:782:9f6f:edbc with SMTP id qf19-20020a1709077f1300b007829f6fedbcmr10285478ejc.544.1664642393151; Sat, 01 Oct 2022 09:39:53 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id f18-20020a05640214d200b004588ef795easm2841896edx.34.2022.10.01.09.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:39: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 v2 1/9] drm/arm/malidp: use drmm_* to allocate driver structures Date: Sat, 1 Oct 2022 18:39:38 +0200 Message-Id: <20221001163946.534067-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 6F14AC433FE for ; Sat, 1 Oct 2022 16:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiJAQkK (ORCPT ); Sat, 1 Oct 2022 12:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbiJAQkF (ORCPT ); Sat, 1 Oct 2022 12:40:05 -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 2811A26561 for ; Sat, 1 Oct 2022 09:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642400; 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=VkNRAFiSrosnva2K2Nfox+FAdpeu+OumI5CH8YjQjIA=; b=QYo19Lh3ifg5RPkfIB4eDHLuRBtmuDh5DcuCtK1TXOKatO3WW3PNGRTohjnCSTxsXzvLKV FUXvmPNOw5750toxBk7ADFk/ftSOP1gXc8/SKrcuguNIGvS4rsc0Q7mYb+KTnRRBTxQlzV sgRKmL2CQHPbPohS0XLaUnpprLj4lGE= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-347-v6PxhS1OPA-tpERRFNkYBQ-1; Sat, 01 Oct 2022 12:39:59 -0400 X-MC-Unique: v6PxhS1OPA-tpERRFNkYBQ-1 Received: by mail-ed1-f70.google.com with SMTP id b17-20020a056402351100b00453b19d9bd0so5686447edd.4 for ; Sat, 01 Oct 2022 09:39:58 -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=VkNRAFiSrosnva2K2Nfox+FAdpeu+OumI5CH8YjQjIA=; b=j7LdOMpMpP1utW13r4Wvvi53sZH6KPocpVliqMCBjqJB3mQZPcKbWXPRz/LjCOL9oO QN/9mzpo9KR55OL2xgLGODZwwyMRO9HS5jN9MqJoPkPJMODAQIQs2lphzJPFS/HAFmKi CmXWGerp9+GkGABrDtkI6NNrvrsWbRWhulUt9MaAgJtCojmskzmFCCpSug12tXNoB5gG 1TU/3ve2EAkyx8mMFeE9+ADba9HNwmDCOyIM30QjE2VIkfpywASOHhcjdNGej3uN7DYp 4o5Y2+k7X4uft3IV5gcOb3FP73DjKDIu6GEYFZlMREXqWpG3dZHMzSa7qAX1RGnZ1+WM vvCw== X-Gm-Message-State: ACrzQf3EseFU8XiEoFyBPqod9Rzk1XSLfD6faQPmd9HMrHNA2Q6bcvmD WRKgDS84cSylGL5dClKhmMe/ZGqms5/S8L0+XR7UdwlPF8TXUqVpye336ZuDgz/UntKUM7He4m6 bkrUMappyXZBJWLO2aST+qAKt X-Received: by 2002:a17:906:8a4a:b0:781:70ab:e7cb with SMTP id gx10-20020a1709068a4a00b0078170abe7cbmr9930635ejc.492.1664642397088; Sat, 01 Oct 2022 09:39:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM64Tsyr3aMS8FShUalKSLKk8eT6+4IqjM5v1TlJXLMReM+3+XLhDDh+jlVkvKuxsmPbrWmvhw== X-Received: by 2002:a17:906:8a4a:b0:781:70ab:e7cb with SMTP id gx10-20020a1709068a4a00b0078170abe7cbmr9930626ejc.492.1664642396857; Sat, 01 Oct 2022 09:39:56 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id v18-20020a50d092000000b00457e5a760e3sm3857785edd.54.2022.10.01.09.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:39:56 -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 v2 2/9] drm/arm/malidp: replace drm->dev_private with drm_to_malidp() Date: Sat, 1 Oct 2022 18:39:39 +0200 Message-Id: <20221001163946.534067-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 EED38C433F5 for ; Sat, 1 Oct 2022 16:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbiJAQkN (ORCPT ); Sat, 1 Oct 2022 12:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbiJAQkH (ORCPT ); Sat, 1 Oct 2022 12:40:07 -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 E29912528A for ; Sat, 1 Oct 2022 09:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642403; 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=zds5b/EQDqkx7Pyf1ZJFBZj3XHxRFNCLAcjtw1LYg8w=; b=Rt+uZYpqVqwWIuc3IuZg2vQpCeBvkVy9aI+FJLTxUp5ZV8TMlL2lCnr8JTWICY+/O9UTPL 8amysgf3Jjmq7TGdt3gFv3Rb/Yfr2Q1iAR/Osbn4YGpW8HIblTkDAwz/goZieQb0XW6tCw xw/ReDfO9kH74trooj3OxfG/kWKLKuA= 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-519-lanEiFRNPWKNwNNPHGTS9Q-1; Sat, 01 Oct 2022 12:40:02 -0400 X-MC-Unique: lanEiFRNPWKNwNNPHGTS9Q-1 Received: by mail-ed1-f72.google.com with SMTP id w17-20020a056402269100b0045249bc17a9so5712506edd.9 for ; Sat, 01 Oct 2022 09:40:01 -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=zds5b/EQDqkx7Pyf1ZJFBZj3XHxRFNCLAcjtw1LYg8w=; b=Cx5emnTDEDYt/Bro79c5lIVNpQvGWUFxv+3La3/CIgd+WqntFomXoq3vRVPnVmu1Bp 9+58sn4+EKUb821JSa1s4TAA/94+fzPDD1WXoA8LkZuPtyT5IK8P7OSf0/KVirDyyJhP caw3LRhDpzy3tdcZZ7IXBziNUfFT4FmbjsS+Wj36PntM3U3I/ptuBqJEaXuLUCNK4hwB b6T5o0Po8PmSxiZDOVBhEqL4CyDqOpFuhJWLV1jO0TjFS4iDjpMhG+yoMn1F6m2jUgBM Bss0SkoBFQSZv6cfLkY+oZAc4mGme+Qoh0p7gkTT2bW0UTiE6W2WoKPG80BXQTxFq4SK BtiQ== X-Gm-Message-State: ACrzQf1O0Jn9WxDlYe8hHWQYOPr8nOOHrIHyRE3xqNgK5CjZAN8IUmCR mV24tReeAHqxyvSzozhDBdLwZ947BoYexdyEL7GYBiOdh3n8GLzCapdSFyDRBv+0IC9Yq0olFCn vt99w2g9ap++f/Vk2tY55cIFQ X-Received: by 2002:a05:6402:90c:b0:457:b5ce:5f18 with SMTP id g12-20020a056402090c00b00457b5ce5f18mr12517589edz.309.1664642400681; Sat, 01 Oct 2022 09:40:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6oFsJ5/vkjCjrOH42LhRQl7FKzQpDN5xpPB29HBBbAof6bb+X69T6LRMlsEyBBdMK9vS++Ng== X-Received: by 2002:a05:6402:90c:b0:457:b5ce:5f18 with SMTP id g12-20020a056402090c00b00457b5ce5f18mr12517575edz.309.1664642400495; Sat, 01 Oct 2022 09:40:00 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id bi6-20020a170906a24600b00782cd82db09sm2923342ejb.106.2022.10.01.09.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40:00 -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 v2 3/9] drm/arm/malidp: crtc: use drmm_crtc_init_with_planes() Date: Sat, 1 Oct 2022 18:39:40 +0200 Message-Id: <20221001163946.534067-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 AD739C433F5 for ; Sat, 1 Oct 2022 16:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbiJAQkt (ORCPT ); Sat, 1 Oct 2022 12:40:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbiJAQk1 (ORCPT ); Sat, 1 Oct 2022 12:40:27 -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 C9C8B3054C for ; Sat, 1 Oct 2022 09:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642412; 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=gpNq1qUZhKiifLu+KM9SiJRwdNZ6qs1ZpRyRyQhvDJU=; b=iFEEP9qNvGuiLuSJnxFWSD9GDnLucOenpo4FoLMhj8iVnr7OiXMrYCkPF1AqKD2rbWKkPW DE+d44kky9CYxA6q4WMb/LM2KUAsotH/Bwx/ZZccRilq6SBzsJEmTgRHhDBZhOVt2x7cyG bVAUPVmUCsYUe6zlQCpdh2mdRoAP9hk= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-651-JfRlQj9IMQajs7ACL-51xQ-1; Sat, 01 Oct 2022 12:40:06 -0400 X-MC-Unique: JfRlQj9IMQajs7ACL-51xQ-1 Received: by mail-ed1-f70.google.com with SMTP id z9-20020a05640240c900b00458dae4ed9cso94729edb.3 for ; Sat, 01 Oct 2022 09:40:05 -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=gpNq1qUZhKiifLu+KM9SiJRwdNZ6qs1ZpRyRyQhvDJU=; b=Jzf9bvJVN8lzotjLG+SKW1M8LZBsbxnMPM22Bb58YPRPPs6XkYGVG7JO8rAfqgV86Z fxO9s/4z9NSx/WZeIBq1DRTK27Mm/xQGwnM4mIP+zlUqIgVk0FA0r0QxkM+NXPul8/YJ 2B/UPp+WLLVvTIYyrX1DErXvnCzrUAz/+tcZPVNzPgi5i5FDlS1LSsh/CxDNIdpRN1na ZOG9VfIETjHfU+RF6ba9uT/gyQwZS9wzA0vdNiqmk5Fcgoz/1e7NcUoXG1uRnadvraQk Xs+w2GvBjjWprHVvLKhGniu5UlD5Dx5FXSKpPE7pwZrJuGTL5Hd3C8rEC53quJyWTcog 2GzQ== X-Gm-Message-State: ACrzQf1vkd+7LM7E7Hb+BKRE/mGq1nDUJxe6xMkhTI9E3dIkJc+Is1fW K0Pme8Mh4kNZ4xkCVd+0u8aexdY2PD8NW4KAuWaf/+4O0werHt3hbTi+MRqxwuJF576lqjH+3EL 9esg8RIm5EwhgrtXTDeSkmTpZ X-Received: by 2002:a17:906:58c6:b0:782:bfb1:eae8 with SMTP id e6-20020a17090658c600b00782bfb1eae8mr10275543ejs.546.1664642404594; Sat, 01 Oct 2022 09:40:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6dlsCgBFNn35lBrJDeKfcylAkcj1My9M18VcnXKYSMaZYumIZ4S/welPhel8+NRewGbsWS3w== X-Received: by 2002:a17:906:58c6:b0:782:bfb1:eae8 with SMTP id e6-20020a17090658c600b00782bfb1eae8mr10275528ejs.546.1664642404187; Sat, 01 Oct 2022 09:40:04 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id p14-20020a17090653ce00b00781d411a63csm2878086ejo.151.2022.10.01.09.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40:03 -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 v2 4/9] drm/arm/malidp: plane: use drm managed resources Date: Sat, 1 Oct 2022 18:39:41 +0200 Message-Id: <20221001163946.534067-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 31AA2C433FE for ; Sat, 1 Oct 2022 16:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbiJAQkd (ORCPT ); Sat, 1 Oct 2022 12:40:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbiJAQkY (ORCPT ); Sat, 1 Oct 2022 12:40:24 -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 471142F00F for ; Sat, 1 Oct 2022 09:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642410; 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=7y8Kg9mwa0vUvwm8PGHbH7MwQR+LJsA0v4Hu5SumJhk=; b=JjONB6bwt0KxJQWlVLZaO5np3cm6Il9+/Djm8/mtBl2K7t3FCQrhuhPf33SuNuSRlSS3ap Ix+0PowIW5BxvGbejZTzV+GyNTj+zBOFEGbYjx8v0OxLvG1ZYEP03GGLMnIV3gPkatkBsC IXyNIwAnxHBWHS+Pl5yqPmd2gWABviM= 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-631-OVsv31N9PbqzNUBtUn8z-Q-1; Sat, 01 Oct 2022 12:40:09 -0400 X-MC-Unique: OVsv31N9PbqzNUBtUn8z-Q-1 Received: by mail-ed1-f71.google.com with SMTP id i17-20020a05640242d100b0044f18a5379aso5843989edc.21 for ; Sat, 01 Oct 2022 09:40:08 -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=7y8Kg9mwa0vUvwm8PGHbH7MwQR+LJsA0v4Hu5SumJhk=; b=wSAadHfRhFO6D7qCmy4sNtbhP+rswQg+skw1HyxQDhNgeM5EeaeVxyZlrX7ooXeddu MD5VW5ed9JVt0fk9MbispfSZmcpJoijv9evSjp6zBHB1lYHpgeZACscUU99Z5hIqCXWE 5gY8f0NrujZf9CwnA/jgHI/UHU+P9wCgFQxitL5szI1e2IkAAcf/NiurQFlX1c147gNw 43Giunrcx1IEOclJE8uGgO5zBs+ZDEuVNOmrOlb6oxVX4ZwucOrLjVduRHnRYb8NX5d4 ZS8H/XtCSdxPJGE69vrmWw698NQZx/imTzwXkwjFdP/4X1ecXSrWhl9MLGK9sKewfMhb PAlw== X-Gm-Message-State: ACrzQf0Ea+KCW2rUTm2toHQsrx1nQUvz7XrbgWPy0tpv+fp8wnbRHSRn RtVeQudLXXyikS4JwBDccytwXHjuXqsGS2VphPn12b2C6jmJ9meoy5UF7GOS4m9sjxeONjZ3B6V 1BI1Yxv3aPO5nrJG6zmOHXQ0O X-Received: by 2002:a05:6402:4441:b0:454:8a74:5459 with SMTP id o1-20020a056402444100b004548a745459mr11944337edb.155.1664642408034; Sat, 01 Oct 2022 09:40:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DTCDeA0KWBh6kSo2zm+j4Tg0+Kb8tU2UeueTgZVbg3102O9jUVRVuOw8bgSS/D1ZVeC8EAw== X-Received: by 2002:a05:6402:4441:b0:454:8a74:5459 with SMTP id o1-20020a056402444100b004548a745459mr11944325edb.155.1664642407879; Sat, 01 Oct 2022 09:40:07 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id o25-20020a1709062e9900b0077f15e98256sm2865110eji.203.2022.10.01.09.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40:07 -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 v2 5/9] drm/arm/malidp: use drm_dev_unplug() Date: Sat, 1 Oct 2022 18:39:42 +0200 Message-Id: <20221001163946.534067-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 583F9C433F5 for ; Sat, 1 Oct 2022 16:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbiJAQkw (ORCPT ); Sat, 1 Oct 2022 12:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbiJAQk2 (ORCPT ); Sat, 1 Oct 2022 12:40:28 -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 188C332047 for ; Sat, 1 Oct 2022 09:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642414; 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=X4+Ptu+qDGFqb0SHVblFALZEdZlh0sqNqyuMfzJpFUM=; b=a7rmAE96/IKnQePJD6jJL3OBXxu9hyqUxsZuBqg5/KV9UnqcKkWEUeIuHWZRHPNcF1ubys XDQPXNorJTiFL0jx6vQ5Wy7ma6TKTOyQD47NNUyrgf0G0iC3Z+xmL/C3YTCD0Gbt7xZLhg OSbJ6nsv9zwdkfuigMqst/cbKflrtBg= 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-152-Z-CWaDvpOUeSNUTNRUFzkg-1; Sat, 01 Oct 2022 12:40:13 -0400 X-MC-Unique: Z-CWaDvpOUeSNUTNRUFzkg-1 Received: by mail-ed1-f72.google.com with SMTP id z9-20020a05640240c900b00458dae4ed9cso94871edb.3 for ; Sat, 01 Oct 2022 09:40:12 -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=X4+Ptu+qDGFqb0SHVblFALZEdZlh0sqNqyuMfzJpFUM=; b=cbSrtC2z0pjYeLpRxDkiiB3H88YefXjCFgi+G6HKrKR1uBMH3V4u+V8McLYjijs+vT V7SPkwuRQkAyLkQi/v5YgpyzJsD6qUmwqOMZ5y3aq7v+KEcY/fwFvjhXFgeIhCQxyrIz hyskTGpwq1W0WLbacsB1cp02BCcQGuC74go/qgSnZ35Cx6t0q8a60izUsjRJmAkEQ6AK vp9fnvyawqrDVoPrDDyHBWguTP5VJy5TwoEhv8wPnYAivN/2YonsYC6FIxkmx402TOcU 3Ychp+ZvBMi0K5Ublrf+MIV4jbOusCPnQ+4FVzZKYBOUBv41PyQCWYM1xb3aE1lsSdHo CTAw== X-Gm-Message-State: ACrzQf2VcbtPLIgheWOtGZr/I45cRniEU76rJe74v1X4pIU2gqBwT3Za rO9/dA5CWLIDTMHkzEeSV/c9dklO/obEdq4m2ZOgnDTXV7sj9P8Xvd2klT4sAbIjWfhdgR3YyOL rjVJE4EYWtE1yTZHawiFmIjk0 X-Received: by 2002:a17:906:db02:b0:780:24e:cf9 with SMTP id xj2-20020a170906db0200b00780024e0cf9mr10115644ejb.460.1664642411747; Sat, 01 Oct 2022 09:40:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4sqRzShEvzcXK3sHQwN9XIDX9ReJ+nLvVhphfWZ1v1LAlyL8kh4A0p/0J+VR7oZU5jC9b3Sw== X-Received: by 2002:a17:906:db02:b0:780:24e:cf9 with SMTP id xj2-20020a170906db0200b00780024e0cf9mr10115640ejb.460.1664642411595; Sat, 01 Oct 2022 09:40:11 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id b18-20020a17090630d200b0073dd8e5a39fsm2888945ejb.156.2022.10.01.09.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40:11 -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 v2 6/9] drm/arm/malidp: plane: protect device resources after removal Date: Sat, 1 Oct 2022 18:39:43 +0200 Message-Id: <20221001163946.534067-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 F1B01C433F5 for ; Sat, 1 Oct 2022 16:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbiJAQlP (ORCPT ); Sat, 1 Oct 2022 12:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbiJAQkf (ORCPT ); Sat, 1 Oct 2022 12:40:35 -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 9E58136DF0 for ; Sat, 1 Oct 2022 09:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642418; 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=NI0bF9fBHKufsMehkRni4gVvJDlrywziIYn+evXebr8=; b=ZXgNPh/BAiUc8KtjiVe53Oy0uT1/LUdNbbMW4hYL9x5Hyzovl9aGBKBRRRSsHoUtnfS8Vz 2ADZcKm4znpZr1nIFgpMLvOzq8SO3KHiGJx+VJTUm45MUsTAhZhGminQZLJqY4O6KasNBT RKGnDCazEUirZC5vQYxWYp7wXalJmg8= 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-35-X_CK9hvbNLas7VPxoSOzEg-1; Sat, 01 Oct 2022 12:40:16 -0400 X-MC-Unique: X_CK9hvbNLas7VPxoSOzEg-1 Received: by mail-ed1-f72.google.com with SMTP id z16-20020a05640235d000b0045485e4a5e0so5756837edc.1 for ; Sat, 01 Oct 2022 09:40:16 -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=NI0bF9fBHKufsMehkRni4gVvJDlrywziIYn+evXebr8=; b=yyzPDIxYRmadmO6x2DmT4JFx2o0GGoC/Iu5kalaSl6sKsKYlb6jJoy30dd5p3q1N54 QpNslWsq6E3kpUCrbYDsHy+aUwc/8rMOV5lba917awL4c1/ekKhf5iUOom0HyfykWOWM oWDByfYT7SrMB6fbIL5y75r61EUGZeio6Nv2LCezrjXCEj/wXVd5TZZ064PKAfGkkrEf xW4NAUW23MU+N4fDdKxu8AH6cQbgt0kKIYcE+HOZqW1ViXVBID+gnEAdLpWeWe38/cDC JtZ6H2OAYS3dIp3pkMzKpXuXEf+GOdLKKw2nj7szX6c2EVsHGygozYlj+tCSjfu9UHCD GZfw== X-Gm-Message-State: ACrzQf3P4m+IFhfgkV8884h7DjZxLgxPXmPJv6iT0g0XhuAgu3jymGO/ 93Etz7+CWW1hK4MdvRoATDtuU7cFQdNNrfp+QOULMZqiusV1aUwJ+JLSQshRk1sa2O2mELg9a78 Hq6ys2hYSsQAlmI85GCf4p9b7 X-Received: by 2002:a17:906:4bd3:b0:731:3bdf:b95c with SMTP id x19-20020a1709064bd300b007313bdfb95cmr10256743ejv.677.1664642415615; Sat, 01 Oct 2022 09:40:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7C/Ts2uHJUPcJEM6l6hCyE9V7MI9D7avdy67tj8jdhoBYY6yqYRglyvOpGoWE5CwNmUEgcUw== X-Received: by 2002:a17:906:4bd3:b0:731:3bdf:b95c with SMTP id x19-20020a1709064bd300b007313bdfb95cmr10256732ejv.677.1664642415407; Sat, 01 Oct 2022 09:40:15 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id r8-20020a1709062cc800b0072b7d76211dsm2926614ejr.107.2022.10.01.09.40.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40:14 -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 v2 7/9] drm/arm/malidp: crtc: protect device resources after removal Date: Sat, 1 Oct 2022 18:39:44 +0200 Message-Id: <20221001163946.534067-8-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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 | 61 +++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp= _crtc.c index dc01c43f6193..e11cda5fdeb7 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,8 @@ 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; + enum drm_mode_status status =3D MODE_OK; + int idx; =20 /* * check that the hardware can drive the required clock rate, @@ -34,15 +37,21 @@ static enum drm_mode_status malidp_crtc_mode_valid(stru= ct 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) { DRM_DEBUG_DRIVER("pxlclk doesn't support %ld Hz\n", req_rate); - return MODE_NOCLOCK; + status =3D MODE_NOCLOCK; + goto out; } } =20 +out: + drm_dev_exit(idx); return MODE_OK; } =20 @@ -52,11 +61,15 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *= crtc, struct malidp_drm *malidp =3D crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev =3D malidp->dev; struct videomode vm; - int err =3D pm_runtime_get_sync(crtc->dev->dev); + int err, idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; =20 + err =3D pm_runtime_get_sync(crtc->dev->dev); if (err < 0) { DRM_DEBUG_DRIVER("Failed to enable runtime power management: %d\n", err); - return; + goto out; } =20 drm_display_mode_to_videomode(&crtc->state->adjusted_mode, &vm); @@ -68,6 +81,9 @@ 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); + +out: + drm_dev_exit(idx); } =20 static void malidp_crtc_atomic_disable(struct drm_crtc *crtc, @@ -77,7 +93,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 +110,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 +281,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; @@ -268,8 +292,10 @@ static int malidp_crtc_atomic_check_scaling(struct drm= _crtc *crtc, } =20 /* The scaling engine can only handle one plane at a time. */ - if (scaling & (scaling - 1)) - return -EINVAL; + if (scaling & (scaling - 1)) { + ret =3D -EINVAL; + goto out; + } =20 drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) { struct malidp_plane *mp =3D to_malidp_plane(plane); @@ -331,10 +357,10 @@ static int malidp_crtc_atomic_check_scaling(struct dr= m_crtc *crtc, =20 mclk_calc: drm_display_mode_to_videomode(&state->adjusted_mode, &vm); - ret =3D hwdev->hw->se_calc_mclk(hwdev, s, &vm); - if (ret < 0) - return -EINVAL; - return 0; + ret =3D hwdev->hw->se_calc_mclk(hwdev, s, &vm) < 0 ? -EINVAL : 0; +out: + drm_dev_exit(idx); + return ret; } =20 static int malidp_crtc_atomic_check(struct drm_crtc *crtc, @@ -498,9 +524,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 +541,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.3 From nobody Tue May 7 18:09:39 2024 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 3F2EBC433F5 for ; Sat, 1 Oct 2022 16:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbiJAQlw (ORCPT ); Sat, 1 Oct 2022 12:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbiJAQlM (ORCPT ); Sat, 1 Oct 2022 12:41:12 -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 91E21386AC for ; Sat, 1 Oct 2022 09:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642421; 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=dnX59dffWK1EQ9RPt7g3flEI99/gWclWQ2eDM1z8XdM=; b=FeaxxWMNZi02H+FbvzW4IDMAhzty+9I5Uc3Np8VcldVBJaOI2/OLhB12jlrYDqfebqWDTT hO2qvS4bTe747G0PB2H5GpeksTFSl3FrgpR7QFNxqQNghiyq64bRbmaQHxX1qQn1j/5YGO nOyj/qoxMMpK1V0B6HENID8iN/mmRM8= 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-15-l_jQoT7INqaRZC73vpKpKw-1; Sat, 01 Oct 2022 12:40:20 -0400 X-MC-Unique: l_jQoT7INqaRZC73vpKpKw-1 Received: by mail-ed1-f71.google.com with SMTP id e15-20020a056402190f00b0044f41e776a0so5731100edz.0 for ; Sat, 01 Oct 2022 09:40: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 :subject:date; bh=dnX59dffWK1EQ9RPt7g3flEI99/gWclWQ2eDM1z8XdM=; b=hqqeWr6eEmZIoECQHWJtgzE+rQzzG6mq6YxO561Yla2CAOcwoA3zydEntjTibcRLYl cbpWtMMFHYJy0FDXvEZ+fdilFiwKefXlYAGIIWpFOa+KN0RmAkvx3ekHbaYIsULOLe0o EYJsndihIJTeq4Nr52EhQOilIkasnz+AODZJlT63StgMDoAvAKSDGkd3Xq8yMgEXA4si zXY21DjB7zfdgiJPvA4DtHM2aBQPnwxm+qprXWm3YbJSAXxK5nnmjiCK5maD4IG1TpDy rimiuQRslSVNrQOTqUyRj7EauetU72HjktijhIJm+DPn4lLMu3ABvy4q59/vL0T/grxc Ek0A== X-Gm-Message-State: ACrzQf1SLXUAV0iRLf2F9bxPF1zFdLEyjN0EH0r/wLzp5bODNlxN1OLg ns/b1pomdcmuA7DZOQjvQcV/w2/4A3VtZk+qYPbTaiobVp+4Cqfm+ivnNFgqQKM8fuyrWEAofQR +MAPLMjNAIdHSFPf4D5Iktt96 X-Received: by 2002:a17:907:97cd:b0:787:ccc3:fde1 with SMTP id js13-20020a17090797cd00b00787ccc3fde1mr9121361ejc.334.1664642419227; Sat, 01 Oct 2022 09:40:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55Xp3BW3rc7QOk4esgcgUFW3Z9EOPnOO6tbl7W/JvSQU5pKXlUjMPacZd1NQ3DBccPKxweZQ== X-Received: by 2002:a17:907:97cd:b0:787:ccc3:fde1 with SMTP id js13-20020a17090797cd00b00787ccc3fde1mr9121349ejc.334.1664642419069; Sat, 01 Oct 2022 09:40:19 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id c20-20020a1709060fd400b0078167cb4536sm2886785ejk.118.2022.10.01.09.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40: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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH drm-misc-next v2 8/9] drm/arm/malidp: drv: protect device resources after removal Date: Sat, 1 Oct 2022 18:39:45 +0200 Message-Id: <20221001163946.534067-9-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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.3 From nobody Tue May 7 18:09:39 2024 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 8C77DC433F5 for ; Sat, 1 Oct 2022 16:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229823AbiJAQlV (ORCPT ); Sat, 1 Oct 2022 12:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbiJAQkj (ORCPT ); Sat, 1 Oct 2022 12:40:39 -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 81FCE386A1 for ; Sat, 1 Oct 2022 09:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642425; 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=abXRF2x6PmkkxgNipX/KKomtwvHsLuue5IHJHi8dXLg=; b=FYuv0wu0icqQjGTwGWp2im17b0qaQuBHfQ7EmfJD7iCS0BLMePAWLvL7/HxVRKpTatF4g9 U9+E4hr2haGHIKD2UG3Tu9JHonjgMMmQDaevhn8o0V8a2B1ryxKlbrGwRmGQkVn1C9RVOD 7EH1GsMF6uqo+BJ9dEA14ZASiZC5rGk= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-648-cDf9RxTCOtOUMI-gjmwxvw-1; Sat, 01 Oct 2022 12:40:24 -0400 X-MC-Unique: cDf9RxTCOtOUMI-gjmwxvw-1 Received: by mail-ed1-f70.google.com with SMTP id b17-20020a056402351100b00453b19d9bd0so5687057edd.4 for ; Sat, 01 Oct 2022 09:40: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 :subject:date; bh=abXRF2x6PmkkxgNipX/KKomtwvHsLuue5IHJHi8dXLg=; b=MSLqd1O5YZoWn0dibPWx6XMbzAVgqeIuDu3pss2HIv6Keh0Jomh9qkW3+3m+4N1uC3 lsXvyEiOUNwGKsqwoRtofY8EKcyoNZPCNcqiFH6TJeQfzFE/JjqiBQHt5xGbO2pwfMG5 wwpPbpnsCIUKG7KiY3yA1b0b7gaxh5b0qiB5R46DPL0eLyq3me7aT3SsH67paIleEHKI AZtSDqcMwVsqkXsiMwosqQP3wmrwBv8QfbwkJPSPIN6h3sZcXyC4SFVv9yX7h2o+VAgG y33eg1dcALYu323Fn7EEUFgid+jz3PsCTVi6xSV8cv8D4LTqDQ/67d61G0hrwqXzXjaV iVoA== X-Gm-Message-State: ACrzQf1l1ANbcIYbxpOMR5aoU0cfm2g5+IyukWGeQhGSXjsM6pLEhTUI ypMR/YfNCG5xzUHYPG4TTd3bfHaWfW9IF8OiZuN1YU7c8vZ41EdMFT6mfwSHGqll/SncOWX3LA+ aO9P8vHE5wsvn3Y2of04wSG4t X-Received: by 2002:aa7:c3d7:0:b0:457:e335:20a9 with SMTP id l23-20020aa7c3d7000000b00457e33520a9mr12146835edr.423.1664642422843; Sat, 01 Oct 2022 09:40:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5c2q88b9WNyAEwkZN6tMyNNztnVJ4pVe2/TWskbOVxN+6Ua71UqSEuXJApBRk2W+5Mjn8+xw== X-Received: by 2002:aa7:c3d7:0:b0:457:e335:20a9 with SMTP id l23-20020aa7c3d7000000b00457e33520a9mr12146827edr.423.1664642422703; Sat, 01 Oct 2022 09:40:22 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id rp9-20020a170906d96900b0077fb63da010sm2907882ejb.114.2022.10.01.09.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:40: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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH drm-misc-next v2 9/9] drm/arm/malidp: remove calls to drm_mode_config_cleanup() Date: Sat, 1 Oct 2022 18:39:46 +0200 Message-Id: <20221001163946.534067-10-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001163946.534067-1-dakr@redhat.com> References: <20221001163946.534067-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" drm_mode_config_init() simply calls drmm_mode_config_init(), hence cleanup is automatically handled through registering drm_mode_config_cleanup() with drmm_add_action_or_reset(). While at it, get rid of the deprecated drm_mode_config_init() and replace it with drmm_mode_config_init() directly. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_= drv.c index 8bb8e8d14461..ef6a9fc1c864 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -401,7 +401,9 @@ static int malidp_init(struct drm_device *drm) struct malidp_drm *malidp =3D drm_to_malidp(drm); struct malidp_hw_device *hwdev =3D malidp->dev; =20 - drm_mode_config_init(drm); + ret =3D drmm_mode_config_init(drm); + if (ret) + goto out; =20 drm->mode_config.min_width =3D hwdev->min_line_size; drm->mode_config.min_height =3D hwdev->min_line_size; @@ -412,24 +414,16 @@ static int malidp_init(struct drm_device *drm) =20 ret =3D malidp_crtc_init(drm); if (ret) - goto crtc_fail; + goto out; =20 ret =3D malidp_mw_connector_init(drm); if (ret) - goto crtc_fail; - - return 0; + goto out; =20 -crtc_fail: - drm_mode_config_cleanup(drm); +out: return ret; } =20 -static void malidp_fini(struct drm_device *drm) -{ - drm_mode_config_cleanup(drm); -} - static int malidp_irq_init(struct platform_device *pdev) { int irq_de, irq_se, ret =3D 0; @@ -879,7 +873,6 @@ static int malidp_bind(struct device *dev) bind_fail: of_node_put(malidp->crtc.port); malidp->crtc.port =3D NULL; - malidp_fini(drm); query_hw_fail: pm_runtime_put(dev); if (pm_runtime_enabled(dev)) @@ -907,7 +900,6 @@ static void malidp_unbind(struct device *dev) component_unbind_all(dev, drm); of_node_put(malidp->crtc.port); malidp->crtc.port =3D NULL; - malidp_fini(drm); pm_runtime_put(dev); if (pm_runtime_enabled(dev)) pm_runtime_disable(dev); --=20 2.37.3