From patchwork Sat Oct 1 01:18:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996253 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 5F0DBC433FE for ; Sat, 1 Oct 2022 01:19:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8D9EA10EDF7; Sat, 1 Oct 2022 01:19:18 +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 E65C810EDF7 for ; Sat, 1 Oct 2022 01:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587155; 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=fLaZVg/Gn3THIn1ghLrf5MedEqRFiq/AUqXfvtIcrvk=; b=PaDP/rAwA1usCWsU8HRj0xQ7xc2MvInSxOsyV5d3P2mqZGp559cqNNnUx8e7f69kzD6rKa CApjCE8CexCAXTBmZ7ouNd0avIp3tQPvQiE8XIb2KGb8Ef8NskmOQzQ83ElIN2v3rofg/w JtqvSCj2SJPIruO16omxam2yiG6xn1g= 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-556-PTdE3r_5OoC6AV2878UA-w-1; Fri, 30 Sep 2022 21:19:14 -0400 X-MC-Unique: PTdE3r_5OoC6AV2878UA-w-1 Received: by mail-ed1-f71.google.com with SMTP id y14-20020a056402440e00b0044301c7ccd9so4618622eda.19 for ; Fri, 30 Sep 2022 18:19:13 -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=fLaZVg/Gn3THIn1ghLrf5MedEqRFiq/AUqXfvtIcrvk=; b=ujm4jhwTgmbMj+1gJVElEDku8leqnTECo8F04AOJdogY22pDQbIcqdAy4Lh2x080jl bDe/EqedDS2d09InrP0bDAAsPKSUR4uXzOjP9YKrrtL4kk04yxMjFhnWCbDIY2T9Wf/f FDXjZmihwAPBpNEIh/Q6eqL/HynVdemYykX4zgt5I/ijw7pSRuYfwopX6sm1BZZiFAum +8TE2yFKPvsB49jNqwe/sz2tXU2Udg3gS4p2aTVZqZez+nqHTGM1SltbvXSuviq/xddO tYsV36+GRce9x/R2h2371BWlYIKMvClX0EsHPkLnmYuFmmTg4enBgf7LFavuxscZNAwH 3y1g== X-Gm-Message-State: ACrzQf3Sji0AHXX+WgRtNd6RQKsNGbAzfAPk9+m6fp/UbdbDJyhF3Frw lHfn+F/WI+KNFPE//7XhT/LbtJxsnW7HgOdbK7hXRBH/3JgQdWuDtOtUkLpzeW5uLnpI/8TM8lq NwhktdhRxT73VD4Z7ORPmPuSCspgK X-Received: by 2002:a17:907:8a23:b0:782:6a5:6dd5 with SMTP id sc35-20020a1709078a2300b0078206a56dd5mr7966642ejc.581.1664587152866; Fri, 30 Sep 2022 18:19:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78eXx11AzAz/KYCu4ClVlwjL9PudeR4cdFQOhob9od/+BuIzr8TrZGeicdldxZ/IHZxleCMg== X-Received: by 2002:a17:907:8a23:b0:782:6a5:6dd5 with SMTP id sc35-20020a1709078a2300b0078206a56dd5mr7966632ejc.581.1664587152705; Fri, 30 Sep 2022 18:19:12 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id g18-20020a17090604d200b007822196378asm1934302eja.176.2022.09.30.18.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:12 -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 v3 1/7] drm/arm/hdlcd: use drmm_* to allocate driver structures Date: Sat, 1 Oct 2022 03:18:59 +0200 Message-Id: <20221001011905.433408-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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 Sat Oct 1 01:19:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996254 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 095E5C433FE for ; Sat, 1 Oct 2022 01:19:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C85B10EDF8; Sat, 1 Oct 2022 01:19:25 +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 8BE6810EDF8 for ; Sat, 1 Oct 2022 01:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587160; 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=yZIl1OKGrL3KJyd7ruXlclzCfjtYvrZNcDLCxG8/BBY=; b=EDLPTQmodbfAArFjc5sAGLdBgzo8XWfKeK+NKs3ti6I8GovllBtTvzvlzME+697KweWd27 fdEkPHyOYiWHxZAtZFbFDDOiYZ6PDlCF3usfF+VQzsey0v25j8ANlFGLyZ57Y/NvrKUytS pG+MI09D9uVbt1P8Brmy3oU8cjrpL/0= 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-28-lJ-379TOP064DW9AwC3Kyw-1; Fri, 30 Sep 2022 21:19:17 -0400 X-MC-Unique: lJ-379TOP064DW9AwC3Kyw-1 Received: by mail-ed1-f72.google.com with SMTP id r11-20020a05640251cb00b004516feb8c09so4633680edd.10 for ; Fri, 30 Sep 2022 18:19:17 -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=yZIl1OKGrL3KJyd7ruXlclzCfjtYvrZNcDLCxG8/BBY=; b=p+aDQBpNHX+DfR9VbpslClMsd7UvF9coP9Ms2F4CUDqDSd6YqkOI/edxYvsumAPLx0 GTyEKIwQ1QzYqMSh9etP8g1GWdCkFy3HHq2QM70TPZnCj6LjvnPN957NoxeUG3+IWgqs CvCmYiUu9nGbPV+Kr6EcopCf8+Zmg6YGuQQGLL3JAsV6eB8fTRSHFq84iJNJTmBjX4D/ i+c/PvFe8Fu5agi1DM9r2qrYgtCitSjn/ZU/516LGA1Sl3GiEsu5EqnuUiBFbp6DiFdV cuaePULTY3avFyybWvQKrnC+lxMgLjdRH/tFSAISCBg2qUmWupyrbSF5RhfUsbPJgOg9 6wWw== X-Gm-Message-State: ACrzQf2AH6V/VCU+m0y0mQm93MvRxGVSARoNcKrftNiW1qqdH9dZueeK 4yTGYjCz1vcl+9Rt58yNLBFXs1Szuuo2d1daiLZglj4hIU/5c2Ef90VY1GZzabhdNgPgK/E48eS sPpm+kSgYOUcelBjdCPnAh/IscKV5 X-Received: by 2002:a17:907:a044:b0:770:da0d:171d with SMTP id gz4-20020a170907a04400b00770da0d171dmr7828110ejc.742.1664587156484; Fri, 30 Sep 2022 18:19:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4eBxmC9x/tkFzxVy0Ywf9ks7MiJUJ5b/u5kQtcjdJwQnAOGv3FCHcSaFJN6022V7sq0e0VMg== X-Received: by 2002:a17:907:a044:b0:770:da0d:171d with SMTP id gz4-20020a170907a04400b00770da0d171dmr7828106ejc.742.1664587156315; Fri, 30 Sep 2022 18:19:16 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id t14-20020a170906a10e00b0077e6be40e4asm1914914ejy.175.2022.09.30.18.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:16 -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 v3 2/7] drm/arm/hdlcd: replace drm->dev_private with drm_to_hdlcd_priv() Date: Sat, 1 Oct 2022 03:19:00 +0200 Message-Id: <20221001011905.433408-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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 Sat Oct 1 01:19:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996255 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 290A5C433FE for ; Sat, 1 Oct 2022 01:19:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 65AC010EDF9; Sat, 1 Oct 2022 01:19:28 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id E861110EDF8 for ; Sat, 1 Oct 2022 01:19:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587162; 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=3NFp4VgvnrWlpf0cR1jJD5RUagyd6mZ8BYx1FSeEHWg=; b=HjLcwA5kDeYRRwkwpqMbREEgV11ngXiv3p2I0ZMEvOkkbc6bgb29qSp/uRjPdV8cp7oyth homz4zRz89pSqfXiORPfKAa0oYS4TsvpyRtdS+qs+JtGm/cfxgcME8T7KyhEB+1ApvKMw7 zT2BGkwowtSjIN+ENLd+BBnkmByAfxQ= 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-172-s_AtS4EhOM-UGTYZKOiHUQ-1; Fri, 30 Sep 2022 21:19:21 -0400 X-MC-Unique: s_AtS4EhOM-UGTYZKOiHUQ-1 Received: by mail-ed1-f69.google.com with SMTP id y1-20020a056402358100b00451b144e23eso4607658edc.18 for ; Fri, 30 Sep 2022 18:19:21 -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=3NFp4VgvnrWlpf0cR1jJD5RUagyd6mZ8BYx1FSeEHWg=; b=YbOTphouMhvhoTdyurtUKbCSLPh7Am2YBtXhTXi0rkMesVF6zc6WE1MlNsmMU9uUdn dBilG9C/fnIvwAK4deblFHjL+NS5fy90yGtmvt/bQNv5RS5cPq+f4BLFz9o+b5F8wWyw 0LfvPFSeiqrTiPm6CIb6h8f5I0QG76SPP/1SZnz7I5fi0IW14b1G1o3DjvWUCEUWr9EF rpzYnpsYUG0fIwP6ddrWV/Zk8wYueQw5qIaOe9GBE1dDwgmhRqplLn9+TdWOMrc1om3s IAFNXlhXtq2pZwOnluXgFJIRK61SMu1qG+Dqm3aaY/uoGOEBYP4CZCoZwwo+gSQWQ0Ft /olg== X-Gm-Message-State: ACrzQf1NJGQsH8ycoKcy5GarCjgRtQ5baXCvkmOuxFDlFRPvMiMFtgUi RagntwpY+r1iDaenQUqhVvSECzfBBDjpV6wO9nwQN+stTPSAjzZ35ChOZajlp8dSnUUsHBLDlAN tgjOml/2upDgm8CnR0iGYjETSbvHo X-Received: by 2002:a17:907:9812:b0:781:bbff:1d20 with SMTP id ji18-20020a170907981200b00781bbff1d20mr8193515ejc.33.1664587160117; Fri, 30 Sep 2022 18:19:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CQSQnjdvUmSQnJbZMdXRbmz2WBI2YEXp3z+zGa5bI24ZgAEiRi9g+ipz6Q5+W+HezYugKOw== X-Received: by 2002:a17:907:9812:b0:781:bbff:1d20 with SMTP id ji18-20020a170907981200b00781bbff1d20mr8193507ejc.33.1664587159964; Fri, 30 Sep 2022 18:19:19 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id rk14-20020a170907214e00b0078238c1c182sm1870090ejb.222.2022.09.30.18.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:19 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v3 3/7] drm/arm/hdlcd: plane: use drm managed resources Date: Sat, 1 Oct 2022 03:19:01 +0200 Message-Id: <20221001011905.433408-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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 4a8959d0b2a6..1de0f7b23766 100644 --- a/drivers/gpu/drm/arm/hdlcd_crtc.c +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c @@ -290,7 +290,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, @@ -298,24 +297,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 Sat Oct 1 01:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996257 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 8A8C1C433FE for ; Sat, 1 Oct 2022 01:19:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B2B7F10EE06; Sat, 1 Oct 2022 01:19:34 +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 4F6E710EDFD for ; Sat, 1 Oct 2022 01:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587168; 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=hsWBexLFDVqUOZMqbhy+SL8q312glCS9Mla/+vP6MEc=; b=VxGwHVOqw+hsOxzMXO+xYyfgU11cxwkaDkc/b5kaCguRPR1Ak74B0DNzvVz24+y4BWHbyw 7OfQiGMhy0RuxGGkyxYwZbtACGGJ9Prr31yTPTgMkNPpN4OeiR5bxU9nvdkYrAnt5jaL7v G4yEfRRcnVpZckeaVEhVlUdIY7uED2U= 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-215-MQGRGA6HPLqahs2wKT98Ng-1; Fri, 30 Sep 2022 21:19:24 -0400 X-MC-Unique: MQGRGA6HPLqahs2wKT98Ng-1 Received: by mail-ed1-f71.google.com with SMTP id s17-20020a056402521100b004511c8d59e3so4684037edd.11 for ; Fri, 30 Sep 2022 18:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=hsWBexLFDVqUOZMqbhy+SL8q312glCS9Mla/+vP6MEc=; b=1l2uw3M0y3TOfH3m9+nrwHwhi4ZcWFG6GTeN8YZyEAig1F8/0O6shywwtZWsgfGLPT MnyNZyYzNrZdNQZajULo1/nbuz4HKs8iUf4BNiM67BPlIc4TefxMG7d3l0TXIn6JVptL hb8wxZxx45rx2rsPZvFPYBn0bPxEewe7GVwoprdjGOu8A3cFiDhY3gFyte0zIhv+JKhZ SzAVjc5R/Zs3EO/e0sflcDy9WzlBR3pEt6a/Dds1z4nY3iMfGJVJInU0HpM8kGKhle2V 07eICv6NTLYQ5fFi2KA0JB+o1PYm+XUIcD3vxZYxuhMxPa0nvw44ps0zEbtwUsYXEZqD xEgQ== X-Gm-Message-State: ACrzQf2aa3o6h8xKmpMogWxA6OTZrYR42TUMcIFvJQ6ylY3wkdKca9sN vZz6qMHGk34aVPN/wqnl1EAJVvXfAn+I8ls+4izOTBjRe3dh3NdNX5DjGLvp1N4vhh4ge2/pxni zGEeM+cljchROHbYh19O3N/LVidaq X-Received: by 2002:a17:907:2c77:b0:77c:59aa:c011 with SMTP id ib23-20020a1709072c7700b0077c59aac011mr8480019ejc.724.1664587163739; Fri, 30 Sep 2022 18:19:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zcMskX82KTUkI5E7f0f84qForNAwCdRF+W3G2xOEagDWoB9NXlhmTv0aJC4uLhVIyAmcViA== X-Received: by 2002:a17:907:2c77:b0:77c:59aa:c011 with SMTP id ib23-20020a1709072c7700b0077c59aac011mr8480004ejc.724.1664587163596; Fri, 30 Sep 2022 18:19:23 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id r20-20020aa7c154000000b004582a37889csm2573958edp.16.2022.09.30.18.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:23 -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 v3 4/7] drm/arm/hdlcd: use drm_dev_unplug() Date: Sat, 1 Oct 2022 03:19:02 +0200 Message-Id: <20221001011905.433408-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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 Sat Oct 1 01:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996256 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 94816C433FE for ; Sat, 1 Oct 2022 01:19:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BF7910EE04; Sat, 1 Oct 2022 01:19:34 +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 DF60B10EE04 for ; Sat, 1 Oct 2022 01:19:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587170; 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=VOw+nn7ti+m5Q8fWTW3IpLkOdVFAAWp2wbEVH0hCZZg=; b=FYOiL4+pquoGr8fBNj94+zNlgf+Pt4z3Bg+oXJAy32WZLO15ISIAJ/NZWOWZqjGSPxIxYq F6BN3LqDzhzUtWUslmd5Aw2T3PFgxDR+SEMtO9Tmm1OcDI7fsuFDq0uXPXrSvb3XVuXnDJ acj6Oi8cOEipUCXjDH1H0lfbSjYiteo= 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-413-dVB-DlQXPfa7MNuPezF0Vg-1; Fri, 30 Sep 2022 21:19:28 -0400 X-MC-Unique: dVB-DlQXPfa7MNuPezF0Vg-1 Received: by mail-ed1-f72.google.com with SMTP id w20-20020a05640234d400b00450f24c8ca6so4622199edc.13 for ; Fri, 30 Sep 2022 18:19:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=VOw+nn7ti+m5Q8fWTW3IpLkOdVFAAWp2wbEVH0hCZZg=; b=06zHC1ClD+K4QZ2yXSTir2IU53zmiYR67f5oUz2iEEzLP2oBu5wY5Ih2a9iMPi/82H hv2KtHhr7zqJeiSnauXppSoP0a3zl24uK4rRYbmuzzIrovN4uCh0ZVljplt0cwGlAbOF y4Ft1YAeyYnnxRgak2WzFb2ejb9ivFRxCyrSjIwrzp5giD+iAbCjnfWUu1dMm3VN0+dV MpP2YpxMOSngu6T2665eqOUuPpANrcjl8orXQrQuOcDiRolQpsK1crXYKf7hgbIhOxJw uDPfPIJ5Q3IXqFid5YcnwwnUvK3BxkrKxcvp9k03+5ZET/6uFGoXcAxnD6eGlnotCP/Z FLbw== X-Gm-Message-State: ACrzQf13VrTBA9qa5uLJ4Fe+8BTbzLy2ZcrIiLyFXTQWhjMpsqImxdCI qe9CKyQl8JcA0c8VeC9r/64TFlg/DM97xy4xWdUH+BD9eJo8Ww1xFPS8LtP660NxLQtuWI9NLRM MkoeUUPJQcb+nbL2VQyzEtXIgkJRr X-Received: by 2002:a05:6402:1f89:b0:453:8093:c4e5 with SMTP id c9-20020a0564021f8900b004538093c4e5mr10144844edc.182.1664587167487; Fri, 30 Sep 2022 18:19:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Cz2MhkPwjR82bZuuI/cuJB5Tw0OCSgZ/P3E5KDFUBi+NqgMptkOjbE77f1V0GFF7/gDVgWg== X-Received: by 2002:a05:6402:1f89:b0:453:8093:c4e5 with SMTP id c9-20020a0564021f8900b004538093c4e5mr10144830edc.182.1664587167242; Fri, 30 Sep 2022 18:19:27 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id c9-20020a17090618a900b007821f4bc328sm1948804ejf.178.2022.09.30.18.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:26 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v3 5/7] drm/arm/hdlcd: crtc: protect device resources after removal Date: Sat, 1 Oct 2022 03:19:03 +0200 Message-Id: <20221001011905.433408-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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 | 60 +++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index 1de0f7b23766..7ce88fb6e822 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,28 +40,50 @@ 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)) + goto cleanup; /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); + + drm_dev_exit(idx); + +cleanup: drm_crtc_cleanup(crtc); } 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 = { @@ -171,21 +194,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, @@ -193,15 +228,23 @@ 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; + enum drm_mode_status status = MODE_OK; + 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 */ if (abs(rate - clk_rate) * 1000 > clk_rate) { /* clock required by mode not supported by hardware */ - return MODE_NOCLOCK; + status = MODE_NOCLOCK; + goto out; } - return MODE_OK; +out: + drm_dev_exit(idx); + return status; } static void hdlcd_crtc_atomic_begin(struct drm_crtc *crtc, @@ -268,10 +311,14 @@ 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 (!fb) + if (!drm_dev_enter(plane->dev, &idx)) return; + if (!fb) + goto out; + dest_h = drm_rect_height(&new_plane_state->dst); scanout_start = drm_fb_dma_get_gem_addr(fb, new_plane_state, 0); @@ -280,6 +327,9 @@ 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); + +out: + drm_dev_exit(idx); } static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs = { From patchwork Sat Oct 1 01:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996258 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 23D88C433FE for ; Sat, 1 Oct 2022 01:19:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 39E2510EE05; Sat, 1 Oct 2022 01:19:40 +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 6048110EE05 for ; Sat, 1 Oct 2022 01:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587173; 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=IDL/AgTFWdm+PP/N7/EovNn2CFq5LCV9poLaDqClvoQ=; b=WQhpMBxIBG1TlpdilNZtTa49/48WxSbXE5Ojw42LxhgeAJ3pT4bEKuwg67p6XlY//UkK2x C7QNnaRTrLotPzZQHOejUTYOuHYihnv7OLV0idqife3DrzK4WsbeqPMPzN2xxKwCQYUXi3 9OTepbjsm+YCOV0uqHdm7SVG+EaVmRs= 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-7-aam0GDC7PbKrdg3viOnjuA-1; Fri, 30 Sep 2022 21:19:32 -0400 X-MC-Unique: aam0GDC7PbKrdg3viOnjuA-1 Received: by mail-ed1-f70.google.com with SMTP id e15-20020a056402190f00b0044f41e776a0so4640976edz.0 for ; Fri, 30 Sep 2022 18:19:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=IDL/AgTFWdm+PP/N7/EovNn2CFq5LCV9poLaDqClvoQ=; b=jk3Sx1nsBrCqbSqoJcXD58ET3b9J3puulP6yOZ87EehJQckOLZVukewp1jN58D6Oge ogIVRs++nAsuMNYd8sCSUqSQxEwRLuzM3Z/nLjoaL+DH+Kydgsk4V/yxQjzpHxbYHwtg PVnB11Fwgyh4XzuLnARprKS/JmeP6FeKUKLkHRiYG+bd1Wro4WKxMQRPbZUh1Jze6gei wt7W3H3M3SIa04WR0p/1H8GZrMhSPd38b3/9mRFjQdba1kr1Eoe09ZZY2fzJhXm9nfYY +5nEZkzbWb7mBW9BO0KoWX/Jev1zJcF8bc91o6SDLaS9JcBfT08Ab3xucleVgduF6c42 dN+g== X-Gm-Message-State: ACrzQf309h31TBJwPILitO9aPTbWWQY7D4kSdgfdxxmSMoHGfm1Mp/PJ 4lMMhT2BCvdpaxfW8tTH4toiciFLmA65J/b/Z+xInVOUMfQ6u55jKVwFJo0neHLuk0nfWgWaoxw D/H77tgaVIkPnjgK0/6Jq4OAddKKZ X-Received: by 2002:a17:907:7f13:b0:783:6227:b939 with SMTP id qf19-20020a1709077f1300b007836227b939mr7826772ejc.416.1664587171146; Fri, 30 Sep 2022 18:19:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wyZtxUwtQbZgS2YO5wic9h7BmWOQ9xCf4l19faoKnOUNoHKq43TyHpezKHLZZwq7kSKONgA== X-Received: by 2002:a17:907:7f13:b0:783:6227:b939 with SMTP id qf19-20020a1709077f1300b007836227b939mr7826762ejc.416.1664587170962; Fri, 30 Sep 2022 18:19:30 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id oz23-20020a170906cd1700b007724b8e6576sm1931950ejb.32.2022.09.30.18.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:30 -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 v3 6/7] drm/arm/hdlcd: debugfs: protect device resources after removal Date: Sat, 1 Oct 2022 03:19:04 +0200 Message-Id: <20221001011905.433408-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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; } From patchwork Sat Oct 1 01:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12996259 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 BB5F2C433FE for ; Sat, 1 Oct 2022 01:19:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 46F5910EE0E; Sat, 1 Oct 2022 01:19:49 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F8B210EE0E for ; Sat, 1 Oct 2022 01:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664587184; 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=FflVPY5URLlO/QnD0oVlID0lCcDMEG9+FRQWDZ3uQVQ=; b=AJxXhK+hYSI9mFZHX3KazZ0gKoMg5cP9/UPE58ioxF3Bihi/kFlekRn0aXwqP2LBMQtfMO J15Qo0B2/vgOr56N+TxV/4Pu0fS6TZRrDLIDTa2zSZchvuH0cjSTw5yO6jCq76FyL8FZG+ hrLgloyPsvrsiOSok7/lDYrYaqEarNw= 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-210-M_8hNdBBO16Y4MI6THpF5Q-1; Fri, 30 Sep 2022 21:19:35 -0400 X-MC-Unique: M_8hNdBBO16Y4MI6THpF5Q-1 Received: by mail-ed1-f71.google.com with SMTP id s17-20020a056402521100b004511c8d59e3so4684278edd.11 for ; Fri, 30 Sep 2022 18:19:35 -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=FflVPY5URLlO/QnD0oVlID0lCcDMEG9+FRQWDZ3uQVQ=; b=3QCFkiAL6zLJTq+UTJ1UqqBjtXKEltn7qeZ4zMhkUcyN0aWkrEdw/iw1nmmonrpJyx 1R+YTlzNrwF4Z2ICwJ8/4FXXJnlSv8uWyxGSyTrnzn3qDzpp/+V2dEEAY3KhhJO4bz/I Kp50Yvv53dGfsbdX28/5idRzG481zn2iUtX94cyTlDq9l77wenMtfxqZvUZ+HbNQSpQL BH8/w+gI1xfCiLTZkYVYE/oL3jBBy1Wc6GaqB+nvnbwEEwWLEjZylc6MuhbelTqComrh vmSLSdo9bde7VCGe5dnoU0OyOdGCYP2fJs5uNnZ2C4e8j/Z6aCxeqF0fft+zp+xEWW/9 wv7A== X-Gm-Message-State: ACrzQf0HgKECnwRla6nz81nQGstv9YqYy+maHeRixS4hDfSkTjQs5Hlp 2KAhCy+2o9E0i8ZRF3mbP05oyBRjsp2tpu/pEo8xP2ucQ5gBBVnQ0zcyGLXiRwcV4eEXxlaiHMM v2j1SKFfDM/BG5ZndvhnY0GJaJpP5 X-Received: by 2002:a17:906:7310:b0:782:cfd4:9c07 with SMTP id di16-20020a170906731000b00782cfd49c07mr8553111ejc.708.1664587174774; Fri, 30 Sep 2022 18:19:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4x4xTB6S0FGXzv4kk/zNUKjUE/t9WGKOcAeGn0jSeAtcx2ggB6JSwppKVYxMJjyrcRCJ5xeQ== X-Received: by 2002:a17:906:7310:b0:782:cfd4:9c07 with SMTP id di16-20020a170906731000b00782cfd49c07mr8553105ejc.708.1664587174628; Fri, 30 Sep 2022 18:19:34 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id g18-20020a17090604d200b0073c8d4c9f38sm1927167eja.177.2022.09.30.18.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:19:34 -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 v3 7/7] drm/arm/hdlcd: remove calls to drm_mode_config_cleanup() Date: Sat, 1 Oct 2022 03:19:05 +0200 Message-Id: <20221001011905.433408-8-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221001011905.433408-1-dakr@redhat.com> References: <20221001011905.433408-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/hdlcd_drv.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c index 020c7d0c70a5..e242b6223d77 100644 --- a/drivers/gpu/drm/arm/hdlcd_drv.c +++ b/drivers/gpu/drm/arm/hdlcd_drv.c @@ -175,14 +175,21 @@ static const struct drm_mode_config_funcs hdlcd_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; -static void hdlcd_setup_mode_config(struct drm_device *drm) +static int hdlcd_setup_mode_config(struct drm_device *drm) { - drm_mode_config_init(drm); + int ret; + + ret = drmm_mode_config_init(drm); + if (ret) + return ret; + drm->mode_config.min_width = 0; drm->mode_config.min_height = 0; drm->mode_config.max_width = HDLCD_MAX_XRES; drm->mode_config.max_height = HDLCD_MAX_YRES; drm->mode_config.funcs = &hdlcd_mode_config_funcs; + + return 0; } #ifdef CONFIG_DEBUG_FS @@ -263,7 +270,10 @@ static int hdlcd_drm_bind(struct device *dev) dev_set_drvdata(dev, drm); - hdlcd_setup_mode_config(drm); + ret = hdlcd_setup_mode_config(drm); + if (ret) + goto err_free; + ret = hdlcd_load(drm, 0); if (ret) goto err_free; @@ -322,9 +332,7 @@ static int hdlcd_drm_bind(struct device *dev) hdlcd_irq_uninstall(hdlcd); of_reserved_mem_device_release(drm->dev); err_free: - drm_mode_config_cleanup(drm); dev_set_drvdata(dev, NULL); - return ret; } @@ -345,7 +353,6 @@ static void hdlcd_drm_unbind(struct device *dev) if (pm_runtime_enabled(dev)) pm_runtime_disable(dev); of_reserved_mem_device_release(dev); - drm_mode_config_cleanup(drm); dev_set_drvdata(dev, NULL); }