From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2659BC28D13 for ; Fri, 19 Aug 2022 23:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243587AbiHSXLM (ORCPT ); Fri, 19 Aug 2022 19:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243553AbiHSXLI (ORCPT ); Fri, 19 Aug 2022 19:11:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C56D7B8A42 for ; Fri, 19 Aug 2022 16:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FE6F/FaZU56VVek/ild/rdOe20eLgXYTWVytxZbV5OU=; b=YWNqS+qF22ppNcRD7PZeCE1EQwAnvVpXlcIo1O3Hxjb4UofMfaEWYZcQliN65UUiFrhj4x QWrIz6LLDJmeZynvz6tjabIAe7hnXBRWPdgOygS4DW6zq3LTQIo6e2RFxlTDwnOTdkLCM1 dtn9wCnu7e3hVAvu6LaT5IG7oXGnUQA= 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-148-I3M3MW3BPhqp92R5sMOPZw-1; Fri, 19 Aug 2022 19:11:04 -0400 X-MC-Unique: I3M3MW3BPhqp92R5sMOPZw-1 Received: by mail-ej1-f69.google.com with SMTP id qw34-20020a1709066a2200b00730ca5a94bfso1952183ejc.3 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=uW9NnN7KPB2Wa4xBqYxCBpvZvY7l5KcrydVxfVQKU9aZKFN+Y0xgbQhrrcjP9rhPLN cmHxHYBkWCwOZYbHTVUsYg+2p6BmeSDaw/5JQyxlfTuawBOAQVW6Fbqro1Y/v/AyVgAx rx42Y6uO1xSuUONqQaXesc6+VQJRo5Kb+Q50G4PlKXpfy/vxEN5WXnSXxxmfiAXcW6bi Gul7te2p26lQkekTATZrrcN9oMhNwo2qZ4RqWSXES8TtS1fZABukNu6VNkMFyr7nADE0 bMuTlg2dj3+S1S3nM7vXq+RJ5P9PmiHRcfOkEbMpxogr7I0yKRJhRywRy0Y7AqTac3k0 SQrA== X-Gm-Message-State: ACgBeo3Kq6Qh5I9twv8wsuHqcWEOreQCXMVLyR08fuFiMAQtlOgi9Nhq 26kKZt+xWv4PqoEa7ZB0/j+uIovuVNIrvXczdcszxrNYW40Invq8K2CjzccRWqgI1T+bPnvO9xH +OZQDUWmwzFmh5zgvKZ1FPq/C X-Received: by 2002:a05:6402:26c9:b0:446:354a:ede4 with SMTP id x9-20020a05640226c900b00446354aede4mr4448973edd.424.1660950663414; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_dr= v.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; =20 - hdlcd =3D devm_kzalloc(dev, sizeof(*hdlcd), GFP_KERNEL); - if (!hdlcd) - return -ENOMEM; + hdlcd =3D devm_drm_dev_alloc(dev, &hdlcd_driver, typeof(*hdlcd), base); + if (IS_ERR(hdlcd)) + return PTR_ERR(hdlcd); =20 - drm =3D drm_dev_alloc(&hdlcd_driver, dev); - if (IS_ERR(drm)) - return PTR_ERR(drm); + drm =3D &hdlcd->base; =20 drm->dev_private =3D 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); =20 return ret; } @@ -344,7 +341,6 @@ static void hdlcd_drm_unbind(struct device *dev) drm_mode_config_cleanup(drm); drm->dev_private =3D NULL; dev_set_drvdata(dev, NULL); - drm_dev_put(drm); } =20 static const struct component_master_ops hdlcd_master_ops =3D { diff --git a/drivers/gpu/drm/arm/hdlcd_drv.h b/drivers/gpu/drm/arm/hdlcd_dr= v.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__ =20 struct hdlcd_drm_private { + struct drm_device base; void __iomem *mmio; struct clk *clk; struct drm_crtc crtc; --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DF04C28D13 for ; Fri, 19 Aug 2022 23:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242093AbiHSXLT (ORCPT ); Fri, 19 Aug 2022 19:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240693AbiHSXLL (ORCPT ); Fri, 19 Aug 2022 19:11:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E54B69E8 for ; Fri, 19 Aug 2022 16:11:10 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zE4vp0voY9uQjkQjmHJf9kE7FYAP7kTVaTS+8HIh/tE=; b=XZu6COxwMPb7lFW4ZPPzuAuOczMF9uYnfEfvh9PwX6hchVne7kfxpaB6M+f4c8G7IHO45S xTYFqBNah7C5kyv8XFyBjLSu+z5OG+yLlvl3w1UxBHNognOE/Q0p8Ls4JUcxZ0SSDnkTMw FMwdjuAFOhzjG6N8DZxlPePCe6ovQaE= 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-245-2CXtklsTMgG1nJA1DBoEMA-1; Fri, 19 Aug 2022 19:11:08 -0400 X-MC-Unique: 2CXtklsTMgG1nJA1DBoEMA-1 Received: by mail-ej1-f72.google.com with SMTP id js11-20020a17090797cb00b00730d73eac83so1943430ejc.19 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=HQRq4e6fZIs1QWX1LXiTNfR9rlJxMeWkHhPE2o+PWxjTFc6UssZrbJC90gfNcDiZHJ v7i+0UlmGperE7MzhIWbcRMZOr7fmENOYzxnUU+ngSczVUfvITOst/0/VaYQv5oqiBvv 75o/qa58gKyQfs24nVTLUo+kMnKq4nbm5M4ODqlMPc7eQXOX3xMHDmmAGM6YUM4y2QF0 MClJz/jadV66mH0ZDE8HW26XWKqM+ZhNaKbLfjEkPPghIxKY79rCO2FOElkWbXYi9RRW wm+BiDdVG+rkIVp+jQtLKlXRtbki5bzt4Csc1TE2T5oGR3hdQRguC479GQ9POEt4G41l TivQ== X-Gm-Message-State: ACgBeo1mSP7/Z1eS/L9mUO1Zt6oks60uAoY3gbSAqIigH4+3zeedRyi7 oRvrDnbG3V1hb49A7yDDfln8ufX75T30dWHuOlJrWpml27zbapxdkrR5cpssKDw/E9ibRy1wRwU Wesfvq/P9XbMdtBNhb7GmT5Ej X-Received: by 2002:a05:6402:4407:b0:43f:68b8:3358 with SMTP id y7-20020a056402440700b0043f68b83358mr7653912eda.215.1660950667177; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_c= rtc.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 =3D drm_rect_height(&new_plane_state->dst); scanout_start =3D drm_fb_dma_get_gem_addr(fb, new_plane_state, 0); =20 - hdlcd =3D plane->dev->dev_private; + hdlcd =3D 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_de= vice *drm) =20 int hdlcd_setup_crtc(struct drm_device *drm) { - struct hdlcd_drm_private *hdlcd =3D drm->dev_private; + struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); struct drm_plane *primary; int ret; =20 diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_dr= v.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) =20 static int hdlcd_load(struct drm_device *drm, unsigned long flags) { - struct hdlcd_drm_private *hdlcd =3D drm->dev_private; + struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); struct platform_device *pdev =3D 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 =3D (struct drm_info_node *)m->private; struct drm_device *drm =3D node->minor->dev; - struct hdlcd_drm_private *hdlcd =3D drm->dev_private; + struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); =20 seq_printf(m, "underrun : %d\n", atomic_read(&hdlcd->buffer_underrun_coun= t)); 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 =3D (struct drm_info_node *)m->private; struct drm_device *drm =3D node->minor->dev; - struct hdlcd_drm_private *hdlcd =3D drm->dev_private; + struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); unsigned long clkrate =3D clk_get_rate(hdlcd->clk); unsigned long mode_clock =3D hdlcd->crtc.mode.crtc_clock * 1000; =20 @@ -253,7 +253,6 @@ static int hdlcd_drm_bind(struct device *dev) =20 drm =3D &hdlcd->base; =20 - drm->dev_private =3D hdlcd; dev_set_drvdata(dev, drm); =20 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 =3D dev_get_drvdata(dev); - struct hdlcd_drm_private *hdlcd =3D drm->dev_private; + struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); =20 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 =3D NULL; dev_set_drvdata(dev, NULL); } =20 diff --git a/drivers/gpu/drm/arm/hdlcd_drv.h b/drivers/gpu/drm/arm/hdlcd_dr= v.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 }; =20 +#define drm_to_hdlcd_priv(x) container_of(x, struct hdlcd_drm_private, bas= e) #define crtc_to_hdlcd_priv(x) container_of(x, struct hdlcd_drm_private, cr= tc) =20 static inline void hdlcd_write(struct hdlcd_drm_private *hdlcd, --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37C62C28D13 for ; Fri, 19 Aug 2022 23:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243739AbiHSXL1 (ORCPT ); Fri, 19 Aug 2022 19:11:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243553AbiHSXLN (ORCPT ); Fri, 19 Aug 2022 19:11:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD2E9B9586 for ; Fri, 19 Aug 2022 16:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7wDtbQGLiE39PVFtlUhXuYz+XJ8dWxVCvJywCPPxRNQ=; b=TvTySDGvF1dE6UogjvpNOPDjZW4g1uOAqs9FlKlYSAqz+M3IlPMPdM9J1Xg0Vyus4Iue9G ORz8fgwRZOiLcMmLfdaVArJlrrf0qdBQFjfpNG9aICUk+t5dId9qWb0Zxx1gx1RkKl3U4w 9hev4+yY5NiQof8nQS6hgVsoQ9AZ4yY= 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-526-CuKz5kdjO9qFZMxxHkzoSA-1; Fri, 19 Aug 2022 19:11:09 -0400 X-MC-Unique: CuKz5kdjO9qFZMxxHkzoSA-1 Received: by mail-ed1-f71.google.com with SMTP id j19-20020a05640211d300b0043ddce5c23aso3448984edw.14 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=K+CZKjKZ3i2qAwA/YTTgUPLggi95Dx6wIzD1EFG8xccMuS/As9ixCCcWHft+hpdf6f 4ZNvboUr9WN4RmBmPcW3+epqYDiQpZHBkHvBbb+cT84fWCUfkah+Ew6axo7QqD5VSbuo tXDiMitI1PyNZOUzQjnbq0eu7ACVhvnUADV41WI/3A1ZzwH5RvMTyJF6DfZPXUXi5ciU b7O1zbauvulogQtogR9VAGZXfPxyoN+gURW3rGMw/eqwPSNytWUBEWa5Fye9eWCHS8VQ RSN4fTppxh7Ho+EBTSL/Qbg/okttJzQCU5QySeb8IHuAESK39szOf70BhEvmTWjvf/b5 ZAHw== X-Gm-Message-State: ACgBeo0krs3YEov63o2SKtZ2VWf7nhS6MoReArGp7CedO7jhcKu4nFNK Ldi2l79YGjfeQXUfANMaftrYFb99dKyWQZHfQwMGJErGlAfwK8vmMhYiP+AWEYu+eMqNyru9hU2 7h2wZLXqWVHzcBow7gGMbQL+E X-Received: by 2002:a05:6402:d57:b0:445:fba7:422d with SMTP id ec23-20020a0564020d5700b00445fba7422dmr7839122edb.138.1660950668523; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_c= rtc.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) =20 /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); - drm_crtc_cleanup(crtc); } =20 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); =20 - ret =3D drm_crtc_init_with_planes(drm, &hdlcd->crtc, primary, NULL, - &hdlcd_crtc_funcs, NULL); + ret =3D drmm_crtc_init_with_planes(drm, &hdlcd->crtc, primary, NULL, + &hdlcd_crtc_funcs, NULL); if (ret) return ret; =20 --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D6B3C28D13 for ; Fri, 19 Aug 2022 23:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239452AbiHSXLa (ORCPT ); Fri, 19 Aug 2022 19:11:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243577AbiHSXLZ (ORCPT ); Fri, 19 Aug 2022 19:11:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6055EB8A67 for ; Fri, 19 Aug 2022 16:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NEM+8qA1l934tBlwuTsd8qBaVhltlHSYDFpUMi13koI=; b=jRhQP8MIlNrqtvpwe2H8yi81qxMtEwli4hFvnsJ3zAQKe6mlOqwHHjuK0OOSyxptpfmSeS knoV336f92nHEZMbDZVn3hMecTf9h3ST3uKsGxry6qCoPlEMZzkUUy+gJfOFnSlPYQGbfi 2YwQllBwPv3kW69cUI6cueAGhFbbFAw= 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-537-Y6hVcIzuPEGAAZzdBH-f-w-1; Fri, 19 Aug 2022 19:11:13 -0400 X-MC-Unique: Y6hVcIzuPEGAAZzdBH-f-w-1 Received: by mail-ed1-f70.google.com with SMTP id x20-20020a05640226d400b0043d50aadf3fso3500505edd.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=3XjzYcMCd1kMWOUmKBVQPSmTspTNyZ1+mEzskfLMYjP85lHzSEDHj560bdbgFUbnjq JYesS/MsxKdccNLOzPCBPE76EiYoKf0mAc1wbpUSoLy1gv8ER6bMuHKLKjfS2twSBs31 giOCmLlXzNeNPiFqUj3pHJgWEbY/ie7ii9hDTz/ACZxebSiOS/n0bHW0SJGjTj40AOoP wr9ttBnHv7sBuz7VhIkeHfOaZzF5oLvhAuHnvDXzl0Ip6L4QsZsh7TOiZPUQe2qNVhrd 8fM/EHMBTRcWum84NgMkaKiKipeoPC127K0tBArVtd3A/lUXW+kKCOXyoplbwgH4M+/K XFtA== X-Gm-Message-State: ACgBeo0/EKu0qxNAiaZKBatgAR9M7ovJV/x4pquKmjkpFYXg1CAM+zZM RpqJuELgWerS8VTbuU1OCu14haTIPllUqawjLVtm2exfgk618/p4VLnnhFY3p5H1RGh0CBrzLoS 3wIHJ/fDs7cblRYuD0DNPfEmD X-Received: by 2002:a17:907:2cc8:b0:731:53a3:4a33 with SMTP id hg8-20020a1709072cc800b0073153a34a33mr6108582ejc.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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_c= rtc.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 =3D { static const struct drm_plane_funcs hdlcd_plane_funcs =3D { .update_plane =3D drm_atomic_helper_update_plane, .disable_plane =3D drm_atomic_helper_disable_plane, - .destroy =3D drm_plane_cleanup, .reset =3D drm_atomic_helper_plane_reset, .atomic_duplicate_state =3D drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state =3D drm_atomic_helper_plane_destroy_state, @@ -297,24 +296,19 @@ static const struct drm_plane_funcs hdlcd_plane_funcs= =3D { =20 static struct drm_plane *hdlcd_plane_init(struct drm_device *drm) { - struct hdlcd_drm_private *hdlcd =3D drm->dev_private; + struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); struct drm_plane *plane =3D NULL; u32 formats[ARRAY_SIZE(supported_formats)], i; - int ret; - - plane =3D devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL); - if (!plane) - return ERR_PTR(-ENOMEM); =20 for (i =3D 0; i < ARRAY_SIZE(supported_formats); i++) formats[i] =3D supported_formats[i].fourcc; =20 - ret =3D 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 =3D 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; =20 drm_plane_helper_add(plane, &hdlcd_plane_helper_funcs); hdlcd->plane =3D plane; --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D66FDC28D13 for ; Fri, 19 Aug 2022 23:11:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243877AbiHSXLo (ORCPT ); Fri, 19 Aug 2022 19:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243735AbiHSXL1 (ORCPT ); Fri, 19 Aug 2022 19:11:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F66DB066 for ; Fri, 19 Aug 2022 16:11:24 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AFFGKxt+Rynb6H3rLFquNUiuipOW4GaSN2+USkzDWw0=; b=djyuI2kx3GJL3V+WioTbWxkfrJMauburDl4tEVw4/jG2LPuFiK12iPtOhDTXJWoJMCu2CB CJOmXeH9OgLJreZMy63e/oZrjL2HfSu7HJuBOxwZ2hBPmbTrkuVGSORxpuwgeVvsnUHpDz u4bYweeof3DhYvqxXqpj3CMccJJvgKc= 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-251-Gif5761qMau8eh-agGmS2w-1; Fri, 19 Aug 2022 19:11:14 -0400 X-MC-Unique: Gif5761qMau8eh-agGmS2w-1 Received: by mail-ej1-f71.google.com with SMTP id qw34-20020a1709066a2200b00730ca5a94bfso1952435ejc.3 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=r7zjmM0OJvzq5G+t7aNUAbUPTxDm4WIVtj4UXlR+JeGxtheM0j6NXtGVI+/mLyIQV3 HUyU59dH5LSeN/T7Zjh0OM6DvILO6gMy/jwewiorqqioFL349pw74nGCHd8YKmWBzxDp f6rhy2KteSYaZGcSFX4ClXkyUoyHmNZUkJjdCiGkAC1jnkj7We+1ZygxNaaoqP8n/QLx qgt9vdl+JevCukS2gysEPm9pvUXPwAQkxMHfBvBDH7ilCb/sWPdbQ1atr6HHHD3Qnw6z t1EIry4BznD/RsZ9qgM2nRlIFiP3Q+oAMMIt3AwGpnrfwwx+a5QGPr5Pb/Y7ta90FgIg 79tg== X-Gm-Message-State: ACgBeo0TqqrMUZdH/l/KTY58SUdfCCXMKDLNa+4wpQCUvZYpm+9e/FQl 4ZoriR1Yf+IX0QzFvIIR/NsZ9ZZ7VOpw4uHiuTIbIuc+iwQTuaD10xDetPhrwiilDbrOlAgmhEe aN2XOqbrwrlnOlN//XKwv5KGu X-Received: by 2002:a05:6402:b37:b0:446:79cb:8ed2 with SMTP id bo23-20020a0564020b3700b0044679cb8ed2mr22589edb.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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_dr= v.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 =3D dev_get_drvdata(dev); struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); =20 - 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); --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05206C28D13 for ; Fri, 19 Aug 2022 23:11:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243778AbiHSXLe (ORCPT ); Fri, 19 Aug 2022 19:11:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243670AbiHSXL0 (ORCPT ); Fri, 19 Aug 2022 19:11:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87263C7B94 for ; Fri, 19 Aug 2022 16:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dLZfq6WypLg+PIKaSCfWFhdUOS8zDvxPUxnHNhKzURQ=; b=JJckpCDRtd3eAtZcJTCcnMblUOLi2J8IBG6t2DpM6DqiQPLiVz1fkoAJlESEzxEBuChExQ eHBgh2X/YQg5+7C/BE1bHzlUNM4H7eopd5LUXkjMjhtrWMY2rM1CrSHwF2MeWuTlsK9h+w TuUlbZQkArHDIVeQ1vxCp0AIExvmi9c= 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-36-dJKUwvnHP9S9DVqZcY_fUw-1; Fri, 19 Aug 2022 19:11:18 -0400 X-MC-Unique: dJKUwvnHP9S9DVqZcY_fUw-1 Received: by mail-ej1-f69.google.com with SMTP id sd6-20020a1709076e0600b0073315809fb5so1952387ejc.10 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=5/hjeMu9/5Cm7SCTcuR7j18W2kTgyaoXd1wK3GiURCTBsPDTaa2rq9luPqGD4SZoU5 1SlJykxBbQZCoOA89cU7cBo0m1yG0kSHvZf0CguJ6WWj0lYk9zqGyYK+z16q133JV6G5 315yZC0wOU2YtYsaCS3d3Gt82XxzEwZ+H1/7V9Z9Dm24gVKYodnNvhtFwAHF8pP1MR8I LZjliRoKB1CBg4ZSitz3+FbxkDbHwBTFqtYhBFWaMFDu+OnkmAY/y6/pkpFmcHcWmBm9 aMOzadPOcndwXSg7l398mXIySoJj49VJS2FyDz1jC0+Mhjk0gZMNB3wYMsjgTOvuRK4v 2npA== X-Gm-Message-State: ACgBeo0nibkAs1KE2NJ5Y6D9ZTt2lqLGeqMs7lVCLVohcSBMrf4glc/7 E2x/v5cC1eIxyXqmkPNc5JXRxWsmx5E+8JCZofuaDWaPXJZOawLBbO8oKvqLuqaOVTiot7QsMoD HUl0DeY4F+XYtZn7hQo4iRssz X-Received: by 2002:a05:6402:e86:b0:440:d1be:20c7 with SMTP id h6-20020a0564020e8600b00440d1be20c7mr7754762eda.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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" (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_c= rtc.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 =3D crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; =20 /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); + + drm_dev_exit(idx); } =20 static int hdlcd_crtc_enable_vblank(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd =3D crtc_to_hdlcd_priv(crtc); - unsigned int mask =3D hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); + unsigned int mask; + int idx; =20 + if (!drm_dev_enter(crtc->dev, &idx)) + return -ENODEV; + + mask =3D hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask | HDLCD_INTERRUPT_VSYNC); =20 + drm_dev_exit(idx); + return 0; } =20 static void hdlcd_crtc_disable_vblank(struct drm_crtc *crtc) { struct hdlcd_drm_private *hdlcd =3D crtc_to_hdlcd_priv(crtc); - unsigned int mask =3D hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); + unsigned int mask; + int idx; =20 + if (!drm_dev_enter(crtc->dev, &idx)) + return; + + mask =3D hdlcd_read(hdlcd, HDLCD_REG_INT_MASK); hdlcd_write(hdlcd, HDLCD_REG_INT_MASK, mask & ~HDLCD_INTERRUPT_VSYNC); + + drm_dev_exit(idx); } =20 static const struct drm_crtc_funcs hdlcd_crtc_funcs =3D { @@ -170,21 +191,33 @@ static void hdlcd_crtc_atomic_enable(struct drm_crtc = *crtc, struct drm_atomic_state *state) { struct hdlcd_drm_private *hdlcd =3D crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; =20 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); } =20 static void hdlcd_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct hdlcd_drm_private *hdlcd =3D crtc_to_hdlcd_priv(crtc); + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; =20 drm_crtc_vblank_off(crtc); hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); clk_disable_unprepare(hdlcd->clk); + + drm_dev_exit(idx); } =20 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(stru= ct drm_crtc *crtc, { struct hdlcd_drm_private *hdlcd =3D crtc_to_hdlcd_priv(crtc); long rate, clk_rate =3D mode->clock * 1000; + int idx; + + if (!drm_dev_enter(crtc->dev, &idx)) + return MODE_NOCLOCK; =20 rate =3D 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(struc= t drm_crtc *crtc, return MODE_NOCLOCK; } =20 + drm_dev_exit(idx); + return MODE_OK; } =20 @@ -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; =20 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); } =20 static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs =3D { --=20 2.37.2 From nobody Fri Apr 10 18:50:55 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDF56C28D13 for ; Fri, 19 Aug 2022 23:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243812AbiHSXLh (ORCPT ); Fri, 19 Aug 2022 19:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243682AbiHSXL1 (ORCPT ); Fri, 19 Aug 2022 19:11:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23ECAD5DEB for ; Fri, 19 Aug 2022 16:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660950680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0y/a4pTSF6VtadOpwMNTC/mvZDJbVIcTrD8TXNTMH9w=; b=e4sUl5rhbcDtgpuKtwGdwId8WiJHqNZEe3aWFrcnsBqI5QvP9XKWtSyUijHVnUfQwvA3ON NlmAKv1+ynauy/ZXxp86DYWTGQYtbEkvu9pOvGVGGVNeTEmS9wTLtKdEOqBa8JuuJhvbwr ohKkn4vW+A8RJgwcBcob4xWHZu5bucQ= 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-360-b6xnA5ofMZWPN1goblxMEA-1; Fri, 19 Aug 2022 19:11:19 -0400 X-MC-Unique: b6xnA5ofMZWPN1goblxMEA-1 Received: by mail-ej1-f72.google.com with SMTP id hv19-20020a17090760d300b00730d0a018a6so1982635ejc.21 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=4sLZhWBZ3dHhNZ3dCNaj907eD5UXWu04unHC8ZvkB/uZQMjyWPKY/e34LJX9YsyjMe o+FCL8lpb3tDPktMzYsap+28NW9apMmpxXkebf2s7WBYX+De1BTf2eMDR9FjJsfOsTXV n3oiLxSVLfiId5UxtXYHBbntJHEoN4ZgzyqKFpu0kyPidcftpjD03D41w6YIv/HrhwEN nKBoQwAeU4PndcExlyGDFJl1oMNgKuyJEq+1MrKKgZlhgss9V00q0BeYOV/UVKQgV9J4 saogB4ARARaezGWe19mCKnsT1bbsAheNQ1SSIoavok3gTYlehgZVJInWHp/1Fx9drxVt O0EQ== X-Gm-Message-State: ACgBeo13EA+YA9wz5DoH+MIjfm+dukRrzWpkdEscnJdGWbe8b6KdlhKN Jph52beYHYFvwgMxTFW7yipX7EgD3OvIzfGHzw2XRWyh+IDpvGePJIc5HdkbbZKv6LQPCqUNAgW dFdxumTCG8wKX1+HszKDw51Rd X-Received: by 2002:a05:6402:2714:b0:43d:ca4f:d2a2 with SMTP id y20-20020a056402271400b0043dca4fd2a2mr7764355edd.185.1660950678519; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" (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_dr= v.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, vo= id *arg) struct drm_info_node *node =3D (struct drm_info_node *)m->private; struct drm_device *drm =3D node->minor->dev; struct hdlcd_drm_private *hdlcd =3D drm_to_hdlcd_priv(drm); - unsigned long clkrate =3D clk_get_rate(hdlcd->clk); - unsigned long mode_clock =3D hdlcd->crtc.mode.crtc_clock * 1000; + unsigned long clkrate, mode_clock; + int idx; + + if (!drm_dev_enter(drm, &idx)) + return -ENODEV; + + clkrate =3D clk_get_rate(hdlcd->clk); + mode_clock =3D hdlcd->crtc.mode.crtc_clock * 1000; =20 seq_printf(m, "hw : %lu\n", clkrate); seq_printf(m, "mode: %lu\n", mode_clock); + + drm_dev_exit(idx); return 0; } =20 --=20 2.37.2