From patchwork Mon Sep 5 15:27:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966295 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 7C7F5ECAAD5 for ; Mon, 5 Sep 2022 15:27:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3136710EA44; Mon, 5 Sep 2022 15:27:41 +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 AC77410EA44 for ; Mon, 5 Sep 2022 15:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391655; 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=FE6F/FaZU56VVek/ild/rdOe20eLgXYTWVytxZbV5OU=; b=X7byDzOdog63ft814HY9k+rDPcNjPsU3HEVKDIWwEe0hJVYZ6xPnoVVzjePuEQYXK9Xggg HTEmTDy9wv+Ue0TFBPCK8KlrA4L0B+/0sWi4a/pYTQ0+fMGDcMFteLN/jELTwOPf75D7ek 6vOajLLt0HpqK+qlX2H6RZEJZblB4ms= 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-63-FKNG48CTMyuGRLHis-64Qw-1; Mon, 05 Sep 2022 11:27:27 -0400 X-MC-Unique: FKNG48CTMyuGRLHis-64Qw-1 Received: by mail-ed1-f71.google.com with SMTP id z20-20020a05640235d400b0043e1e74a495so6012105edc.11 for ; Mon, 05 Sep 2022 08:27:27 -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=FE6F/FaZU56VVek/ild/rdOe20eLgXYTWVytxZbV5OU=; b=qX2Hq460tHkhoxaGntrIz4rBYEhF1OoPE5313+HYqccaELuCrdefsYqPkjOdCQOeqc gn5Z69Dv7r3hveWiQD4m5ZW6tRILlA5Ne3MCv1pQxCWIJJz6xYllydqAFYOOq55ZTGLA BGo8HEjvatuDzp7936a5DzQ1Ff3qCs7Cc6q8g8lFtSOVa50cb2zWVSnIMFpbyKXdSGiW sZ/eoeJ0W108Oa8/ls5IaT4r//BHCyMNL6jj7d3RgpFB1T8R3T+52BydYj3wRwskJxma ZEGpztFwFPBWXBfkylaKxrMYscEDr1v9jkMWB8/gyONQJkKF3vytA05Ha2J7Z039uxag eAvQ== X-Gm-Message-State: ACgBeo3JHHB4r2IzeWqfvDx//cjNLfbGDNohUC2gyeZTEG/aUI0/di5X 89hnsjncc1mJlfL5eCRlN5dv+9iBrUb9dN+qcv/I0/NzFfUEb0R56AWMdrdGeASvgyoPNXsYU/6 /hiNMrsaqxvm4mvZnIqC70JLqW9Dv X-Received: by 2002:a05:6402:440c:b0:43a:1124:e56a with SMTP id y12-20020a056402440c00b0043a1124e56amr44852793eda.134.1662391646401; Mon, 05 Sep 2022 08:27:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BS5DNOpTRPfqGzZykMKxlBAlMPKYg+ROhMX68+pN9BWH3v/YckKemYfM6AbpZZ05FOv8u2A== X-Received: by 2002:a05:6402:440c:b0:43a:1124:e56a with SMTP id y12-20020a056402440c00b0043a1124e56amr44852783eda.134.1662391646266; Mon, 05 Sep 2022 08:27:26 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id bv6-20020a170906b1c600b00730979f568fsm5145387ejb.150.2022.09.05.08.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:25 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 1/7] drm/arm/hdlcd: use drmm_* to allocate driver structures Date: Mon, 5 Sep 2022 17:27:13 +0200 Message-Id: <20220905152719.128539-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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/hdlcd_drv.c | 12 ++++-------- drivers/gpu/drm/arm/hdlcd_drv.h | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c index a032003c340c..463381d11cff 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.c +++ b/drivers/gpu/drm/arm/hdlcd_drv.c @@ -247,13 +247,11 @@ static int hdlcd_drm_bind(struct device *dev) struct hdlcd_drm_private *hdlcd; int ret; - hdlcd = devm_kzalloc(dev, sizeof(*hdlcd), GFP_KERNEL); - if (!hdlcd) - return -ENOMEM; + hdlcd = devm_drm_dev_alloc(dev, &hdlcd_driver, typeof(*hdlcd), base); + if (IS_ERR(hdlcd)) + return PTR_ERR(hdlcd); - drm = drm_dev_alloc(&hdlcd_driver, dev); - if (IS_ERR(drm)) - return PTR_ERR(drm); + drm = &hdlcd->base; drm->dev_private = hdlcd; dev_set_drvdata(dev, drm); @@ -319,7 +317,6 @@ static int hdlcd_drm_bind(struct device *dev) err_free: drm_mode_config_cleanup(drm); dev_set_drvdata(dev, NULL); - drm_dev_put(drm); return ret; } @@ -344,7 +341,6 @@ static void hdlcd_drm_unbind(struct device *dev) drm_mode_config_cleanup(drm); drm->dev_private = NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); } static const struct component_master_ops hdlcd_master_ops = { diff --git a/drivers/gpu/drm/arm/hdlcd_drv.h b/drivers/gpu/drm/arm/hdlcd_drv.h index 909c39c28487..3892b36767ac 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.h +++ b/drivers/gpu/drm/arm/hdlcd_drv.h @@ -7,6 +7,7 @@ #define __HDLCD_DRV_H__ struct hdlcd_drm_private { + struct drm_device base; void __iomem *mmio; struct clk *clk; struct drm_crtc crtc; From patchwork Mon Sep 5 15:27:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966293 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 40EB1ECAAD5 for ; Mon, 5 Sep 2022 15:27:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DDED110EA42; Mon, 5 Sep 2022 15:27:37 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB9D410EA42 for ; Mon, 5 Sep 2022 15:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391653; 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=zE4vp0voY9uQjkQjmHJf9kE7FYAP7kTVaTS+8HIh/tE=; b=c7voO7PQ8RutlxfidzRWTZUHX0fHHSVmYnF+lgswFoKlCo8XE91h5babZROBtf/VlwdlB2 gwWApr2/xTInOh/59muX34GQ6MwLTrsw9rcyLg8O7JzJOb3CLcgiTmSUm3RUQu1A9UWfS4 vWx2LwIOn06wKNApOb70/9s8vJvcnu4= 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-421-xPoklLLCO1WKt42_b5QLNA-1; Mon, 05 Sep 2022 11:27:30 -0400 X-MC-Unique: xPoklLLCO1WKt42_b5QLNA-1 Received: by mail-ed1-f70.google.com with SMTP id h6-20020aa7de06000000b004483647900fso6055019edv.21 for ; Mon, 05 Sep 2022 08:27:30 -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=zE4vp0voY9uQjkQjmHJf9kE7FYAP7kTVaTS+8HIh/tE=; b=PESeLdYqpy6445GD57+wtzPgItAsm65WZ+QGYcrUZrw54cJxKuVQD93yyXvNG4x5BA V1JXcoMkYJiwGqU5xgYB/q07Nb7/6jcdWhNoAZ2zTligraQ7Cvdlk1sHktW03LzGsXbo dVjS6NO9c+ETsmOjWpOIqSVm7/ev0ui1cxxExXGf7bWjt1gWwMAr8cEoWI0izPqasePi 16gULvGcgq7G37lVeInjlfYPG1q7o5iJCwgFKbFZs0o5f44K6L5RZQWmj65WJh3HiH2Y nV4CBmUejPIw2uH1V1Pb851teNjK5gHqGQ4N3dIF7azhsvOhS+RbDhviMqLDr8e1/Quz Gxpw== X-Gm-Message-State: ACgBeo36wQflh/lOR+f5fDitiljzlTK6/260skA20AKMsqlm7XEU2gIb qPTo0/75MWkDuHw/dTy0Erd+SU6c256l3uwszFCFS3/L4jNgNbSHaz0scs7MRJaQpklwkPdckO3 lapZ7uF0dk9TZPvWqzjMF4GNEA40Y X-Received: by 2002:aa7:da4f:0:b0:44e:864b:7a3e with SMTP id w15-20020aa7da4f000000b0044e864b7a3emr4580106eds.378.1662391649844; Mon, 05 Sep 2022 08:27:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR6eRsPqq50yL4Usg2GYEpC6XNwnbZmH47/muJMsQlX5hbTFYfwGVLWm+eOrwjh1/5M41p1CXw== X-Received: by 2002:aa7:da4f:0:b0:44e:864b:7a3e with SMTP id w15-20020aa7da4f000000b0044e864b7a3emr4580090eds.378.1662391649693; Mon, 05 Sep 2022 08:27:29 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id 8-20020a170906308800b0073d60922edfsm2895178ejv.102.2022.09.05.08.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:29 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 2/7] drm/arm/hdlcd: replace drm->dev_private with drm_to_hdlcd_priv() Date: Mon, 5 Sep 2022 17:27:14 +0200 Message-Id: <20220905152719.128539-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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 hdlcd_drm_private, hence we can use container_of() to get the struct drm_device instance instead. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/hdlcd_crtc.c | 4 ++-- drivers/gpu/drm/arm/hdlcd_drv.c | 10 ++++------ drivers/gpu/drm/arm/hdlcd_drv.h | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index 7030339fa232..4a8959d0b2a6 100644 --- a/drivers/gpu/drm/arm/hdlcd_crtc.c +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c @@ -275,7 +275,7 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane, dest_h = drm_rect_height(&new_plane_state->dst); scanout_start = drm_fb_dma_get_gem_addr(fb, new_plane_state, 0); - hdlcd = plane->dev->dev_private; + hdlcd = drm_to_hdlcd_priv(plane->dev); hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, fb->pitches[0]); hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, fb->pitches[0]); hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1); @@ -325,7 +325,7 @@ static struct drm_plane *hdlcd_plane_init(struct drm_device *drm) int hdlcd_setup_crtc(struct drm_device *drm) { - struct hdlcd_drm_private *hdlcd = drm->dev_private; + struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); struct drm_plane *primary; int ret; diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c index 463381d11cff..120c87934a91 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.c +++ b/drivers/gpu/drm/arm/hdlcd_drv.c @@ -98,7 +98,7 @@ static void hdlcd_irq_uninstall(struct hdlcd_drm_private *hdlcd) static int hdlcd_load(struct drm_device *drm, unsigned long flags) { - struct hdlcd_drm_private *hdlcd = drm->dev_private; + struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); struct platform_device *pdev = to_platform_device(drm->dev); struct resource *res; u32 version; @@ -190,7 +190,7 @@ static int hdlcd_show_underrun_count(struct seq_file *m, void *arg) { struct drm_info_node *node = (struct drm_info_node *)m->private; struct drm_device *drm = node->minor->dev; - struct hdlcd_drm_private *hdlcd = drm->dev_private; + struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); seq_printf(m, "underrun : %d\n", atomic_read(&hdlcd->buffer_underrun_count)); seq_printf(m, "dma_end : %d\n", atomic_read(&hdlcd->dma_end_count)); @@ -203,7 +203,7 @@ static int hdlcd_show_pxlclock(struct seq_file *m, void *arg) { struct drm_info_node *node = (struct drm_info_node *)m->private; struct drm_device *drm = node->minor->dev; - struct hdlcd_drm_private *hdlcd = drm->dev_private; + struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); unsigned long clkrate = clk_get_rate(hdlcd->clk); unsigned long mode_clock = hdlcd->crtc.mode.crtc_clock * 1000; @@ -253,7 +253,6 @@ static int hdlcd_drm_bind(struct device *dev) drm = &hdlcd->base; - drm->dev_private = hdlcd; dev_set_drvdata(dev, drm); hdlcd_setup_mode_config(drm); @@ -324,7 +323,7 @@ static int hdlcd_drm_bind(struct device *dev) static void hdlcd_drm_unbind(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct hdlcd_drm_private *hdlcd = drm->dev_private; + struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); drm_dev_unregister(drm); drm_kms_helper_poll_fini(drm); @@ -339,7 +338,6 @@ static void hdlcd_drm_unbind(struct device *dev) pm_runtime_disable(dev); of_reserved_mem_device_release(dev); drm_mode_config_cleanup(drm); - drm->dev_private = NULL; dev_set_drvdata(dev, NULL); } diff --git a/drivers/gpu/drm/arm/hdlcd_drv.h b/drivers/gpu/drm/arm/hdlcd_drv.h index 3892b36767ac..f1c1da2ac2db 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.h +++ b/drivers/gpu/drm/arm/hdlcd_drv.h @@ -21,6 +21,7 @@ struct hdlcd_drm_private { #endif }; +#define drm_to_hdlcd_priv(x) container_of(x, struct hdlcd_drm_private, base) #define crtc_to_hdlcd_priv(x) container_of(x, struct hdlcd_drm_private, crtc) static inline void hdlcd_write(struct hdlcd_drm_private *hdlcd, From patchwork Mon Sep 5 15:27:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966294 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 245B2ECAAD5 for ; Mon, 5 Sep 2022 15:27:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 444A610EA46; Mon, 5 Sep 2022 15:27:41 +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 20FB910EA42 for ; Mon, 5 Sep 2022 15:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391655; 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=7wDtbQGLiE39PVFtlUhXuYz+XJ8dWxVCvJywCPPxRNQ=; b=ORGLURHj/wLhnIW5StgTZzoLEbWEpRhvkz7zT8C5nVW3Oi1sVOljI/6AcTbPM/AZEEoA/B Ivs542Wt9jioUp5dxVuOQIhR7DcpJxe6xD7XF+V4xMidfxMPZNBruJwC/5ggdY5E2j7J05 JuOf0vJfWXks+5dFLDiGXBWJP6xV/vk= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-510-wjxcugNHMd2gFjV3ABB0Qw-1; Mon, 05 Sep 2022 11:27:34 -0400 X-MC-Unique: wjxcugNHMd2gFjV3ABB0Qw-1 Received: by mail-ej1-f72.google.com with SMTP id dr17-20020a170907721100b00741a1ef8a20so2464466ejc.0 for ; Mon, 05 Sep 2022 08:27:34 -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=7wDtbQGLiE39PVFtlUhXuYz+XJ8dWxVCvJywCPPxRNQ=; b=N0BnVX6JfzCQC/VmgE4zNq78/HCtlXEY9pdIl228muuH7P/QlYspr8GasfkZoEiBnA Orgdv7Te4SE9hV5lg0uQnUWpncI6Klhprr4Sh4DodLAcOJ7kYLGHKWpeByicP6fu4Pg1 fujlhbtVjThK/kux6sSgM4rl5vO62NfCCXfZHjivxJuKzmcoXnS4zDhAQ7UkRMwhR73j SEEACfJ5L97jz9QdfmRQZIDQCnDplwIC+7Tm7NGzPPS2g5etgz9KOCVOnuFOCGjxYxyY Yqg/I73NigqIKJvAZQXY/EiUBRh4OQTviCwN3lFrLAtV9w2o9oBG1roN6yZrqnyNScAT OlkA== X-Gm-Message-State: ACgBeo2mIgEylt4KKrRSgcOG9UpdbgXUIZb/nkCd1CUo+eg7NvdUtZL4 lXH5LRGj/lwtCAKFp2xJuutkeKpUEpez6wElE+dxXh7cDCt8YXD91mPPjihlbuRyYHmrcZGmahz GFO52wtkewmE/KR3L090kGJTFYEkt X-Received: by 2002:a17:907:a427:b0:761:2bd0:3e72 with SMTP id sg39-20020a170907a42700b007612bd03e72mr6872896ejc.346.1662391653348; Mon, 05 Sep 2022 08:27:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR5+7yZe7QTs81r9HK652dKS4RqWWeQcqNFOZjjgqfsu9vjr6GJZS80WRbgfEaB3pVKfT3aG+A== X-Received: by 2002:a17:907:a427:b0:761:2bd0:3e72 with SMTP id sg39-20020a170907a42700b007612bd03e72mr6872882ejc.346.1662391653085; Mon, 05 Sep 2022 08:27:33 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id i23-20020aa7c9d7000000b0044e7d69091asm2418412edt.85.2022.09.05.08.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:32 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 3/7] drm/arm/hdlcd: crtc: use drmm_crtc_init_with_planes() Date: Mon, 5 Sep 2022 17:27:15 +0200 Message-Id: <20220905152719.128539-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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 drm_crtc_cleanup() call. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/arm/hdlcd_crtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index 4a8959d0b2a6..c0a5ca7f578a 100644 --- a/drivers/gpu/drm/arm/hdlcd_crtc.c +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c @@ -42,7 +42,6 @@ static void hdlcd_crtc_cleanup(struct drm_crtc *crtc) /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); - drm_crtc_cleanup(crtc); } static int hdlcd_crtc_enable_vblank(struct drm_crtc *crtc) @@ -333,8 +332,8 @@ int hdlcd_setup_crtc(struct drm_device *drm) if (IS_ERR(primary)) return PTR_ERR(primary); - ret = drm_crtc_init_with_planes(drm, &hdlcd->crtc, primary, NULL, - &hdlcd_crtc_funcs, NULL); + ret = drmm_crtc_init_with_planes(drm, &hdlcd->crtc, primary, NULL, + &hdlcd_crtc_funcs, NULL); if (ret) return ret; From patchwork Mon Sep 5 15:27:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966297 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 03ADFECAAD5 for ; Mon, 5 Sep 2022 15:27:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 795C910EA47; Mon, 5 Sep 2022 15:27:52 +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 A5C4310EA44 for ; Mon, 5 Sep 2022 15:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391658; 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=NEM+8qA1l934tBlwuTsd8qBaVhltlHSYDFpUMi13koI=; b=Zj+un6D/xc3HOI0QjcuAEn3gSqGK9mivVOY6lmGf97Jjawrr4UcT/feqMJdAAOm5lucxF1 bqbTRmHH6oMVbUQdX/Wd78XmrUFKqpQdFpzzF4dmkB5z1/jGOk1SEwjXxu7UEzOfJ1voOE XPX0b5KtQhR4Y47tj+l3jcSnFG8j6RI= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-18-d5YHdsuGNIeQh5iv7KWGIQ-1; Mon, 05 Sep 2022 11:27:37 -0400 X-MC-Unique: d5YHdsuGNIeQh5iv7KWGIQ-1 Received: by mail-ej1-f72.google.com with SMTP id jg40-20020a170907972800b0074148cdc7baso2446781ejc.12 for ; Mon, 05 Sep 2022 08:27:37 -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=NEM+8qA1l934tBlwuTsd8qBaVhltlHSYDFpUMi13koI=; b=lpgQ+P28BsLvev0lOaQlMuA7OG2m2vHcKPUwzJXwdSbowuWyG10rAmvXtlg59fFRhF iKFpSlL7+XkC1ULddVI0Y9kRiKEd/7j+vCVJFhwZcw+xqz1OJCMhOKT5Jp3jB+KtlOWu cTGcywMcnWZ3gINu6eNEhMitz53P6p45LLfak2dmHRwuFoILNR5EsH4F78ytYSRl2HB0 /gw7rbaP+x9W6ZC4sYKZaoDl9ND/pUOq9DDx0J7iVIhmgCjL7CvCZn0EZEL00idnYYYg +bxllvPT3qBojy4lIUbM4FuMlpy6OcG9t8U8KS+J6trSyi567CH7yL69k1Mib/1G5Qe9 LRTA== X-Gm-Message-State: ACgBeo1V2kyn4NM7EXVHmTedrm0RG2qiidhWX7kkeWpBNRXxMFlbVsul U35Sp7R2E7c8UwEMivMflpGjnMtklTZIRq352jggWTK3VD6GEhHggk3k0tLQKKGT6wVYja+6rNc s5KTM0qVWcQLfFsFLog6tdWciEJcF X-Received: by 2002:a17:907:2bce:b0:73d:dd00:9ced with SMTP id gv14-20020a1709072bce00b0073ddd009cedmr33121654ejc.739.1662391656689; Mon, 05 Sep 2022 08:27:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ZkK+8F2F9/wkZzegh9qRMurglKs44lIEA7p306fDAZ+htrVC8A6RHorF7fdbKZuptgiaRlA== X-Received: by 2002:a17:907:2bce:b0:73d:dd00:9ced with SMTP id gv14-20020a1709072bce00b0073ddd009cedmr33121642ejc.739.1662391656544; Mon, 05 Sep 2022 08:27:36 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id kw19-20020a170907771300b0073c5192cba6sm5175398ejc.114.2022.09.05.08.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:36 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 4/7] drm/arm/hdlcd: plane: use drm managed resources Date: Mon, 5 Sep 2022 17:27:16 +0200 Message-Id: <20220905152719.128539-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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/hdlcd_crtc.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index c0a5ca7f578a..17d3ccf12245 100644 --- a/drivers/gpu/drm/arm/hdlcd_crtc.c +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c @@ -289,7 +289,6 @@ static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs = { static const struct drm_plane_funcs hdlcd_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, - .destroy = drm_plane_cleanup, .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, @@ -297,24 +296,19 @@ static const struct drm_plane_funcs hdlcd_plane_funcs = { static struct drm_plane *hdlcd_plane_init(struct drm_device *drm) { - struct hdlcd_drm_private *hdlcd = drm->dev_private; + struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); struct drm_plane *plane = NULL; u32 formats[ARRAY_SIZE(supported_formats)], i; - int ret; - - plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL); - if (!plane) - return ERR_PTR(-ENOMEM); for (i = 0; i < ARRAY_SIZE(supported_formats); i++) formats[i] = supported_formats[i].fourcc; - ret = drm_universal_plane_init(drm, plane, 0xff, &hdlcd_plane_funcs, - formats, ARRAY_SIZE(formats), - NULL, - DRM_PLANE_TYPE_PRIMARY, NULL); - if (ret) - return ERR_PTR(ret); + plane = drmm_universal_plane_alloc(drm, struct drm_plane, dev, 0xff, + &hdlcd_plane_funcs, + formats, ARRAY_SIZE(formats), + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); + if (IS_ERR(plane)) + return plane; drm_plane_helper_add(plane, &hdlcd_plane_helper_funcs); hdlcd->plane = plane; From patchwork Mon Sep 5 15:27:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966296 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 E64F7ECAAD5 for ; Mon, 5 Sep 2022 15:27:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BBC9610EA48; Mon, 5 Sep 2022 15:27:50 +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 275B110EA48 for ; Mon, 5 Sep 2022 15:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391662; 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=AFFGKxt+Rynb6H3rLFquNUiuipOW4GaSN2+USkzDWw0=; b=OQGS6E2iiktVnwMjtGKxnfsnlF9CsTGXjL8VNH/Hll27yO+teJ9B3OiytEzhIUtDWk4JqI x4yUURIMRAW9qVhTMUyTaE0q7zLYr3lAknVAreVbfsE0NhsjDymeVxKG7IN3Ay3nRbVmzR jkE76ILt+EyvscQv7WHv9icQ13PJ9QI= 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-524-VD8NtoS3Oqi-gNQEpNzjjg-1; Mon, 05 Sep 2022 11:27:41 -0400 X-MC-Unique: VD8NtoS3Oqi-gNQEpNzjjg-1 Received: by mail-ed1-f72.google.com with SMTP id y12-20020a056402358c00b00448898f1c33so5926283edc.7 for ; Mon, 05 Sep 2022 08:27:41 -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=AFFGKxt+Rynb6H3rLFquNUiuipOW4GaSN2+USkzDWw0=; b=m2HNbjSXBqwk5WOLjQxFoYlvmhk1TyXsKDq6aY+EqZHgiHWgGeK2GoohXFg4U0PzG/ /AyBpGq/NNGXgI5KupAFkNohn76t3b5nIV1440kG/t+0O/ATqNtRhZvF4wuHCIG00fJ/ msono7CRU0Ku4JazIp9iUJIU4AFtP1CMdIdled5/1N5PlVbtCldjrYOfcq1RyE/isa/3 xipz0iFWUqVuaP1Vae0rY5IkvHtm3tllxsLXMAdeRECGdmlCylE0vjSFIp2L1bmzjEoG XVoxe9U7/rimjqoengNGOJh2t6Vwlhk7vjwvqe4bUMiq85x1/rN1UFKpmBWAI6mQ9vA/ SL2w== X-Gm-Message-State: ACgBeo22DLlXdUKDhOJXDWS9SHzoDABeMubipYoacBmr8W5lQuu5zHkK DosTduQcJ4KyKwxX+ZaDwZ14Oz9ZxiafdUh699SwCedm+Ts4hiHvNX4Yl92o6uFjvBMOPDRuGOv aC6592rMcBt98C4EZ7+vHusO47NFG X-Received: by 2002:a17:907:1c89:b0:741:4453:75be with SMTP id nb9-20020a1709071c8900b00741445375bemr30493942ejc.208.1662391660391; Mon, 05 Sep 2022 08:27:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6WM2uFwG2RTEDgKoROw3MIJz+VXV9au2IY/ThjnrDXlkgsiZ2ds5tMDggnRKnnGCTJfkxepA== X-Received: by 2002:a17:907:1c89:b0:741:4453:75be with SMTP id nb9-20020a1709071c8900b00741445375bemr30493926ejc.208.1662391660199; Mon, 05 Sep 2022 08:27:40 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id i10-20020a170906264a00b0073cf8e0355fsm5034306ejc.208.2022.09.05.08.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:39 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 5/7] drm/arm/hdlcd: use drm_dev_unplug() Date: Mon, 5 Sep 2022 17:27:17 +0200 Message-Id: <20220905152719.128539-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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/hdlcd_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c index 120c87934a91..e41def6d47cc 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.c +++ b/drivers/gpu/drm/arm/hdlcd_drv.c @@ -325,7 +325,7 @@ static void hdlcd_drm_unbind(struct device *dev) struct drm_device *drm = dev_get_drvdata(dev); struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); - drm_dev_unregister(drm); + drm_dev_unplug(drm); drm_kms_helper_poll_fini(drm); component_unbind_all(dev, drm); of_node_put(hdlcd->crtc.port); From patchwork Mon Sep 5 15:27:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966298 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 1C050ECAAD3 for ; Mon, 5 Sep 2022 15:28:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0FD6610EA49; Mon, 5 Sep 2022 15:28:03 +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 D8BE010EA39 for ; Mon, 5 Sep 2022 15:27:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391666; 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=dLZfq6WypLg+PIKaSCfWFhdUOS8zDvxPUxnHNhKzURQ=; b=KTibtTdDMh0k3O5I6BDVWjcnhoMMZUDgQRnmlbHzxfCAn/oWdPHlDcPEUincSvJblTak8C GSiiEnMLXYLcIDp51dPfY4+FsvIZhjzXLrBBDHgRjhCvRpKNLER00ywJl+hKXSH6jUMLbj umtCByAr2oZwcwgzYm9rTCSGQBEumdo= 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-669-6IWnVbP5O-qiipUXP1CZSg-1; Mon, 05 Sep 2022 11:27:45 -0400 X-MC-Unique: 6IWnVbP5O-qiipUXP1CZSg-1 Received: by mail-ed1-f69.google.com with SMTP id r11-20020a05640251cb00b004484ec7e3a4so5960863edd.8 for ; Mon, 05 Sep 2022 08:27:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=dLZfq6WypLg+PIKaSCfWFhdUOS8zDvxPUxnHNhKzURQ=; b=zOjKAMtFlANKVVqAxEV3WYSWIkrpNAuTXjl6SmV0FRSUNtR7rpGnvuKYKlpP1ZWzyt 5t6T7rE4CFMzrtElddofm5Rf6b4F4QB54XekEENYRgUW2/CjDgdIK5KUXZckNKbEvv7J lPap71iZWoQD5OvqMAYhmX293ZaraouwXhe9V+tHZiJ6Hl4hauaLliwC+H6whxTCTDBP gSvQATCmrigdOjZ/EoR9WsxCACHqtWSX46nH9OYREWT/jWMWdU4TTOLBz1GbLn8J/mRl x9WT0TpPjvwYoBaRP3oAxzeDHKgjApUQFIYCj2HgjxpLVfaavnU4qI4scGTkdA8lNvSe h5fQ== X-Gm-Message-State: ACgBeo1Th7mXyjHz+N3KkOTamWNd5Cjy05M/bH74KJfsryXjtZh1zJHC Y3lOwX4PAKfVJSu5C9mvRGhPWiDgQkL/7iiThq8NpBmmbb8C6F71dey24/DEqBx7r3Nm2kBVDQ1 eINRkrccGShfj/HUkLcnUin5VZFjf X-Received: by 2002:a17:907:c14:b0:741:6823:11c with SMTP id ga20-20020a1709070c1400b007416823011cmr27662849ejc.295.1662391663858; Mon, 05 Sep 2022 08:27:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dwJv7NiLCGz84YQfyCvg+ySl/SBl/OUwxr1LnrBoTmR9wUNpbaUemop0pEzd67X8DZyHo7A== X-Received: by 2002:a17:907:c14:b0:741:6823:11c with SMTP id ga20-20020a1709070c1400b007416823011cmr27662833ejc.295.1662391663684; Mon, 05 Sep 2022 08:27:43 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id t19-20020a1709067c1300b00730b61d8a5esm5206061ejo.61.2022.09.05.08.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:43 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 6/7] drm/arm/hdlcd: crtc: protect device resources after removal Date: Mon, 5 Sep 2022 17:27:18 +0200 Message-Id: <20220905152719.128539-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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/hdlcd_crtc.c | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index 17d3ccf12245..bfc42d4a53c2 100644 --- a/drivers/gpu/drm/arm/hdlcd_crtc.c +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -39,27 +40,47 @@ static void hdlcd_crtc_cleanup(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); + + drm_dev_exit(idx); } static int hdlcd_crtc_enable_vblank(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); - unsigned int mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); + unsigned int mask; + int idx; + if (!drm_dev_enter(crtc->dev, &idx)) + return -ENODEV; + + mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask | HDLCD_INTERRUPT_VSYNC); + drm_dev_exit(idx); + return 0; } static void hdlcd_crtc_disable_vblank(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); - unsigned int mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); + unsigned int mask; + int idx; + if (!drm_dev_enter(crtc->dev, &idx)) + return; + + mask = hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask & ~HDLCD_INTERRUPT_VSYNC); + + drm_dev_exit(idx); } static const struct drm_crtc_funcs hdlcd_crtc_funcs = { @@ -170,21 +191,33 @@ static void hdlcd_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; clk_prepare_enable(hdlcd->clk); hdlcd_crtc_mode_set_nofb(crtc); hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 1); drm_crtc_vblank_on(crtc); + + drm_dev_exit(idx); } static void hdlcd_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; drm_crtc_vblank_off(crtc); hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); clk_disable_unprepare(hdlcd->clk); + + drm_dev_exit(idx); } static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, @@ -192,6 +225,10 @@ static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); long rate, clk_rate = mode->clock * 1000; + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return MODE_NOCLOCK; rate = clk_round_rate(hdlcd->clk, clk_rate); /* 0.1% seems a close enough tolerance for the TDA19988 on Juno */ @@ -200,6 +237,8 @@ static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, return MODE_NOCLOCK; } + drm_dev_exit(idx); + return MODE_OK; } @@ -267,6 +306,10 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane, struct hdlcd_drm_private *hdlcd; u32 dest_h; dma_addr_t scanout_start; + int idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; if (!fb) return; @@ -279,6 +322,8 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane, hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, fb->pitches[0]); hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1); hdlcd_write(hdlcd, HDLCD_REG_FB_BASE, scanout_start); + + drm_dev_exit(idx); } static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs = { From patchwork Mon Sep 5 15:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12966299 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 269D4ECAAD3 for ; Mon, 5 Sep 2022 15:28:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0070610EA52; Mon, 5 Sep 2022 15:28:08 +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 2E14F10EA47 for ; Mon, 5 Sep 2022 15:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662391669; 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=0y/a4pTSF6VtadOpwMNTC/mvZDJbVIcTrD8TXNTMH9w=; b=gSkkW/dRfqmcU0BN8gL6XM6+eNNMLiwUhiVNAXYkagIB/iMZeABBkjoyn4zyug2rBnWHL6 C1evmdBPYJXRVqmdbIoIfL9I0/EV7h4JyZKXYo7YoQfyWPSfBpFnRY7ed5OPHDQRtUfHq4 JEy/9JaaTtjgIhFNw6cOkK1oKo9cEh8= 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-175-YbE-E2mDND-JuoWHXTBlhQ-1; Mon, 05 Sep 2022 11:27:48 -0400 X-MC-Unique: YbE-E2mDND-JuoWHXTBlhQ-1 Received: by mail-ed1-f69.google.com with SMTP id f9-20020a056402354900b0044e0ea9eb2dso2993634edd.1 for ; Mon, 05 Sep 2022 08:27:48 -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=0y/a4pTSF6VtadOpwMNTC/mvZDJbVIcTrD8TXNTMH9w=; b=fa5RtwV3S+jQDMNdI6VGvi+ut2oDHZOh0V7tJ+05O2rxcCddXW5lpV0sErH9PoSAyD +AHI15zl3s0LiCgwQ7spM3NcIYbbsAXW6EgFINU5FEZhNHO+ADWcyEUdtOqm547XNEqK VDzZN7arV2LFVvqDHeT891oKJdnXzT+BKn79r1ZS2glscx1OVNS8ms+TNWRLOEyAg3fW Jdi27kpxOOVBseFNYaHwvQEl4ZitjwNw7Ul/ruU2U7N86L0L/wnLD/pvP+OWU1AbjQHt aQzr0D50FmcAgCVGSmyQGIT840mtnLvMFfIBV8+Nbs0+qpCna7rapLtAEjuzBOlkyJHQ GLaA== X-Gm-Message-State: ACgBeo07WxdpkKmQRey7aWNxm8ml1sS6drnHr4JQhwTRx6ZVX4AmMSvz SLDzsFjwCoJRl3hJwJWB13YKGpZ83MDg4OnQ/iA+5BNmU9isMTrt8tInhiQNueS4jOynMWUirDm HNMilEe/GtI6XdVlqD13TQHpghgNT X-Received: by 2002:a17:907:2c44:b0:741:5173:8082 with SMTP id hf4-20020a1709072c4400b0074151738082mr27811200ejc.428.1662391667248; Mon, 05 Sep 2022 08:27:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KUF8JbNYhrJVPVL+fNpO9wlbYaKNx1Fi+IP83CtCcvsAKUfVUGf8JgD4mpG+Mk8t00cPgUg== X-Received: by 2002:a17:907:2c44:b0:741:5173:8082 with SMTP id hf4-20020a1709072c4400b0074151738082mr27811186ejc.428.1662391667099; Mon, 05 Sep 2022 08:27:47 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id b10-20020a056402138a00b0044e81203bebsm2338949edv.31.2022.09.05.08.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:27:46 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH RESEND drm-misc-next 7/7] drm/arm/hdlcd: debugfs: protect device resources after removal Date: Mon, 5 Sep 2022 17:27:19 +0200 Message-Id: <20220905152719.128539-8-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220905152719.128539-1-dakr@redhat.com> References: <20220905152719.128539-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/hdlcd_drv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c index e41def6d47cc..020c7d0c70a5 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.c +++ b/drivers/gpu/drm/arm/hdlcd_drv.c @@ -204,11 +204,19 @@ static int hdlcd_show_pxlclock(struct seq_file *m, void *arg) struct drm_info_node *node = (struct drm_info_node *)m->private; struct drm_device *drm = node->minor->dev; struct hdlcd_drm_private *hdlcd = drm_to_hdlcd_priv(drm); - unsigned long clkrate = clk_get_rate(hdlcd->clk); - unsigned long mode_clock = hdlcd->crtc.mode.crtc_clock * 1000; + unsigned long clkrate, mode_clock; + int idx; + + if (!drm_dev_enter(drm, &idx)) + return -ENODEV; + + clkrate = clk_get_rate(hdlcd->clk); + mode_clock = hdlcd->crtc.mode.crtc_clock * 1000; seq_printf(m, "hw : %lu\n", clkrate); seq_printf(m, "mode: %lu\n", mode_clock); + + drm_dev_exit(idx); return 0; }