From patchwork Fri Aug 19 23:10: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: 12949384 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 8CD5FC28D13 for ; Fri, 19 Aug 2022 23:12:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E7C3310EDE2; Fri, 19 Aug 2022 23:12:05 +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 227B710E213 for ; Fri, 19 Aug 2022 23:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950666; 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=MtmSaLbIKauTsp3vMqjOSjI37p5UyDFZTiWRLooemKepfKHAqQvmiKFOkdvo4AvQq0A2HW W72lOJjKDwYGp84rc7gYbgpN+SBKFNbwgCQNqXJn1VBtQzRCgdRA05H9gDCm6CJaYnQ4GR vptcMJZcV5wqrXIZ0X4pR/jXM8YwyOE= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-255-JH62tAFfN4q8v2em-bTyEw-1; Fri, 19 Aug 2022 19:11:04 -0400 X-MC-Unique: JH62tAFfN4q8v2em-bTyEw-1 Received: by mail-ej1-f70.google.com with SMTP id gn23-20020a1709070d1700b0073094d0e02cso1995893ejc.20 for ; Fri, 19 Aug 2022 16:11: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; bh=FE6F/FaZU56VVek/ild/rdOe20eLgXYTWVytxZbV5OU=; b=e8GrEvclHjfRDMmitH00Mc4P6FBBUbkXGXHUdBs6LmCyOJEusPjMzymi+s6+ESeypH Hu2w1DOV/hdW+/wcXobCw9vwhy8OfNK5698aXjus1r0ESBotlFe0XT3QuRCpRGo+Zi6J qdjN2fWfvfWlbk/ckTqF+KO8vUjH88MMIOgMv1NXevO6z5r0YE24osLR2eW7KKcuRB6h Jxm9BxgTqur+FmuijXg8KeX50hh6pNn0sTuhIExHVbkmXAdYFnGV9zyD2MZS6PXCLXLL 02+cqHWxjWQa4JuOjxWhBwDmHdMV/DSLvRXWz0/mgo45UEe/fnQIYAE6rw0oYSoVtOBF nvPw== X-Gm-Message-State: ACgBeo11gcYme7z4SUXH8bauBbV+mP9wDngBkkHSi46WQTI5gwrwqC9b 6+p0WounoD3MMP4OKM5VCH1E95X8qVh5ixXZNOn5kMXOy11kx1tpCBpfYawAZtygIIGHqTOr37Q Nzi9RL/wBARzlruL5zEc2APzvOvbI X-Received: by 2002:a05:6402:26c9:b0:446:354a:ede4 with SMTP id x9-20020a05640226c900b00446354aede4mr4448974edd.424.1660950663421; Fri, 19 Aug 2022 16:11:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6BLVr1Yg+PkMQqjnyOamsS7c3J30OI7E+eQHw0nlsYqnq4YTHzerFj8CavCvwWsievdP/amQ== X-Received: by 2002:a05:6402:26c9:b0:446:354a:ede4 with SMTP id x9-20020a05640226c900b00446354aede4mr4448960edd.424.1660950663264; Fri, 19 Aug 2022 16:11:03 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id ss28-20020a170907c01c00b00730a18a8b68sm2887088ejc.130.2022.08.19.16.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11:02 -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 1/7] drm/arm/hdlcd: use drmm_* to allocate driver structures Date: Sat, 20 Aug 2022 01:10:52 +0200 Message-Id: <20220819231058.647658-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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 Fri Aug 19 23:10: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: 12949383 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 272EEC28D13 for ; Fri, 19 Aug 2022 23:12:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E27AE10E9B6; Fri, 19 Aug 2022 23:11: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 4388410E213 for ; Fri, 19 Aug 2022 23:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950669; 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=JfhSU1AcRnSWC7+tC92yOY1zFYIwd54RSsN40s1CiGzN0bs3DrbsUdD1RHqpGsUNOgG8R4 NW6BQ67wLA4CRe1RUcA+Ycv4JQ+LGyG5stgRXRL9WmPBcJq4LLOsOb57+AY0MMhP+LU2qZ VZVxZW2YGLBHNtHgv4Tq3GD/rd8VsR4= 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-354-KvO_LYn1NqyZxdqWs17BEA-1; Fri, 19 Aug 2022 19:11:08 -0400 X-MC-Unique: KvO_LYn1NqyZxdqWs17BEA-1 Received: by mail-ej1-f72.google.com with SMTP id g18-20020a1709065d1200b0073082300e1fso1942381ejt.12 for ; Fri, 19 Aug 2022 16:11: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; bh=zE4vp0voY9uQjkQjmHJf9kE7FYAP7kTVaTS+8HIh/tE=; b=yMXiye6DZltP9/6TdHf8v57OjuFrjOljnmaoyb7gDD5K7urGw9MxOtY27bw0k5phoZ GkWfVDqjddXVgSYg4SHkEUz/WgQc+WnkyZbcW9ndfOYvO4LCGMPs0OwiKspQC7nncxyP ciqxcT0JZ3XvIRXCtybsHpjZLK3UiI+GIPEzkYaC8QXgfspyOG53JLBYbQSHC4laLVQM Tk8qEqVcej1z49QSmkhZIHAULF2NiOXowZzbY5MVWnDBEhLeubgFYvnVVd9P36g/N1a+ fDNQ0Bhef17TDROeAYbvY2GD8SpH7Vndg2IVjFMYLvi4DqU/rfdPuJE3TzCEBrPjqrco 8SaQ== X-Gm-Message-State: ACgBeo028pNlc7TlKaAu0PwNYdtpTFmymnrteei+hxzs1lrmuft9a0dr nkMYhQ9BGUf9ks9JBJ6w6g2JynWvdJDlO99EZG75vlIW1b7NL0nGu2WYHcWMiZYo/+OGGjxkzmh mb6VkiwICiZSnXaZjuHtiF8Y1vx/N X-Received: by 2002:a05:6402:4407:b0:43f:68b8:3358 with SMTP id y7-20020a056402440700b0043f68b83358mr7653910eda.215.1660950667174; Fri, 19 Aug 2022 16:11:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XXSBauExpDyHCPOh+rGZm4yhkBfQtEDjqIJnq8eNLc63PAUAH+xTLtF7VgUFav7SSgkv9Xg== X-Received: by 2002:a05:6402:4407:b0:43f:68b8:3358 with SMTP id y7-20020a056402440700b0043f68b83358mr7653895eda.215.1660950667040; Fri, 19 Aug 2022 16:11:07 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id w20-20020a1709060a1400b007303fe58eb2sm2844636ejf.154.2022.08.19.16.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11: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 2/7] drm/arm/hdlcd: replace drm->dev_private with drm_to_hdlcd_priv() Date: Sat, 20 Aug 2022 01:10:53 +0200 Message-Id: <20220819231058.647658-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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 Fri Aug 19 23:10: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: 12949381 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 DC80EC28D13 for ; Fri, 19 Aug 2022 23:12:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1610510E4B4; Fri, 19 Aug 2022 23:11: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 A0A7910E213 for ; Fri, 19 Aug 2022 23:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950670; 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=PnCDG3mxiOjW2BQahm8w1uA8IQzG3msjFuLKpKinCI8975HodqOhPnBruWyDQg8hgl/SaG 8iwcdGeqAcRzyNP92OCL9XqZqN1m/jjhS/0ri0JzbYnvWXrUg4CjoBWpHnEP8L/Ohb6DDT 0217RWaY8Tx+gsL6IldVyzj8rJvu4yA= 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-73-3ICOLQCyN527Esq0ELL9yA-1; Fri, 19 Aug 2022 19:11:09 -0400 X-MC-Unique: 3ICOLQCyN527Esq0ELL9yA-1 Received: by mail-ed1-f72.google.com with SMTP id r12-20020a05640251cc00b00440647ec649so3506589edd.21 for ; Fri, 19 Aug 2022 16:11:09 -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; bh=7wDtbQGLiE39PVFtlUhXuYz+XJ8dWxVCvJywCPPxRNQ=; b=yoQ8E/s9JZ8DpPCZVRg+KvVv/G++PR68jy7mLl3GFgm6WzE6O7ZMUiupiduvM3jT8M mjTH5gSfpY0PoB6lbodvcHOdP1mDmIrjnSqG6CHghvi5tMJa0eeFfXUk/vyzzBhf4bTU 61z3dpveqZWV3HaTc6V6wTjs/eRxRvoLZwounsLI8bdKjzHV2vpmzdOyVLZyTFXb/JVN cWb8e6jmRNNhCLIL5mCvdWghUVxRwAzGpXTPl5ZbWpZoWjyyBYuEfhcOZVaX5m5VGW3I 35LSTYAmVCtRoJoEilbCDRMuFD/40yVd7ww2PWicRAUK/AUUMPIBM0AEeu3X+wvwusdv EVcw== X-Gm-Message-State: ACgBeo0hqnrqst2jxjyYP7OuAl6Y2wl8LT2yjYnIszSmbvrFyFXafVku 7CmAzSor47X8KUHa0u/hyeq5mbn9Tt9DkSHWRFa03foHg2Skjt1qG545mXYtjvvP01Ashe39Y3U RVWM1e0GCanMBQR9YPaljauqEQ0ux X-Received: by 2002:a05:6402:d57:b0:445:fba7:422d with SMTP id ec23-20020a0564020d5700b00445fba7422dmr7839118edb.138.1660950668522; Fri, 19 Aug 2022 16:11:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ZHmzoVrJtKFNxyLeq3xlHQ8rgV2AX90b7fLIXFYEYTM65oS0HV/TmNv1//+V+iUNwTnHqfA== X-Received: by 2002:a05:6402:d57:b0:445:fba7:422d with SMTP id ec23-20020a0564020d5700b00445fba7422dmr7839114edb.138.1660950668409; Fri, 19 Aug 2022 16:11:08 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id w20-20020a1709060a1400b007303fe58eb2sm2844636ejf.154.2022.08.19.16.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11:07 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 3/7] drm/arm/hdlcd: crtc: use drmm_crtc_init_with_planes() Date: Sat, 20 Aug 2022 01:10:54 +0200 Message-Id: <20220819231058.647658-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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 Fri Aug 19 23:10: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: 12949385 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 301FFC28D13 for ; Fri, 19 Aug 2022 23:12:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E7D2310EE0C; Fri, 19 Aug 2022 23:12:06 +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 20C5910E2A8 for ; Fri, 19 Aug 2022 23:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950676; 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=iYHmoAkb5J55xsl5qCm8HSDA7lpg5xBB78ANEy2x+7AJBh1cS0xAFZdYo+hC1h6ik25Ze4 oKrAtBZAr8975PD2x8j6wuomIrP/urlR2vMWQqv8cFGXuda1rzb4f4huzj6riKEAc9EmND l0MxnXL9PN99csbv4FOPonenHKqXpPc= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-638-hBiLaaiXPeWnavmRkKNTSQ-1; Fri, 19 Aug 2022 19:11:13 -0400 X-MC-Unique: hBiLaaiXPeWnavmRkKNTSQ-1 Received: by mail-ej1-f70.google.com with SMTP id ne41-20020a1709077ba900b00730cde40757so1981258ejc.23 for ; Fri, 19 Aug 2022 16:11: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; bh=NEM+8qA1l934tBlwuTsd8qBaVhltlHSYDFpUMi13koI=; b=rkHEiHiAGDGy6BVVxPabwk9c6KNf+tg4IpnRXeAhOwK4R4MaeewMO4MvuI3t2xg7uF lvdYWVi+JYnFDMOkHK8IwxPl+P54fl2ErcZTLpYD+0Vjz0uPDLmrs1Ah5UJRXQJ/TsSd 7IvnOnA5nmgn8aB1dkJPQcUKSTNrNn54UKDZ5WEeIgAYQQdw++xVd0w8lAZkGERwsS+K vIcoa94Ipxx3Mk7X5/mWRVemhSIQOBPv6AZ0K3S5irXqsl2dMvdOtm1w+zW/RKQU/J6C 6gH41mc07MddB7ZOHT1kYC66ldMzBVFqhu8ixdZqsEtdnOaXHfhRj9mJetUm9Oo7wQg+ NwNw== X-Gm-Message-State: ACgBeo3vt8zAiJqtbH86qgZnKH5mcweY/+t9uKsW1ICxx0NynRvBwhcX AhfLmg/S4R8GmqtSNpLTYLsX8LZddK4+wLzZIAzrpB68eK1CyHEFjAK7DZZRt28CugIGvguAsL6 0MUSrr3rHrEE+9mQm/NjgiLRN85vQ X-Received: by 2002:a17:907:2cc8:b0:731:53a3:4a33 with SMTP id hg8-20020a1709072cc800b0073153a34a33mr6108586ejc.319.1660950672267; Fri, 19 Aug 2022 16:11:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GbQdWDrH/DBv3IsFTvk98vTg0mBEa1EE3Vrq8PDQzt77Aq61RsfVlf+iGoDPMkaLpdChNgg== X-Received: by 2002:a17:907:2cc8:b0:731:53a3:4a33 with SMTP id hg8-20020a1709072cc800b0073153a34a33mr6108579ejc.319.1660950672150; Fri, 19 Aug 2022 16:11:12 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id da7-20020a056402176700b0043a61f6c389sm3761651edb.4.2022.08.19.16.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11:11 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 4/7] drm/arm/hdlcd: plane: use drm managed resources Date: Sat, 20 Aug 2022 01:10:55 +0200 Message-Id: <20220819231058.647658-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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 Fri Aug 19 23:10: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: 12949386 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 E3918C28D13 for ; Fri, 19 Aug 2022 23:12:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C1D4310EE74; Fri, 19 Aug 2022 23:12:17 +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 6C34710E38A for ; Fri, 19 Aug 2022 23:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950683; 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=Stn6rB+1lviyJrNtkGFiQfUAmiCQyX0UUqdO8eW2IYX16j/IvvNnKv/gkv/sS0fD3cvUDL jLP3C1C/4QX1J4Pi2SLfYNtLCvq3fRfQLa8hMWPSoqBWk4MbMXyhy48znsgQol1Ivdo+Nw f7lHKC40cpmkcqOoDZg2DIYc2HnqC2I= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-573-A3KoIPL2PZGZivsH60JBxw-1; Fri, 19 Aug 2022 19:11:14 -0400 X-MC-Unique: A3KoIPL2PZGZivsH60JBxw-1 Received: by mail-ej1-f70.google.com with SMTP id js11-20020a17090797cb00b00730d73eac83so1943577ejc.19 for ; Fri, 19 Aug 2022 16:11: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; bh=AFFGKxt+Rynb6H3rLFquNUiuipOW4GaSN2+USkzDWw0=; b=Ig3s4xkPEk4AZxLpBx90wh7PP+3W7UOqBLG8dSbp/fcxbqzSlj83ZZNW14L+LR4uGK 8nRl82JYM2ydQ6xo46qI+YQ/UPcZqVj8Fhg3+QFkh+99tN7Nbh1eJBcSasRGrwoAgCBN rOnJsUXU9kY26LbwfKyhEh5HzxqM7eN5nIGWmFgL3mxO7tmimPBfN9GVOPex49qk30Cv xpGvNApiOsD/UUUa2LnOdnl0ENeSVGCnJhxQvp1Xf09VUOlaeH/1uS5X/gflURYmYUas 8HM5AiWcJt/9HZ91km86XJj0i+opWl86lxOoB9JLqzgv7/zf8TlfzI8VeMFp23ndjlj3 vxLw== X-Gm-Message-State: ACgBeo3PLRBZWwG2mBonZqwikx6RCNkvvFe7cGfDo2u4tLingNHR8uga MTgbwR+wMYc/byxrUkB9wAW90K8yaxftd7YOMZ0Gp7jR64FCENuAfQNvGxho6L0vGkLhk3vacEd J5biCoPXQymd4YSzpx/+esuBWtx2h X-Received: by 2002:a05:6402:b37:b0:446:79cb:8ed2 with SMTP id bo23-20020a0564020b3700b0044679cb8ed2mr22591edb.265.1660950673505; Fri, 19 Aug 2022 16:11:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR6I47xkeEdQdkJwg0IElCbZlxTvQ3PAI/2KK3WH2jBuBVpkk+QFYyUaoLDoZHy4tthJHuyR9g== X-Received: by 2002:a05:6402:b37:b0:446:79cb:8ed2 with SMTP id bo23-20020a0564020b3700b0044679cb8ed2mr22583edb.265.1660950673381; Fri, 19 Aug 2022 16:11:13 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id da7-20020a056402176700b0043a61f6c389sm3761651edb.4.2022.08.19.16.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11: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 5/7] drm/arm/hdlcd: use drm_dev_unplug() Date: Sat, 20 Aug 2022 01:10:56 +0200 Message-Id: <20220819231058.647658-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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 Fri Aug 19 23:10:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949387 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 E0A79C28D13 for ; Fri, 19 Aug 2022 23:12:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 236F410EE25; Fri, 19 Aug 2022 23:12:23 +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 B9B7C10E235 for ; Fri, 19 Aug 2022 23:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950681; 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=T/aEmMYx0Z02iP/p2oS3LA3F3/Yuzt+yoboJt4rC9G2uQaGTa+79lIJq9q93/FLc2cNLx8 GwqKJXEjy1feU106e6s45jB8MUBfFML1rd+vxIbS6q+VUzaLWmAG13krpJ94DPyICidmF0 HynJDmDlv5wFIwWqzFQI4GsEQ2svJgY= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-399-_D_eFWOIN9ieN5PUylf7IA-1; Fri, 19 Aug 2022 19:11:18 -0400 X-MC-Unique: _D_eFWOIN9ieN5PUylf7IA-1 Received: by mail-ej1-f69.google.com with SMTP id hs4-20020a1709073e8400b0073d66965277so43006ejc.6 for ; Fri, 19 Aug 2022 16:11: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; bh=dLZfq6WypLg+PIKaSCfWFhdUOS8zDvxPUxnHNhKzURQ=; b=EywC6yHt4GcjpkeiCHFr6e0EPhQjMD9cMazy1htgowK9OBBSl/qNlEkACpNa5QHCvK FG+mBdDCoshzINDosd/pi28OLr4dh2pW9pKbLTkx6M/X6GJNVpTL5eCXMcW8vPXbcsyK 3BVJ5ksoVfk4d+QbUArWtSySjgh/aBNTDQNnbt8TeH7raD50ubiVPdVdgSkyqPwzendY K6CzjRXqNCiHP/7to572ISWGYwSLDQwSNkYjpjU/qHkepYmgXeNklw3FEnb+EDyUWM7U 5U1qtx+xxA3aaV55mNAF8vJ42kUxFyaOZEp6zLJESKrHw6FDtLR9AeTanUdguZoojniU 1Y/A== X-Gm-Message-State: ACgBeo1edOaH1Vowc8vOCVwqUpFk2BIGEBFxLmZj5FKdpAbYQWQQjxGL Ylf6V+pqAauq636nirkfFi+OscdcUk5CUqymxhtS1iUMcgjqj62dTtxbKVAC8EfjMir92Zi8s+B kUph1qh1uK8kbDAQj/h4zyWQe9Usl X-Received: by 2002:a05:6402:e86:b0:440:d1be:20c7 with SMTP id h6-20020a0564020e8600b00440d1be20c7mr7754763eda.349.1660950677278; Fri, 19 Aug 2022 16:11:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JSK2TMkoebbHT5LMUu2crmMcWGvQOKm5f0GW7UmQ4oCu69y9RiVIrSgGRUCD1OxOpCrbX3g== X-Received: by 2002:a05:6402:e86:b0:440:d1be:20c7 with SMTP id h6-20020a0564020e8600b00440d1be20c7mr7754751eda.349.1660950677134; Fri, 19 Aug 2022 16:11:17 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id d5-20020a17090694c500b00734bfab4d59sm2923078ejy.170.2022.08.19.16.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11: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 6/7] drm/arm/hdlcd: crtc: protect device resources after removal Date: Sat, 20 Aug 2022 01:10:57 +0200 Message-Id: <20220819231058.647658-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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 Fri Aug 19 23:10:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12949382 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 0FB5DC28D13 for ; Fri, 19 Aug 2022 23:12:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B4C7710E8A6; Fri, 19 Aug 2022 23:11: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 A5ACB10E2A8 for ; Fri, 19 Aug 2022 23:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950682; 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=K0V69/D1v5GdJEuqgM+WnyML/MwsbQUQK64cQCNQ1vVv3+WEkOEg2CCdNBJtHwapQ4NL9F C5YeaT4sOpz8L5tiljpGhmwLnoA0uESvfPXXtXhfU7dggGSZuQx0PlIwyVLxwk5060XSco Uy+YVjP/ObtcLbcO+j1vOec7gLwdmLo= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-380-DOF5dr8xN2qxSb-WAEH_lA-1; Fri, 19 Aug 2022 19:11:21 -0400 X-MC-Unique: DOF5dr8xN2qxSb-WAEH_lA-1 Received: by mail-ej1-f70.google.com with SMTP id sa33-20020a1709076d2100b0073101bdd612so1947530ejc.14 for ; Fri, 19 Aug 2022 16:11:19 -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; bh=0y/a4pTSF6VtadOpwMNTC/mvZDJbVIcTrD8TXNTMH9w=; b=KiGvcz6rGpwxrB3+FJ+jXw8cEwxoAGeKTpmFNEKtLUJNTIYTCzL/ainYQO2+yIWuKO SSc/QwLJmn+DnL1lVQLjtzp4I2llinJMUWGB/suUtkyMiyl5VZJ9aiw7WGyU2TPACPRl +KMT5oXtQYZ8+dy4Vf58WpXspd0jA5apGuWidIwiG++HQPi3PJe7o2VT7vjmJdDK9Z8F JN2iYfOWD5CSARYSHSA1trrXC9h71jF3+jBPj90jJ51WaxOV8Dkl5kV3GgXtMT+AWp6l NDHZe8pY01fgg9F84JXasFwSlcMzk5TPqY+u6WoAwIPxSEqmgWjUpd+aKr04lQ6AVqjR nW/A== X-Gm-Message-State: ACgBeo3rO7KMC0IWleHsAapycgVUKwo4devBjdc7mXVPxkQX1O/DyTrY psmpEu/q+28WzwQ93kbHZkFBsGUZS+h0xskPI+xC3QkuYepT+nIKw3mhPzGthG43ooGpJwHOVRR vhqjfwOHsRcJ/kaXARRJFJszVIWyx X-Received: by 2002:a05:6402:2714:b0:43d:ca4f:d2a2 with SMTP id y20-20020a056402271400b0043dca4fd2a2mr7764364edd.185.1660950678567; Fri, 19 Aug 2022 16:11:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5t8ZWTVk4y4Y4BTXVKS9pOWxmu4s8KtL9YowyUh5bjRrc9ssHwXdvbPAqefLHaOgjt3XLApA== X-Received: by 2002:a05:6402:2714:b0:43d:ca4f:d2a2 with SMTP id y20-20020a056402271400b0043dca4fd2a2mr7764349edd.185.1660950678398; Fri, 19 Aug 2022 16:11:18 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id d5-20020a17090694c500b00734bfab4d59sm2923078ejy.170.2022.08.19.16.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 16:11:18 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, liviu.dudau@arm.com, brian.starkey@arm.com Subject: [PATCH drm-misc-next 7/7] drm/arm/hdlcd: debugfs: protect device resources after removal Date: Sat, 20 Aug 2022 01:10:58 +0200 Message-Id: <20220819231058.647658-8-dakr@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819231058.647658-1-dakr@redhat.com> References: <20220819231058.647658-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; }