From patchwork Sat Oct 1 16:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92E47C433FE for ; Sat, 1 Oct 2022 16:40:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7793C10E661; Sat, 1 Oct 2022 16:40:00 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 63C5F10E65F for ; Sat, 1 Oct 2022 16:39:56 +0000 (UTC) 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TF2idh4cfIfrFOF9EVS0R3ai/ZWpJhhFk/BXprIYCn4=; b=DbxmXzE3TY/dQocpqx5xeK2LdE5tAEjMKt4X6W8mr0PMLzV/ty6Xzz1QNyPoZtGIai5yWJ 7Z5EORtma5dSxuk4Py/fnxt/eWZ/qzvd+KaPrBa3YfXfGP80+IZPjaEWPH57ETRjUdom52 cqBtcfZ1B+tRgRpacWdClFk5tQl5zrM= 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-321-oso4ngkgPYGBSmoO2-moxA-1; Sat, 01 Oct 2022 12:39:54 -0400 X-MC-Unique: oso4ngkgPYGBSmoO2-moxA-1 Received: by mail-ed1-f71.google.com with SMTP id y9-20020a056402270900b00451dfbbc9b2so5722757edd.12 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=z2ICDU9wCmgaosUu7kl4M257tHoOkgyRtpvSbM6U/hhqrlQJlCAqmoq6r7Ov7JXirR xiKNgvHQd4/nFI1hYAeI+ZjeS0CHP6m+HHVw3i0jyGI23mWRMX/nhzew/q4xzJ/SpS8z HwWnvfxwDHmVIF5vSgq7lq4xKGvvRj5Sq6UR1ALglyDTV+Ruv5c4yLRSwl3IIYxUTXFx vobYNyMjMs6Bak9tZjO66RMCj6qH7JgeZQn2QK+S62wJYyp9+Te2yvYr2//HWA3NbCTV Cp54u6/y9rrEbKpJ+kbsgGtxKFdqddhyLibN+EPIqGcm5vSlepKO6sCfTHzPrYJ6wm+N lm7g== X-Gm-Message-State: ACrzQf3hvwgurd1pHkapn6PnFz5+kX39B1JR/k/R8fVCwVRe3lJ1xsxI HY2lZn8RnIiPAGCZPodfCf41won5xlWf8wN87JZ2iEY3V57P7oH+hBeVyU+v3RGZBT91kJR8HfL cMj1XG3BMVLNWFdFyOgoie0ov8vk+ X-Received: by 2002:a17:907:7f13:b0:782:9f6f:edbc with SMTP id qf19-20020a1709077f1300b007829f6fedbcmr10285488ejc.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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use drm managed resources to allocate driver structures and get rid of the deprecated drm_dev_alloc() call and replace it with devm_drm_dev_alloc(). This also serves as preparation to get rid of drm_device->dev_private and to fix use-after-free issues on driver unload. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 20 +++++++------------- drivers/gpu/drm/arm/malidp_drv.h | 1 + 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 1d0b0c54ccc7..41c80e905991 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -716,11 +717,13 @@ static int malidp_bind(struct device *dev) int ret = 0, i; u32 version, out_depth = 0; - malidp = devm_kzalloc(dev, sizeof(*malidp), GFP_KERNEL); - if (!malidp) - return -ENOMEM; + malidp = devm_drm_dev_alloc(dev, &malidp_driver, typeof(*malidp), base); + if (IS_ERR(malidp)) + return PTR_ERR(malidp); + + drm = &malidp->base; - hwdev = devm_kzalloc(dev, sizeof(*hwdev), GFP_KERNEL); + hwdev = drmm_kzalloc(drm, sizeof(*hwdev), GFP_KERNEL); if (!hwdev) return -ENOMEM; @@ -753,12 +756,6 @@ static int malidp_bind(struct device *dev) if (ret && ret != -ENODEV) return ret; - drm = drm_dev_alloc(&malidp_driver, dev); - if (IS_ERR(drm)) { - ret = PTR_ERR(drm); - goto alloc_fail; - } - drm->dev_private = malidp; dev_set_drvdata(dev, drm); @@ -887,8 +884,6 @@ static int malidp_bind(struct device *dev) malidp_runtime_pm_suspend(dev); drm->dev_private = NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); -alloc_fail: of_reserved_mem_device_release(dev); return ret; @@ -917,7 +912,6 @@ static void malidp_unbind(struct device *dev) malidp_runtime_pm_suspend(dev); drm->dev_private = NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); of_reserved_mem_device_release(dev); } diff --git a/drivers/gpu/drm/arm/malidp_drv.h b/drivers/gpu/drm/arm/malidp_drv.h index cdfddfabf2d1..00be369b28f1 100644 --- a/drivers/gpu/drm/arm/malidp_drv.h +++ b/drivers/gpu/drm/arm/malidp_drv.h @@ -29,6 +29,7 @@ struct malidp_error_stats { }; struct malidp_drm { + struct drm_device base; struct malidp_hw_device *dev; struct drm_crtc crtc; struct drm_writeback_connector mw_connector; From patchwork Sat Oct 1 16:39:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C2C7C433FE for ; Sat, 1 Oct 2022 16:40:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9CF2C10E663; Sat, 1 Oct 2022 16:40:04 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5276410E65F for ; Sat, 1 Oct 2022 16:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642399; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VkNRAFiSrosnva2K2Nfox+FAdpeu+OumI5CH8YjQjIA=; b=cFOtmrDbdG7Ssvgf62cfGixFxAFxjspEmfdkHsnbrOWxyL24y9U4bRk3mXRgZbdsZ2syHe 5hcecgEVPuATsLQJhXAXG9ZpcILDjqVzwbpToSrfmeqhvWQj0jPJ0xPKXvY1A5lafkGtTu fsxwJ9sBtmzuzq//IFtMOKyoehPdOjU= 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-570-ufV8Ub87NkKpE9kVQQaRUw-1; Sat, 01 Oct 2022 12:39:58 -0400 X-MC-Unique: ufV8Ub87NkKpE9kVQQaRUw-1 Received: by mail-ed1-f69.google.com with SMTP id b16-20020a056402279000b0044f1102e6e2so5867807ede.20 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=49YQ9b3KV8fPF2SSwMisnzZVIsLrciiuuxdhO2f4d+PBEVxWPCgTvRV3ar3TDHwrsG u7IWuN3kIompC0XBCj1fbPrI7S7Cs6yqh7RjNQJ/sVVhaSHp8kCESLc9oPN6kKe2ql3h jogArYCJgiTc94JU/IDOPyKC95egLSaYPFux9HEFYZmaLUx7kmP/J3SKvzKbOMdlrb5d 7UyH5wMpz9ke8keDYLB/PbWS22u8wZFjpObNcDtXk1yOCXLvYvWx/jnGmYsFcv/0d0+E CJDYQxXp0o4UPd4qGEudmrP+hQeCTRs5G03lMhXw04TP5DRM33Z7PdBKaTavmiV3JA3T M1OQ== X-Gm-Message-State: ACrzQf1l6zhMGZyBiBLSPkpzzS4choX2VP1FTQQPliNLlChFoMSFdHGy HfTkuelW787/PJwerNqVKjx/PpzDLdL1MTU2QHihbyECLZ3SkLmKBYzdA5lRooO1dvW34Dz/V4x OeIPLo3sdewqU2bypVBil20lFUp/h X-Received: by 2002:a17:906:8a4a:b0:781:70ab:e7cb with SMTP id gx10-20020a1709068a4a00b0078170abe7cbmr9930641ejc.492.1664642397089; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Using drm_device->dev_private is deprecated. Since we've switched to devm_drm_dev_alloc(), struct drm_device is now embedded in struct malidp_drm, hence we can use container_of() to get the struct drm_device instance instead. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_crtc.c | 2 +- drivers/gpu/drm/arm/malidp_drv.c | 29 +++++++++++++---------------- drivers/gpu/drm/arm/malidp_drv.h | 1 + drivers/gpu/drm/arm/malidp_hw.c | 10 +++++----- drivers/gpu/drm/arm/malidp_mw.c | 6 +++--- drivers/gpu/drm/arm/malidp_planes.c | 4 ++-- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c index 962730772b2f..34ad7e1cd2b8 100644 --- a/drivers/gpu/drm/arm/malidp_crtc.c +++ b/drivers/gpu/drm/arm/malidp_crtc.c @@ -526,7 +526,7 @@ static const struct drm_crtc_funcs malidp_crtc_funcs = { int malidp_crtc_init(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_plane *primary = NULL, *plane; int ret; diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 41c80e905991..678c5b0d8014 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -169,7 +169,7 @@ static void malidp_atomic_commit_se_config(struct drm_crtc *crtc, */ static int malidp_set_and_wait_config_valid(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; int ret; @@ -190,7 +190,7 @@ static int malidp_set_and_wait_config_valid(struct drm_device *drm) static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state) { struct drm_device *drm = state->dev; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); int loop = 5; malidp->event = malidp->crtc.state->event; @@ -231,7 +231,7 @@ static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state) static void malidp_atomic_commit_tail(struct drm_atomic_state *state) { struct drm_device *drm = state->dev; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_crtc *crtc; struct drm_crtc_state *old_crtc_state; int i; @@ -393,7 +393,7 @@ static const struct drm_mode_config_funcs malidp_mode_config_funcs = { static int malidp_init(struct drm_device *drm) { int ret; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; drm_mode_config_init(drm); @@ -429,7 +429,7 @@ static int malidp_irq_init(struct platform_device *pdev) { int irq_de, irq_se, ret = 0; struct drm_device *drm = dev_get_drvdata(&pdev->dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; /* fetch the interrupts from DT */ @@ -463,7 +463,7 @@ static int malidp_dumb_create(struct drm_file *file_priv, struct drm_device *drm, struct drm_mode_create_dumb *args) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); /* allocate for the worst case scenario, i.e. rotated buffers */ u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1); @@ -509,7 +509,7 @@ static void malidp_error_stats_dump(const char *prefix, static int malidp_show_stats(struct seq_file *m, void *arg) { struct drm_device *drm = m->private; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); unsigned long irqflags; struct malidp_error_stats de_errors, se_errors; @@ -532,7 +532,7 @@ static ssize_t malidp_debugfs_write(struct file *file, const char __user *ubuf, { struct seq_file *m = file->private_data; struct drm_device *drm = m->private; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); unsigned long irqflags; spin_lock_irqsave(&malidp->errors_lock, irqflags); @@ -553,7 +553,7 @@ static const struct file_operations malidp_debugfs_fops = { static void malidp_debugfs_init(struct drm_minor *minor) { - struct malidp_drm *malidp = minor->dev->dev_private; + struct malidp_drm *malidp = drm_to_malidp(minor->dev); malidp_error_stats_init(&malidp->de_errors); malidp_error_stats_init(&malidp->se_errors); @@ -653,7 +653,7 @@ static ssize_t core_id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); return snprintf(buf, PAGE_SIZE, "%08x\n", malidp->core_id); } @@ -671,7 +671,7 @@ ATTRIBUTE_GROUPS(mali_dp); static int malidp_runtime_pm_suspend(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; /* we can only suspend if the hardware is in config mode */ @@ -690,7 +690,7 @@ static int malidp_runtime_pm_suspend(struct device *dev) static int malidp_runtime_pm_resume(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; clk_prepare_enable(hwdev->pclk); @@ -756,7 +756,6 @@ static int malidp_bind(struct device *dev) if (ret && ret != -ENODEV) return ret; - drm->dev_private = malidp; dev_set_drvdata(dev, drm); /* Enable power management */ @@ -882,7 +881,6 @@ static int malidp_bind(struct device *dev) pm_runtime_disable(dev); else malidp_runtime_pm_suspend(dev); - drm->dev_private = NULL; dev_set_drvdata(dev, NULL); of_reserved_mem_device_release(dev); @@ -892,7 +890,7 @@ static int malidp_bind(struct device *dev) static void malidp_unbind(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; drm_dev_unregister(drm); @@ -910,7 +908,6 @@ static void malidp_unbind(struct device *dev) pm_runtime_disable(dev); else malidp_runtime_pm_suspend(dev); - drm->dev_private = NULL; dev_set_drvdata(dev, NULL); of_reserved_mem_device_release(dev); } diff --git a/drivers/gpu/drm/arm/malidp_drv.h b/drivers/gpu/drm/arm/malidp_drv.h index 00be369b28f1..bc0387876dea 100644 --- a/drivers/gpu/drm/arm/malidp_drv.h +++ b/drivers/gpu/drm/arm/malidp_drv.h @@ -45,6 +45,7 @@ struct malidp_drm { #endif }; +#define drm_to_malidp(x) container_of(x, struct malidp_drm, base) #define crtc_to_malidp_device(x) container_of(x, struct malidp_drm, crtc) struct malidp_plane { diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_hw.c index e9de542f9b7c..9b845d3f34e1 100644 --- a/drivers/gpu/drm/arm/malidp_hw.c +++ b/drivers/gpu/drm/arm/malidp_hw.c @@ -1168,7 +1168,7 @@ static void malidp_hw_clear_irq(struct malidp_hw_device *hwdev, u8 block, u32 ir static irqreturn_t malidp_de_irq(int irq, void *arg) { struct drm_device *drm = arg; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev; struct malidp_hw *hw; const struct malidp_irq_map *de; @@ -1226,7 +1226,7 @@ static irqreturn_t malidp_de_irq(int irq, void *arg) static irqreturn_t malidp_de_irq_thread_handler(int irq, void *arg) { struct drm_device *drm = arg; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); wake_up(&malidp->wq); @@ -1252,7 +1252,7 @@ void malidp_de_irq_hw_init(struct malidp_hw_device *hwdev) int malidp_de_irq_init(struct drm_device *drm, int irq) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; int ret; @@ -1286,7 +1286,7 @@ void malidp_de_irq_fini(struct malidp_hw_device *hwdev) static irqreturn_t malidp_se_irq(int irq, void *arg) { struct drm_device *drm = arg; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; struct malidp_hw *hw = hwdev->hw; const struct malidp_irq_map *se = &hw->map.se_irq_map; @@ -1363,7 +1363,7 @@ static irqreturn_t malidp_se_irq_thread_handler(int irq, void *arg) int malidp_se_irq_init(struct drm_device *drm, int irq) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; int ret; diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c index ef76d0e6ee2f..626709bec6f5 100644 --- a/drivers/gpu/drm/arm/malidp_mw.c +++ b/drivers/gpu/drm/arm/malidp_mw.c @@ -129,7 +129,7 @@ malidp_mw_encoder_atomic_check(struct drm_encoder *encoder, struct drm_connector_state *conn_state) { struct malidp_mw_connector_state *mw_state = to_mw_state(conn_state); - struct malidp_drm *malidp = encoder->dev->dev_private; + struct malidp_drm *malidp = drm_to_malidp(encoder->dev); struct drm_framebuffer *fb; int i, n_planes; @@ -207,7 +207,7 @@ static u32 *get_writeback_formats(struct malidp_drm *malidp, int *n_formats) int malidp_mw_connector_init(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); u32 *formats; int ret, n_formats; @@ -236,7 +236,7 @@ int malidp_mw_connector_init(struct drm_device *drm) void malidp_mw_atomic_commit(struct drm_device *drm, struct drm_atomic_state *old_state) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_writeback_connector *mw_conn = &malidp->mw_connector; struct drm_connector_state *conn_state = mw_conn->base.state; struct malidp_hw_device *hwdev = malidp->dev; diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 45f5e35e7f24..815d9199752f 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -151,7 +151,7 @@ bool malidp_format_mod_supported(struct drm_device *drm, { const struct drm_format_info *info; const u64 *modifiers; - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); const struct malidp_hw_regmap *map = &malidp->dev->hw->map; if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) @@ -931,7 +931,7 @@ static const uint64_t linear_only_modifiers[] = { int malidp_de_planes_init(struct drm_device *drm) { - struct malidp_drm *malidp = drm->dev_private; + struct malidp_drm *malidp = drm_to_malidp(drm); const struct malidp_hw_regmap *map = &malidp->dev->hw->map; struct malidp_plane *plane = NULL; enum drm_plane_type plane_type; From patchwork Sat Oct 1 16:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0529FC433FE for ; Sat, 1 Oct 2022 16:40:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E7E210E662; Sat, 1 Oct 2022 16:40:09 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id D1CA910E65F for ; Sat, 1 Oct 2022 16:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zds5b/EQDqkx7Pyf1ZJFBZj3XHxRFNCLAcjtw1LYg8w=; b=ZOqsHv9k2SV2uOYRiK4KlKt660PmDG2NQLOU8XizLUrlNwur0VaTePxiG7Q+6WV3PCezZC rq4eUFIakPYGP05naVEKVRWZzWilXIN8Vw0eZvi1yHqbNH8EsXhy/ACNiJ4wTQRbMg7qmT f/6NiAtefNrk1bFkTdal+ekdiHna1N8= 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-517-B-PSix-KMjWdBz6QK0o7lw-1; Sat, 01 Oct 2022 12:40:01 -0400 X-MC-Unique: B-PSix-KMjWdBz6QK0o7lw-1 Received: by mail-ed1-f69.google.com with SMTP id z9-20020a05640240c900b00458dae4ed9cso94560edb.3 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=lLg+XMH3L5+3uV2THZIH/55ZegCpILNHRLFN8xn+gp+BgNrQHGil1SOmN1CmBE7jfR CtrozNqa4EpYfwmOh26CguZbUhsqUPkTyBaKMrpCoYbbd/tcabj1C9J9imZkSRx0WbCi DB8SOUs97fi4sklnFNVfqRIWE8PMY6UmoPU7RLA8PUWIZpqnfubXJOYw8ivX5jjIiTCq fCaPrDHiINDJH2DUGSHRiKzYzqTZlsf9s4fJ+da0/P8Hl33HMzc4qNvyrus9Yn8UfZBr IBMYLWwlUVHXbBaAT10eJ5gLgHfGMhshm3K4uiONHIpAoR83KSwpBMZskR7sZR4QGg4I nDrg== X-Gm-Message-State: ACrzQf1YVdwEJPkWn1Ellb5AbExbBADk+RChgpgAfVu+NsHoQg58UByc 6jJjLpigaEuoBmOLgWtu3l4GnndbxXUR0zpGBCRL/vGHj1zuznYHM6WGcYeSqryBca3sISoxXHa SdBa/p9rTwrYQN6hmz0yuTAD+STK1 X-Received: by 2002:a05:6402:90c:b0:457:b5ce:5f18 with SMTP id g12-20020a056402090c00b00457b5ce5f18mr12517590edz.309.1664642400682; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use drmm_crtc_init_with_planes() instead of drm_crtc_init_with_planes() to get rid of the explicit destroy hook in struct drm_plane_funcs. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_crtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c index 34ad7e1cd2b8..dc01c43f6193 100644 --- a/drivers/gpu/drm/arm/malidp_crtc.c +++ b/drivers/gpu/drm/arm/malidp_crtc.c @@ -514,7 +514,6 @@ static void malidp_crtc_disable_vblank(struct drm_crtc *crtc) } static const struct drm_crtc_funcs malidp_crtc_funcs = { - .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .reset = malidp_crtc_reset, @@ -548,8 +547,8 @@ int malidp_crtc_init(struct drm_device *drm) return -EINVAL; } - ret = drm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, - &malidp_crtc_funcs, NULL); + ret = drmm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, + &malidp_crtc_funcs, NULL); if (ret) return ret; From patchwork Sat Oct 1 16:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 220E0C433F5 for ; Sat, 1 Oct 2022 16:40:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19C0810E664; Sat, 1 Oct 2022 16:40:14 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id D576410E664 for ; Sat, 1 Oct 2022 16:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gpNq1qUZhKiifLu+KM9SiJRwdNZ6qs1ZpRyRyQhvDJU=; b=MsEHKoFDjbaAjsA+VAOwkRx698L6+hBmaCWeTFmIOqg74RynIghy1UBy+tw29MBNiq7O+4 7KBnydH651Tb3kclI+GRB+Zy3t0JQiHS4Y2UNO126IA8DmL0lU+X8EzD78Ls1VBZbYBl1H MoQf92Evc72a1W+pPrNQi/2MxxTxsgI= 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-664-efyGjX-pNHKyc7TV6WuHyQ-1; Sat, 01 Oct 2022 12:40:05 -0400 X-MC-Unique: efyGjX-pNHKyc7TV6WuHyQ-1 Received: by mail-ed1-f70.google.com with SMTP id r11-20020a05640251cb00b004516feb8c09so5730668edd.10 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=GE8VSVvRX5V09PJQvspGHCaN/1pdt38Wyx7wIZKft11lseEo2d3CDrFIqQksvTXDX5 puoB4+7hSYT+WOJIkzXClqKEQ/9A96SSyWbzWrAXqzOqClQnGfak4vj6gx5Yo90XiyQq 5MoqLIflCV1qstmFWfOwdMt5aixBTe1pbV7D3XG8OOEr7g72TkEUSO6YD4KycXNj7rY4 IswOAIyn9lNMuf4S+2cAX++VDOkY7jLtvB/NKvDdk0lj7hHIhOY2LU227CZcLOmOJufa 0694JUi9xK+PH8eC7KPW3P2QmtcDDgUID6ITJkHgxlpmK4QXsB0dwj3lvwAlS2qcffHi SZzw== X-Gm-Message-State: ACrzQf3AW1EKdKqmZATWEEPiObvpW0cAM/EpMd9KlDhexHCrRDjjOcDC rtuZRjoq7vibHQuCRFwawos4UjatC43Yo0S01dnc4bkF3gTGaXSJ59AUXvt7JcsZL+DjLXySKux yVqBRBDwQBFhYbADheaN1SRx8Z02b X-Received: by 2002:a17:906:58c6:b0:782:bfb1:eae8 with SMTP id e6-20020a17090658c600b00782bfb1eae8mr10275550ejs.546.1664642404641; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use drm managed resource allocation (drmm_universal_plane_alloc()) in order to get rid of the explicit destroy hook in struct drm_plane_funcs. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_planes.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 815d9199752f..34547edf1ee3 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -68,14 +68,6 @@ /* readahead for partial-frame prefetch */ #define MALIDP_MMU_PREFETCH_READAHEAD 8 -static void malidp_de_plane_destroy(struct drm_plane *plane) -{ - struct malidp_plane *mp = to_malidp_plane(plane); - - drm_plane_cleanup(plane); - kfree(mp); -} - /* * Replicate what the default ->reset hook does: free the state pointer and * allocate a new empty object. We just need enough space to store @@ -260,7 +252,6 @@ static bool malidp_format_mod_supported_per_plane(struct drm_plane *plane, static const struct drm_plane_funcs malidp_de_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, - .destroy = malidp_de_plane_destroy, .reset = malidp_plane_reset, .atomic_duplicate_state = malidp_duplicate_plane_state, .atomic_destroy_state = malidp_destroy_plane_state, @@ -972,12 +963,6 @@ int malidp_de_planes_init(struct drm_device *drm) for (i = 0; i < map->n_layers; i++) { u8 id = map->layers[i].id; - plane = kzalloc(sizeof(*plane), GFP_KERNEL); - if (!plane) { - ret = -ENOMEM; - goto cleanup; - } - /* build the list of DRM supported formats based on the map */ for (n = 0, j = 0; j < map->n_pixel_formats; j++) { if ((map->pixel_formats[j].layer & id) == id) @@ -990,13 +975,14 @@ int malidp_de_planes_init(struct drm_device *drm) /* * All the layers except smart layer supports AFBC modifiers. */ - ret = drm_universal_plane_init(drm, &plane->base, crtcs, - &malidp_de_plane_funcs, formats, n, - (id == DE_SMART) ? linear_only_modifiers : modifiers, - plane_type, NULL); - - if (ret < 0) + plane = drmm_universal_plane_alloc(drm, struct malidp_plane, base, + crtcs, &malidp_de_plane_funcs, formats, n, + (id == DE_SMART) ? linear_only_modifiers : + modifiers, plane_type, NULL); + if (IS_ERR(plane)) { + ret = PTR_ERR(plane); goto cleanup; + } drm_plane_helper_add(&plane->base, &malidp_de_plane_helper_funcs); From patchwork Sat Oct 1 16:39:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D578CC4332F for ; Sat, 1 Oct 2022 16:40:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C28910E667; Sat, 1 Oct 2022 16:40:16 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1A48210E664 for ; Sat, 1 Oct 2022 16:40:11 +0000 (UTC) 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7y8Kg9mwa0vUvwm8PGHbH7MwQR+LJsA0v4Hu5SumJhk=; b=flt4+5OYLLNX0KdPkEDBfxjLnoNbXaWbz142IenohxzqlvmMaA8T4mhVu3ni2UlR1NF86P GprLEfSgoo9VdU3EDgRHdeZewx0vgV4sPtub9ZDl97Xl7jLk/upQ9GyWlAVehETgIcMwBy rlMlP+jwh/o9nOODq9DhFpUxSXCEl38= 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-630-ohK6r1YbMYW1rlQC1VF7pg-1; Sat, 01 Oct 2022 12:40:09 -0400 X-MC-Unique: ohK6r1YbMYW1rlQC1VF7pg-1 Received: by mail-ed1-f70.google.com with SMTP id h13-20020a056402280d00b004581108ba90so5725534ede.2 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=1efYxgrICMcYy9+U3sQSZAbN9ShRwvVMT6yYIdRfRLoobuSixUf8Ew8g/7201/RbKX H0awlyjdRvPQ1/YFIWO6Y7kNTBqlgLGWaon9xdKQZGJBgrN7VFPDPnqZxXeBWBPe1uG9 iBr534tp1OL3FfEQYHsNGSiyE2iV8O/HSOE2x0QzQfErKO6Ra+tH35UIA0bbaVJQmg4/ qsdp2UvVBm4zC3CX8gJWlBzUnh9bD7yPO+QL2Ddupnync8RaXXzDlLgNAeNQalCfWO3f 9TUXlgFR1JBG2LkP6yaIz3xH+5Farqz2TZGSmxo8hefcqiX24fAY3kZ/aATUdAxvQ/tT xCNA== X-Gm-Message-State: ACrzQf39abj9MkMhiY+JVTcYltJ7zYkc6pkuwQL+Sx8qS/N/2gI4koDJ QKitq7HilkRghnM4NCjFqYZgPK7xCwpBIrniZW8JO3beHnAMJaZBoflycOrteiTwf1JxCHpAMTL BYTL3qTpmyfUObD+nhkVexq3s1Cfd X-Received: by 2002:a05:6402:4441:b0:454:8a74:5459 with SMTP id o1-20020a056402444100b004548a745459mr11944340edb.155.1664642408036; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" When the driver is unbound, there might still be users in userspace having an open fd and are calling into the driver. While this is fine for drm managed resources, it is not for resources bound to the device/driver lifecycle, e.g. clocks or MMIO mappings. To prevent use-after-free issues we need to protect those resources with drm_dev_enter() and drm_dev_exit(). This does only work if we indicate that the drm device was unplugged, hence use drm_dev_unplug() instead of drm_dev_unregister(). Protecting the particular resources with drm_dev_enter()/drm_dev_exit() is handled by subsequent patches. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 678c5b0d8014..aedd30f5f451 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -893,7 +893,7 @@ static void malidp_unbind(struct device *dev) struct malidp_drm *malidp = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; - drm_dev_unregister(drm); + drm_dev_unplug(drm); drm_kms_helper_poll_fini(drm); pm_runtime_get_sync(dev); drm_atomic_helper_shutdown(drm); From patchwork Sat Oct 1 16:39:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 09DCAC433F5 for ; Sat, 1 Oct 2022 16:40:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7575310E65F; Sat, 1 Oct 2022 16:40:22 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id BFFF210E666 for ; Sat, 1 Oct 2022 16:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X4+Ptu+qDGFqb0SHVblFALZEdZlh0sqNqyuMfzJpFUM=; b=IU6qOcdsHc4sdS+PK/KsA2WMfvWvByxJpjJBQZ2bj7m18rFH+xghKWDEaqMQDJkVFXzl2M x6GAbMHGWpMV23/H6wfy+G10vTMkKx1h0ZX+O0vDtT14//dUMm6Iyw575bOiKfTk1Pywoq TCE7WgSwDWlMpIfPvFO8cp3R+sJXHjg= 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-619-mc5muNS7Oz22ei_H2nIdIg-1; Sat, 01 Oct 2022 12:40:14 -0400 X-MC-Unique: mc5muNS7Oz22ei_H2nIdIg-1 Received: by mail-ed1-f70.google.com with SMTP id dz21-20020a0564021d5500b0045217702048so5685078edb.5 for ; Sat, 01 Oct 2022 09:40:14 -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=R+Xuxwo6TRKxSnikCORYPKseCnOOwKG7jlOISBX6gJ9759OphyVc0Tc0wJNOd9GJHN Z5T2mLg3kSV2uxIWl66yY1X5+dO5BH7ZRyC+v9aMNVzHhU4u9W4AY2gdZqBwYFf9YGNG nzhPoNvJiXTn6lwHFbaye9w1+/2A8cieI8ZWy2V43IvVxBiDVuV0aiRBfxlVFgY2lxO0 PFyZUTUK4fgrj6agSwql7TMHLdhJ6SdCii1+dpE0Q3nhTLp1CORXr3Cr6sGE1V570VE+ Nq+texuPJSl+L4Ha2RcBZFNsDBsCUOy7yrEllW5DrQWzT7EJ0dnDa0JnzIhaBfey5o9k hD7Q== X-Gm-Message-State: ACrzQf3fcSSqHDRaI3bqxgyVD9KZA4pFzCBUVCOhYpCiXgKUeGrQHI1i R4zXKlmdrzABzOnP7oEwYylDkjGIiUVCeIn+lE93iBuhNQQkc5dOvRGikz7AZdgnr7ERhYBqwwO bL3VUybGwe7/TJ4w0Lb+mivQnfUEo X-Received: by 2002:a17:906:db02:b0:780:24e:cf9 with SMTP id xj2-20020a170906db0200b00780024e0cf9mr10115648ejb.460.1664642411750; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user didn't close it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_planes.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index 34547edf1ee3..d2ea60549454 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -790,9 +790,12 @@ static void malidp_de_plane_update(struct drm_plane *plane, u16 pixel_alpha = new_state->pixel_blend_mode; u8 plane_alpha = new_state->alpha >> 8; u32 src_w, src_h, dest_w, dest_h, val; - int i; + int i, idx; struct drm_framebuffer *fb = plane->state->fb; + if (!drm_dev_enter(plane->dev, &idx)) + return; + mp = to_malidp_plane(plane); /* @@ -897,16 +900,24 @@ static void malidp_de_plane_update(struct drm_plane *plane, malidp_hw_write(mp->hwdev, val, mp->layer->base + MALIDP_LAYER_CONTROL); + + drm_dev_exit(idx); } static void malidp_de_plane_disable(struct drm_plane *plane, struct drm_atomic_state *state) { struct malidp_plane *mp = to_malidp_plane(plane); + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; malidp_hw_clearbits(mp->hwdev, LAYER_ENABLE | LAYER_FLOWCFG(LAYER_FLOWCFG_MASK), mp->layer->base + MALIDP_LAYER_CONTROL); + + drm_dev_exit(idx); } static const struct drm_plane_helper_funcs malidp_de_plane_helper_funcs = { From patchwork Sat Oct 1 16:39:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE9FEC433F5 for ; Sat, 1 Oct 2022 16:40:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AB70410E666; Sat, 1 Oct 2022 16:40:27 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id BAFFE10E666 for ; Sat, 1 Oct 2022 16:40:18 +0000 (UTC) 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NI0bF9fBHKufsMehkRni4gVvJDlrywziIYn+evXebr8=; b=h8J1+sGzojx99fDxZMYMyqacTcKr1p6a09t/msd42GkmU9/XLdSCGHnalbEYuHZUuKs87Z 7L1LISCQ2BFC4hql7+m58AvWX5jQOdqnVmZIr/UG8NKoAEgDsolYkjm2lIZs2pMm/wUFQ+ YQpZ/GxIb4RQp9a5kvwTlaaXNjY802k= 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-35-zmfYQEFFNoCFwtAQQqkX7g-1; Sat, 01 Oct 2022 12:40:16 -0400 X-MC-Unique: zmfYQEFFNoCFwtAQQqkX7g-1 Received: by mail-ed1-f71.google.com with SMTP id y9-20020a056402270900b00451dfbbc9b2so5723328edd.12 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=JWootb6cpM+QhvYb/+Ibmn6L0sTABb544dz8hMM5TVsXWp2ND7gHsO6qftp4dZea1a o9+6apeOrlSqdPpMKfJwhOuUav4ndz97Nxrz45w8BjQMox47cuPmKi/xPDRMsyXyY6Os CFYccvaDip+1LBhORYKi0L7WyDZfe4+CFNDiv8FpAqErbhy7q4cV0xdWWzrpYkYsuP4N OY8V7UZos0yNPhH7VIzDXALWda670We/K1dMQfjVLNGsLccrFK6CFoD2QKqzT34Ibtv0 gkhW7KUh3nOh2BcgTcNQ8XHyJgJuaANXiUP7LovwvN8G5Qew+EHDASMWiOD7pHHgkzmk kPig== X-Gm-Message-State: ACrzQf2JXpW2xlOCAfMXx/XiCDPgJOtEQ3mt4KDHhaorcK1GrieGBFqX 8AIhxtSVCa/iniN/08aj1oM3nvpqfbhiPFqwZBYpWOAUMe/MlgG0IVP21VIujLEMEGIMlUkLGXi mFDG6G7aVSsbsk2v2BMurLwSnRv08 X-Received: by 2002:a17:906:4bd3:b0:731:3bdf:b95c with SMTP id x19-20020a1709064bd300b007313bdfb95cmr10256747ejv.677.1664642415616; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user didn't close it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_crtc.c | 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 = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; + enum drm_mode_status status = MODE_OK; + int idx; /* * check that the hardware can drive the required clock rate, @@ -34,15 +37,21 @@ static enum drm_mode_status malidp_crtc_mode_valid(struct drm_crtc *crtc, */ long rate, req_rate = mode->crtc_clock * 1000; + if (!drm_dev_enter(&malidp->base, &idx)) + return MODE_NOCLOCK; + if (req_rate) { rate = clk_round_rate(hwdev->pxlclk, req_rate); if (rate != req_rate) { DRM_DEBUG_DRIVER("pxlclk doesn't support %ld Hz\n", req_rate); - return MODE_NOCLOCK; + status = MODE_NOCLOCK; + goto out; } } +out: + drm_dev_exit(idx); return MODE_OK; } @@ -52,11 +61,15 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc, struct malidp_drm *malidp = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; struct videomode vm; - int err = pm_runtime_get_sync(crtc->dev->dev); + int err, idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; + err = 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; } drm_display_mode_to_videomode(&crtc->state->adjusted_mode, &vm); @@ -68,6 +81,9 @@ static void malidp_crtc_atomic_enable(struct drm_crtc *crtc, hwdev->hw->modeset(hwdev, &vm); hwdev->hw->leave_config_mode(hwdev); drm_crtc_vblank_on(crtc); + +out: + drm_dev_exit(idx); } 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 = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; - int err; + int err, idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; /* always disable planes on the CRTC that is being turned off */ drm_atomic_helper_disable_planes_on_crtc(old_state, false); @@ -91,6 +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); } 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 = 0; /* U16.16 */ u32 v_upscale_factor = 0; /* U16.16 */ u8 scaling = cs->scaled_planes_mask; - int ret; + int idx, ret; + + if (!drm_dev_enter(&malidp->base, &idx)) + return -ENODEV; if (!scaling) { s->scale_enable = false; @@ -268,8 +292,10 @@ static int malidp_crtc_atomic_check_scaling(struct drm_crtc *crtc, } /* The scaling engine can only handle one plane at a time. */ - if (scaling & (scaling - 1)) - return -EINVAL; + if (scaling & (scaling - 1)) { + ret = -EINVAL; + goto out; + } drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) { struct malidp_plane *mp = to_malidp_plane(plane); @@ -331,10 +357,10 @@ static int malidp_crtc_atomic_check_scaling(struct drm_crtc *crtc, mclk_calc: drm_display_mode_to_videomode(&state->adjusted_mode, &vm); - ret = hwdev->hw->se_calc_mclk(hwdev, s, &vm); - if (ret < 0) - return -EINVAL; - return 0; + ret = hwdev->hw->se_calc_mclk(hwdev, s, &vm) < 0 ? -EINVAL : 0; +out: + drm_dev_exit(idx); + return ret; } 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 = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return -ENODEV; malidp_hw_enable_irq(hwdev, MALIDP_DE_BLOCK, hwdev->hw->map.de_irq_map.vsync_irq); + + drm_dev_exit(idx); + return 0; } @@ -508,9 +541,15 @@ static void malidp_crtc_disable_vblank(struct drm_crtc *crtc) { struct malidp_drm *malidp = crtc_to_malidp_device(crtc); struct malidp_hw_device *hwdev = malidp->dev; + int idx; + + if (!drm_dev_enter(&malidp->base, &idx)) + return; malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK, hwdev->hw->map.de_irq_map.vsync_irq); + + drm_dev_exit(idx); } static const struct drm_crtc_funcs malidp_crtc_funcs = { From patchwork Sat Oct 1 16:39:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80A9AC433F5 for ; Sat, 1 Oct 2022 16:40:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D592410E66B; Sat, 1 Oct 2022 16:40:32 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id E813410E668 for ; Sat, 1 Oct 2022 16:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664642427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnX59dffWK1EQ9RPt7g3flEI99/gWclWQ2eDM1z8XdM=; b=gg6J/etSzXuyP5NJFmYSLgnVu7JsHnWG/Yj2YifQzpKsiMprrgC3efC2aG/NcMTD42XB0M shGBuXN28U/hen2nKhn5BM1dS+DuJ0Zu5r7llYlj/2ZQzv1jRdOwXWw036aHqD5IX0yQdE UF5Tj0FaNtrdUQIZ1OA8eX6qxB93BrA= 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-387-9XsbaJA9Mpu_UJq6KrdSJw-1; Sat, 01 Oct 2022 12:40:20 -0400 X-MC-Unique: 9XsbaJA9Mpu_UJq6KrdSJw-1 Received: by mail-ed1-f71.google.com with SMTP id y1-20020a056402358100b00451b144e23eso5701504edc.18 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=dQEkjUOFkb9S+grAx1fA2IiSPc2QHDR/kOhuuv4+xLynhDlUG9kkmvhF6V+kxkN/wK BMiCjxFQdUeGlTzLBzHXs77eLa2+32nqKVGktg/cEyYmF/6qIL8FKDZo86+FX2FZHKjq qPxhup8OKBJqz7AbZmeCnEJkvWM2XT9KHO9UWAScZxaNOB2NWW4F852cgHlzSzoJAzks g8kIfUOxkXTWYpKloF9dyQbAs/iJ+R5rZrgJ7U4VuGavcID7VANHOgYyhNbC0iiV7ry3 dDBTyXqTRvHcq4oIXyXGXJAdJEfyww+MyuKSUiETj/U3J2bA+Dat0mo/lUfJdblWBH8b +gFw== X-Gm-Message-State: ACrzQf10gG6gB5XXPLFMTvWYDb9l8b5hMlAqzDRXmcQ+EWuSgCrvz5Sc 2VBtIa7ymv/vIF+PXe9ZleIUWDDqrxbP5o8s4NSw5cWGDmrfwyq95w2MB2ahFi9RCHNkT5NmKmc csoVjaiQ+HpBk06h8rH7MPnq7oQnU X-Received: by 2002:a17:907:97cd:b0:787:ccc3:fde1 with SMTP id js13-20020a17090797cd00b00787ccc3fde1mr9121358ejc.334.1664642419224; 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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" (Hardware) resources which are bound to the driver and device lifecycle must not be accessed after the device and driver are unbound. However, the DRM device isn't freed as long as the last user didn't close it, hence userspace can still call into the driver. Therefore protect the critical sections which are accessing those resources with drm_dev_enter() and drm_dev_exit(). Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/malidp_drv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index aedd30f5f451..8bb8e8d14461 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -234,9 +234,12 @@ static void malidp_atomic_commit_tail(struct drm_atomic_state *state) struct malidp_drm *malidp = drm_to_malidp(drm); struct drm_crtc *crtc; struct drm_crtc_state *old_crtc_state; - int i; + int i, idx; bool fence_cookie = dma_fence_begin_signalling(); + if (!drm_dev_enter(drm, &idx)) + return; + pm_runtime_get_sync(drm->dev); /* @@ -267,6 +270,8 @@ static void malidp_atomic_commit_tail(struct drm_atomic_state *state) pm_runtime_put(drm->dev); drm_atomic_helper_cleanup_planes(drm, state); + + drm_dev_exit(idx); } static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { From patchwork Sat Oct 1 16:39:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34CB6C433F5 for ; Sat, 1 Oct 2022 16:40:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 34F2510E66A; Sat, 1 Oct 2022 16:40:30 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id E6B2A10E666 for ; Sat, 1 Oct 2022 16:40:25 +0000 (UTC) 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=abXRF2x6PmkkxgNipX/KKomtwvHsLuue5IHJHi8dXLg=; b=EA9Akj7loGtIIO716YAmF+QkdtnULYE+F+q6+Da2LAqRibMAcRaDjDJpf9ryzLUQVIVHbK /SxWR9AdVLo9AI6YEEDLr8bq4pR3637nv7+e4t2qOAsyhnvihJ6NlCgr2d+DJ4IaxustlQ t0ibY1EQVCQNTgDlk6MGLdASUhBD76E= 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-648-TPANuzdfPzmpBdTuMx3jhA-1; Sat, 01 Oct 2022 12:40:24 -0400 X-MC-Unique: TPANuzdfPzmpBdTuMx3jhA-1 Received: by mail-ed1-f69.google.com with SMTP id dz21-20020a0564021d5500b0045217702048so5685262edb.5 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=Bndwlxv4bPbPk6xqHe5PhMpu4BpjmE25gxAVnfkHHXhcmsuvrQyt20THqRnGXBToyF ugB6+VwscNJOdLXgPpdEl/CfDof2OLTCMpxgsqN2FXHi8rG2J8ZMFlTfjwmddIhFNe4e 2F3N89dv21REFD0Q/gdNeM2yFCg3GT9HFSrr0azJB5l+CkEgzkuUJNSn7DHBdUHUKLNz GLfYSaOytsP01ZKtjwuzoiuPMuuRpbGu5yZqbKOY1vJgquckxubnjzq0WVXqZaXSQrvs 40E64VrT03BAQRgb2oyf6tYoYbaO7h6rBsPOHzIZ4TZweRRtzwhmEtramSc+ZCoBzu8s A0lA== X-Gm-Message-State: ACrzQf0hve9/JpGe4qPxAMEQNWJvenF4I1MLG+jgYuubXWKzJYUqr4ba VNRPXVFDOjSwuCZkvbiV6iPH7WNK3u7wXea4OjeAdMxZOOgNj4qkGTN7N50u0a9YqEhr4lrLpzD ZH/DWCFPFzMp8vScwYJQoiYyAabIQ X-Received: by 2002:aa7:c3d7:0:b0:457:e335:20a9 with SMTP id l23-20020aa7c3d7000000b00457e33520a9mr12146834edr.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 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 = drm_to_malidp(drm); struct malidp_hw_device *hwdev = malidp->dev; - drm_mode_config_init(drm); + ret = drmm_mode_config_init(drm); + if (ret) + goto out; drm->mode_config.min_width = hwdev->min_line_size; drm->mode_config.min_height = hwdev->min_line_size; @@ -412,24 +414,16 @@ static int malidp_init(struct drm_device *drm) ret = malidp_crtc_init(drm); if (ret) - goto crtc_fail; + goto out; ret = malidp_mw_connector_init(drm); if (ret) - goto crtc_fail; - - return 0; + goto out; -crtc_fail: - drm_mode_config_cleanup(drm); +out: return ret; } -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 = 0; @@ -879,7 +873,6 @@ static int malidp_bind(struct device *dev) bind_fail: of_node_put(malidp->crtc.port); malidp->crtc.port = 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 = NULL; - malidp_fini(drm); pm_runtime_put(dev); if (pm_runtime_enabled(dev)) pm_runtime_disable(dev);