From patchwork Tue Sep 13 22:14:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12975412 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 84EB7ECAAD8 for ; Tue, 13 Sep 2022 22:16:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5DA6E89F01; Tue, 13 Sep 2022 22:15:43 +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 40CAE10E563 for ; Tue, 13 Sep 2022 22:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107306; 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=iz/h4NfYvMX2kLKX+6ygR/uj+aHMmRXPZxemo3Mzxdt0og8VPBsQLybEWxXWvq8HEQGsCP QcxUIZsYUDINT2ASJ8sNEPPynLbCABjKOhg+7FpS0pAPFJWDhXtU2seiUmKc4G2mpstYnv agWQz6fYw4/jh2NutCFRFVChuDF65/4= 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-578-5FFXCK7mNWmr2ZljqlJIjg-1; Tue, 13 Sep 2022 18:15:04 -0400 X-MC-Unique: 5FFXCK7mNWmr2ZljqlJIjg-1 Received: by mail-ed1-f71.google.com with SMTP id y1-20020a056402358100b00451b144e23eso5531353edc.18 for ; Tue, 13 Sep 2022 15:15:04 -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=IS9nec8OC0y90en3Nejc6/s7uBwGp8nKh7QlIei0tXwhO4T1BOO2nxQs6AtOLTlRzr LZ6LGTPfufTaB5GdyzMY6btYnHX0CCULBv1PWgJoWm6z5YNVajUS0x53PwAgRKZ72CNv H/P+Iwt6qt1v8ru2LraWWZJOW5ggAs+zYtkk/spssnsSQANqyUHDDx4KY34Tuz7A0MqM nbBJValkCsRNhnEsRvENvabbRosJoCsl17gIf6E3vAEkRSpFLHHqI+IA9VB+s0QI6HF2 WxKLsYCJKps0vEDYPMRXB6YVgmm4gCI2pNtYOFa2QATEOktvsRDP4GnIHuGpsA+MjrIr Q0yQ== X-Gm-Message-State: ACgBeo0PqemkBJQF+oR6BQgjfzvbJrkqHXSmJhvrYApX7288flPESfqW 0ZMtRAVHrn7E0FzZTWbc4JuocbrJ0ieL3NuoC+hdxMdzwrpv4QxvyJEUP2qjv0f1YlB9J0W3WVX kvQYJQSgr7MABY/i35mlbrU/F9bbQ X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr5606884ejc.208.1663107303649; Tue, 13 Sep 2022 15:15:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6CWbWIsmU+jbsRrkPOx16ZPv+euqGiqID/bCT9pQvDeXNytvGsUpuMTtiOi0r9m4i33dXEqQ== X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr5606872ejc.208.1663107303439; Tue, 13 Sep 2022 15:15:03 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id g22-20020a170906539600b0076fa6d9d891sm6609451ejo.46.2022.09.13.15.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:03 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v2 1/6] drm/arm/hdlcd: use drmm_* to allocate driver structures Date: Wed, 14 Sep 2022 00:14:51 +0200 Message-Id: <20220913221456.147937-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-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 Tue Sep 13 22:14:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12975408 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 2175DECAAD8 for ; Tue, 13 Sep 2022 22:15:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC08610E565; Tue, 13 Sep 2022 22:15:26 +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 B94ED10E565 for ; Tue, 13 Sep 2022 22:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107309; 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=UmtWsIpg0f+mfzYLkZ50gI9pxyXLbUXAfI8xl0UnKIr+dkgmvYHnQSl5G6ANhKhTsriy2Z VbMYmsgpqOD3mpXBrTLHIqWsPCIE3Jc8VhhR0LrbpjEPj2e+oyP8g2Iial1uZsE5esWE4s +TLSb7kFWucMLc5r4OB7gbX1+Dudshc= 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-643-RaigB6vROj2dlw3b1thisQ-1; Tue, 13 Sep 2022 18:15:08 -0400 X-MC-Unique: RaigB6vROj2dlw3b1thisQ-1 Received: by mail-ed1-f70.google.com with SMTP id z2-20020a056402274200b004516734e755so6815844edd.3 for ; Tue, 13 Sep 2022 15:15:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=yZIl1OKGrL3KJyd7ruXlclzCfjtYvrZNcDLCxG8/BBY=; b=Jov1MOOueOhFqELh2+ibKYlrpt0DRrJwdOtlnIlzN3LZz1jlv+t4LSV5/5+ggv8FS5 GQRCRNUq2e4vYPGGT7onqBYGsBu6HqcPyG317iZTPpFIhzPACtHexmCK11TFx1oakqm6 I5ESoSDjt+t/xjU3Q+U7MB+YWQmPCheS6BUmHV3ZaMpAbhobvPS0/UWZbt6d35ijO72g G1d2ItYkZ3oIH8kpMesQrzuEFREihgiS/5HSf9q82FoZVJGT6TEZawUVyGIizzgE1N5n LaFDA1Z3OEW1G3cLHPlbR2YO0TsZ8wlSgQ5fQBD17nuFJZxlYnnho4Vg+S5pMHKGD3lp /vUQ== X-Gm-Message-State: ACgBeo1IquBhZfPLaQoj1Px+QHfbkX0DysBWBXYTJvFIKb2S5OjK0GTH xAMXuGAVJd6FZdP2YfdJ8ygW1ZGfFqLori/iFoduP37TCR8yMiYj6loeJTK9wTm3MI6vRqRM0/5 ujUkD8qnhuQxMhBeTY+JWync5VaH6 X-Received: by 2002:a17:907:1df1:b0:779:4f57:6bb2 with SMTP id og49-20020a1709071df100b007794f576bb2mr17525244ejc.407.1663107307170; Tue, 13 Sep 2022 15:15:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4YsLe/4f+g12SdIvUKL4wyl4IFJDNXF8MYO1RJXFZ6RDdzyG4arikiWNcVkyelk7WviOjkhg== X-Received: by 2002:a17:907:1df1:b0:779:4f57:6bb2 with SMTP id og49-20020a1709071df100b007794f576bb2mr17525231ejc.407.1663107306986; Tue, 13 Sep 2022 15:15:06 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id q5-20020a17090676c500b00777557d1ea2sm6644176ejn.47.2022.09.13.15.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:06 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v2 2/6] drm/arm/hdlcd: replace drm->dev_private with drm_to_hdlcd_priv() Date: Wed, 14 Sep 2022 00:14:52 +0200 Message-Id: <20220913221456.147937-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-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 Tue Sep 13 22:14:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12975410 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 D8371ECAAD8 for ; Tue, 13 Sep 2022 22:15:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9C83C10E58F; Tue, 13 Sep 2022 22:15: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 9FF1010E57E for ; Tue, 13 Sep 2022 22:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107312; 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=B7MTpW09fQ+lihj0CI+mDTkUlF8jl5Cn+dXT7We6W3EhSLwzYBgiqp8hh6Hji52PY0I7zR MULvqSoJWmGAev3X9dQz9SLzDxkPZlSiI9dBWAuy0O9b6wSSlOS5uLWTXyp+05kH7Wt3wx B9w2tNHbfwL0pDAOOIRgm1fUU33UoTg= 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-663-sKhxm2OlNMaYYFGw21TJZQ-1; Tue, 13 Sep 2022 18:15:11 -0400 X-MC-Unique: sKhxm2OlNMaYYFGw21TJZQ-1 Received: by mail-ed1-f69.google.com with SMTP id m13-20020a056402510d00b004519332f0b1so5833000edd.7 for ; Tue, 13 Sep 2022 15:15:11 -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=bGeR8CrkygBzkc5amKhMDv7wK5e0Kg0RbIed7HxEj11l0lQNzgo4v650MCtqaI+Zgx TRzDZHcI0KK2jep4Xw9xsx0d+FLxQzNny7PCi5fWn03FF1x5Z5l72h9Ud39apYUnlopC Z6PNQYV7c9dMiDwIwt9o8ISVZeuHeYw5Ekq5N4LUaxVo9sKQxvfRtV0oPOJ5wyr4GAFe eOGGZdxwKqD+lCB2QobArmIjE/AK78htyK/2xU6vZEWa5sZzjKHRO3xXKglJa/pfleGB MO/PfBtAtV5J0FoMzt5f0K3Biu16IbBpicbuZ6zG+My3vIHA/HDxu3prMtjpg4Jddgbo 68ZQ== X-Gm-Message-State: ACgBeo38/cmMbeHSAKM3b1Yjy+YU7+8YTzozuwhlmglu0lzDkj9ePhRI v/7N8Y3XkA9aibKHlsfk2Dlbxn72fZOuhxLOkcWQAyOXYoH1Vq3j+Hwul9EnsnFXW0MbYmCjSsl d8wgncCitOz3PXKLOPx08qv4NCUiF X-Received: by 2002:a05:6402:5008:b0:440:941a:93c3 with SMTP id p8-20020a056402500800b00440941a93c3mr11421867eda.47.1663107310594; Tue, 13 Sep 2022 15:15:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR5KhucR8r5x09VFOVDFq9E+WrNdnLRNQO9ncHrfWTWlUc3ZuYrpuLfrhf8xvJhv8/6n25RPzg== X-Received: by 2002:a05:6402:5008:b0:440:941a:93c3 with SMTP id p8-20020a056402500800b00440941a93c3mr11421856eda.47.1663107310449; Tue, 13 Sep 2022 15:15:10 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id 1-20020a170906218100b00730b61d8a5esm6684941eju.61.2022.09.13.15.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:10 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v2 3/6] drm/arm/hdlcd: plane: use drm managed resources Date: Wed, 14 Sep 2022 00:14:53 +0200 Message-Id: <20220913221456.147937-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-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 Tue Sep 13 22:14:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12975409 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 5BBF7ECAAD8 for ; Tue, 13 Sep 2022 22:15:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7390510E57F; Tue, 13 Sep 2022 22:15:38 +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 628C110E565 for ; Tue, 13 Sep 2022 22:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107316; 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=TQbJpJEZrzx2X6HKpqf4JX2O3iKqQYePSwmV7ACSShWERY8heq89K2EcPINvSfqSpys+8X 78y2fm7XfjZcouZha5aI0uvRKFaRyI1SZVEmcSLCcmoKkm41VxmAA9kCZf2aNyzaKcnp0f PSCq9CYkPYTJu/w+vBGwNvDo1uNdd8Q= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-148-dVciF-B2Nr2UFyAtJKUZxg-1; Tue, 13 Sep 2022 18:15:15 -0400 X-MC-Unique: dVciF-B2Nr2UFyAtJKUZxg-1 Received: by mail-ej1-f71.google.com with SMTP id ho13-20020a1709070e8d00b00730a655e173so5228228ejc.8 for ; Tue, 13 Sep 2022 15:15:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=hsWBexLFDVqUOZMqbhy+SL8q312glCS9Mla/+vP6MEc=; b=EB3PtGvVzEGNSmBsqE3pPjvNLTHnpbD2dzAWOOxxN4bY2S9GkWMLaTUwi4UEjxv5wl GpozQ8O7HQbi1vnOh8tozgPczpwMk/Z9lqfxVNx3trvWBTLdERLdZPZyeS9Ij1m2w10d 4hxG8bOya4DuKF0pa+9Z5tzCT+x1ZKjdS16a8Nxc6B4WhU9yHQ1NSFLRLbo4iX/EIwiz ckAP1+o2NwIiynR0o1daGn+Ja4Kw1RUtj8DzXDBBqx9P4iBQ5CNoPp4ACywCP/6LTexp U37rKiJ7pTnX7t3xG4ndmZ5GXXS0U/Jgwj29tH+/FEFNlxBxfPUYX6mgz3rGDIhVE+or ZLCw== X-Gm-Message-State: ACgBeo1wGnczmfwqBx7qvTZ5hb9EG8QJVK2OsuiujrVboeUZnN33L+kD rhSdiYC9ZL+IipIH5BTBKZqALjm0oNXlDExYD06xi6wTk8EhAohfMF0aqgiDgFmlMrST69xwfUF GdN7jvxyHKXwePrmk3uqjYyVEsObr X-Received: by 2002:aa7:da97:0:b0:452:bea2:5200 with SMTP id q23-20020aa7da97000000b00452bea25200mr68244eds.341.1663107314140; Tue, 13 Sep 2022 15:15:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ZKIyEtvn0ZdttQsylhb4+4lRtAhpLE6jDAvGHN/+GdIEgTPcQEnfQ2XrRN4o9j3qVCy3eiw== X-Received: by 2002:aa7:da97:0:b0:452:bea2:5200 with SMTP id q23-20020aa7da97000000b00452bea25200mr68238eds.341.1663107314001; Tue, 13 Sep 2022 15:15:14 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id x24-20020a50d618000000b0044e01e2533asm8720076edi.43.2022.09.13.15.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:13 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v2 4/6] drm/arm/hdlcd: use drm_dev_unplug() Date: Wed, 14 Sep 2022 00:14:54 +0200 Message-Id: <20220913221456.147937-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-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 Tue Sep 13 22:14:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12975413 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 BF83CC54EE9 for ; Tue, 13 Sep 2022 22:16:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 14DE910E59E; Tue, 13 Sep 2022 22:16:44 +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 C24E410E57F for ; Tue, 13 Sep 2022 22:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107335; 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=F/Lhqp1JWUkXQ2yb049nFnR3BgXC5vF+mPmJxxil2YI=; b=K7PVLBxq3Myk+68DWBjTwIxAYmKAlD1Kh6DFg+z7ke16GoqV5Q9U5z7KkF4P/xl/hbFe0t S5b5rZO+i5CYLyo8anUOvqMcBKdkpQGdh4xqSdS0psBytNRxS9u1vPRU4a9I02fs1jFmaL a1OzKoo02Swg7qxuuXnbz0z5D9y0PdQ= 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-457-2KLvydK4POS10LiKfjyp5A-1; Tue, 13 Sep 2022 18:15:18 -0400 X-MC-Unique: 2KLvydK4POS10LiKfjyp5A-1 Received: by mail-ed1-f69.google.com with SMTP id i17-20020a05640242d100b0044f18a5379aso9509633edc.21 for ; Tue, 13 Sep 2022 15:15:18 -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=F/Lhqp1JWUkXQ2yb049nFnR3BgXC5vF+mPmJxxil2YI=; b=BKlP1/8+2IF2fsh3nR5ZFJ3OyfywEhvlgJRjHqIBicdFGc67+bHl/1oBDe34w8V/H9 r9IGR4Q0FNM4rBPHIoCACH9UfgvCUKz8CvHiqSYQviFmRGzNk06kR9GI/VW3eYg4QQ+6 SVjEvWK4y55yAlmlZ35gU6HWKQ1UanSdBNhFJnKXgYm5bLMHxi0wsNZGN3ota2uv86wq 5n7o8Rw1umjCTdSX2mWMF8xJEaXrir3Fu0fJFVb9aR/F+58XceMXwfewL8KmmG/iapeU KnfL9yHxLq29AZF+pBA/m5HIbGPGMbc5Vfz7ntjY9jFFX2zYnTgThfQdynfo+3e0GRse 0iIg== X-Gm-Message-State: ACgBeo2YS+mifDiXyJEPR5cbIP76rZzGNxP69F8tsIt47RriRHMVLQuS KRHv0bCEK+8s5V6R6fPjIv3ojtuLtqJuMYcLlZWmNSBr0blmMgvBA9PvQgUriKL6oXCP152PtvI WgeH6WcylkMJeLXlQjBu0RUYa5zz6 X-Received: by 2002:a05:6402:3550:b0:451:473a:5ca3 with SMTP id f16-20020a056402355000b00451473a5ca3mr15479847edd.48.1663107317636; Tue, 13 Sep 2022 15:15:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR4C20Kieg3SMyoOJCdNFKmKL8ZSD+8UnDiEYDq5h6qGIBOnsvUg5zBURejSehEmhbPcYVQiWA== X-Received: by 2002:a05:6402:3550:b0:451:473a:5ca3 with SMTP id f16-20020a056402355000b00451473a5ca3mr15479839edd.48.1663107317503; Tue, 13 Sep 2022 15:15:17 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id z13-20020a1709060acd00b0077d371a8f29sm4121008ejf.204.2022.09.13.15.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:17 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v2 5/6] drm/arm/hdlcd: crtc: protect device resources after removal Date: Wed, 14 Sep 2022 00:14:55 +0200 Message-Id: <20220913221456.147937-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-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 | 52 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c index 1de0f7b23766..694adddc9f7c 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,49 @@ static void hdlcd_crtc_cleanup(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); + int idx; + + drm_crtc_cleanup(crtc); + + if (!drm_dev_enter(crtc->dev, &idx)) + return; /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); - drm_crtc_cleanup(crtc); + + 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 = { @@ -171,21 +193,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,6 +227,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 */ @@ -201,6 +239,8 @@ static enum drm_mode_status hdlcd_crtc_mode_valid(struct drm_crtc *crtc, return MODE_NOCLOCK; } + drm_dev_exit(idx); + return MODE_OK; } @@ -268,6 +308,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; @@ -280,6 +324,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 Tue Sep 13 22:14:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12975411 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 D1044C54EE9 for ; Tue, 13 Sep 2022 22:16:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D3A289A5C; Tue, 13 Sep 2022 22:15:43 +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 00DA810E596 for ; Tue, 13 Sep 2022 22:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107323; 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=E8R0xeYw7OT4sEuNdFOcN7ZQuLY6Cbp7++z+zes/bT0eyufK9nRhabUnmB4knPOLv9kqT3 XgW8TeqF6HptZkBvcyieE9pw+FMuHrC2JFHjrk0m+zHw4DqZarhtFCbYt8xn2tU2lXuXo3 EOMWNT4Kq+YBIsheZC7lgfo/QcTdzS0= 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-35-bY-B7-YNOjuh-tzIqq1Vcw-1; Tue, 13 Sep 2022 18:15:22 -0400 X-MC-Unique: bY-B7-YNOjuh-tzIqq1Vcw-1 Received: by mail-ej1-f72.google.com with SMTP id qw34-20020a1709066a2200b0077e0e8a55b4so3030891ejc.21 for ; Tue, 13 Sep 2022 15:15: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=IDL/AgTFWdm+PP/N7/EovNn2CFq5LCV9poLaDqClvoQ=; b=v5uxzWZ/suoLwN5CEPp0BXRTxReewho4ONda0Ib9rDEYj+R0py3v3NtytLMICG3LhG T/bTJIRN2HC8diQCQ2YE45VSsmIKPTG5fNqH2BTcOWzmbHP5pZwAd8u5oL9xwnnnesWW R7mZCMbeughOMJ7n1LNHY/0mkqiN1kyEr5HXeNaw27obSr/YjbaLmeU5jzOlHtzAsqxh h1zBpBne0ZBlFDr2I/+81MaENE8Za7joxeN2yr2awTr0NhAALtlbAJrmUgm46+WwrRuN R9ltMHxOuIIyQIb1WT3YFKTv847AkkBxUqaTQCpnf23AXlJWJyARE1ffEHcmu9wDYXje kzAw== X-Gm-Message-State: ACgBeo0cGyhHGQUSrCB4A2oXUuheulc4D+dfYBbBbvHSHlCCPCD8E1SF AIRqhbIdq2+ZuLJpRkV/+Rf129NynyjU1y3UhIvUQg9Xp7YXpZ4Q0XmJ5/6GBfiZv0bl2g1/JTl fzCdLKktYp+WTe7POkTqpkmLwcuK0 X-Received: by 2002:a17:907:b0e:b0:77a:d97d:9afc with SMTP id h14-20020a1709070b0e00b0077ad97d9afcmr12925517ejl.199.1663107321099; Tue, 13 Sep 2022 15:15:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4JrvdPCBd450Ne/WjVuyF2pyNqC+OiG8iXf5IJ2s1pVhR/kJe8SiZhf2Ce+d/6Pv1DDaJDow== X-Received: by 2002:a17:907:b0e:b0:77a:d97d:9afc with SMTP id h14-20020a1709070b0e00b0077ad97d9afcmr12925509ejl.199.1663107320962; Tue, 13 Sep 2022 15:15:20 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id g17-20020a170906c19100b0073dbc35a0desm6628493ejz.100.2022.09.13.15.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 15:15:20 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next v2 6/6] drm/arm/hdlcd: debugfs: protect device resources after removal Date: Wed, 14 Sep 2022 00:14:56 +0200 Message-Id: <20220913221456.147937-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913221456.147937-1-dakr@redhat.com> References: <20220913221456.147937-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; }