From nobody Sun Apr 5 22:47:04 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 C732BECAAD8 for ; Tue, 13 Sep 2022 22:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbiIMWPT (ORCPT ); Tue, 13 Sep 2022 18:15:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbiIMWPM (ORCPT ); Tue, 13 Sep 2022 18:15:12 -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 CFECD13F80 for ; Tue, 13 Sep 2022 15:15:06 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fLaZVg/Gn3THIn1ghLrf5MedEqRFiq/AUqXfvtIcrvk=; b=LYcsX+jcn6+LNHbKGpTe3gia265m0UcG3TSI5NCXqI7yF6cTuuzy0ep0v8FDR/NemRmRs7 RuEoH84mPW/QumRUpM8WooyU6Uv0UwrDoZXyYZUfthVGIQqFyZTK2ZacRIxn5KV/XXPy0N 7gpshf2TSldDDp1+7927mqxNejLHQkM= 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-219-2dISxnWVNquHq3ZnY7Efpw-1; Tue, 13 Sep 2022 18:15:04 -0400 X-MC-Unique: 2dISxnWVNquHq3ZnY7Efpw-1 Received: by mail-ed1-f69.google.com with SMTP id f18-20020a056402355200b0045115517911so9083971edd.14 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=YARwYKL/wsFo6MdQh4P2DWDwiypOSc2y3k3+5o2q4NqWj9ZydbUS7M1n51ZfakFznc LMOAtbpqVKyTZKLBIrp87/ZXRcTMUAmldpnNCelcjykOTyLaxEKbt19+mGoFPjwmFDrp rgNE34uoK//WUA2UlYNICk7RCTmPJkQcU8ddncfTFd8UT8qHBFzn0RVTTvaMuymdp7EG r3TzE+GN31XQcaiRJxjo2mnNRBWx/QSCxuKu5Gx7TUe/PdSOSaN9HcqGkb2qrJh5r1le VP08cQx7CG721uHepU/4JBBrHmttp/VTiKnEjs7jNTULSwazx78pWb+qkcfOoH9ytOqX cUiQ== X-Gm-Message-State: ACgBeo36pfxBtvXi06zWaP5lgyws/rnHuZLZhCM750wbUohh35spsZAH g5kpUxtmOZGBGFFutYOW89A+W/3yMZdhrMyNF5TFjFb/+3qrnmrAMGBdENT8yy507mUHgqBwe/S bgYaJ0S1/YqXKBUVWrmzmz797 X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr5606878ejc.208.1663107303648; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 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.3 From nobody Sun Apr 5 22:47:04 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 9F66EC54EE9 for ; Tue, 13 Sep 2022 22:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbiIMWPW (ORCPT ); Tue, 13 Sep 2022 18:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbiIMWPM (ORCPT ); Tue, 13 Sep 2022 18:15:12 -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 179241CB2B for ; Tue, 13 Sep 2022 15:15:10 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yZIl1OKGrL3KJyd7ruXlclzCfjtYvrZNcDLCxG8/BBY=; b=iOa1cFNFHhy6vCUQDqu6YRRFA1LRhFnoLRAPFWeuknbouCFO0bd0W+uw6SyZWM9euWiOpG fI0I3aOruB1Ok8CoxCvnLsRWNzBTT4Pot8pcL5VbGFt4nZ/+QQwJICjwz+VqK8by4Poe6A yvxVmvWHCWkFvQICQHxu/XF2UW+csM8= 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-662-YpAs0fDIOTyqGNhwdB4rLw-1; Tue, 13 Sep 2022 18:15:08 -0400 X-MC-Unique: YpAs0fDIOTyqGNhwdB4rLw-1 Received: by mail-ed1-f69.google.com with SMTP id m13-20020a056402510d00b004519332f0b1so5832913edd.7 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=LUn1KWp/+Ro9w+MoNfkssKdotPJnHdAfGLby0imdS81MQXiY5Hv1f+g+gMe4YCEu+k azEtcfvhxuM+oE9fm55Tt44UGaV9ND5CQw8SlJ1QFKpeP0/vgkz0JLA7tkXa1FFtYLCY CsRmdX4xQJ65wnSWtw4yX1Gibrif4k3kxFnvNAWmbsnTTWbgD4wFFpU0oSf1dolYs0Ys NYkaU+q7+u9vavGXH4g9nMMMngv3pdWx4ABptyQx1OLPB2PCFMxbywPMNnSiPYIEJsIZ N2WhhH0RPESpIghXu5PC7lLHXDbCM1P6rS5ZZpQ55XJEdXlMr9ErkGmuN8HGoceVHuiH yc3g== X-Gm-Message-State: ACgBeo3HvMypYOl5dmw/RVUyKThlfYb1zuTHq0uWKVfsPjImSKix/tl5 8YKZIhaubEGTpkx3TgZ/bLCBHft/MEMXwvX+XiXF6ZwQ8z/7eCz9y0yytihDukMjuCgDOl6TOk9 bywYqsm075AkbNEbLz26QmN8o X-Received: by 2002:a17:907:1df1:b0:779:4f57:6bb2 with SMTP id og49-20020a1709071df100b007794f576bb2mr17525238ejc.407.1663107307168; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 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.3 From nobody Sun Apr 5 22:47:04 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 BC93DC54EE9 for ; Tue, 13 Sep 2022 22:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229716AbiIMWPZ (ORCPT ); Tue, 13 Sep 2022 18:15:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbiIMWPP (ORCPT ); Tue, 13 Sep 2022 18:15:15 -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 53E0913D72 for ; Tue, 13 Sep 2022 15:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107313; 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=3NFp4VgvnrWlpf0cR1jJD5RUagyd6mZ8BYx1FSeEHWg=; b=EbliY4z3kAjWMgTyFM3VwJs/bo18chNsyUFiZthO48yEyH/BfxROmP4szvCTrwaeFIU/J2 BywdHDar9OPQX764RyVcYJSzvryQhf4iKb6iGFFP9DdQyvWj1vuXEBFwQD/YtzRGfan1uN GsmANFknuitNWy0NU867TI7ylFMKEyw= 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-436-tfTEgqS2NeiVhroYQOlM_Q-1; Tue, 13 Sep 2022 18:15:11 -0400 X-MC-Unique: tfTEgqS2NeiVhroYQOlM_Q-1 Received: by mail-ed1-f70.google.com with SMTP id v11-20020a056402348b00b004516e0b7eedso6594028edc.8 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=1UaxCruB1yxMHtuQcm2aL4+c6YPHs5/nyVSfDtxz83jdiWV5irUrMFCzYrH3b50vkj FWvSPgCP1Sk/pE8jhlqrUBiGvfYwpoYVNjt6xhxbjS6bVODSgbbB/NYCWuDxFLn3MY2R S4ffcE2NUX1EowgHA7bUDDEG9UAt1gvQQd73/u6YwPMiS1MPUCoc7zVrfkf0E6Psuut1 CxKsgVZuhhRZ/KPDRRMVbSsb3vqEqrxzE5pUWs61cipdIeUWHhSa8Sgho1P3LtVGUpIw F1k5LatT86iF3fbBuqqA8OpY21PClaPIYX4CjG09vuPhuqrReD2Sh4vqfprrQ+guaGU4 aLbg== X-Gm-Message-State: ACgBeo0m1QqvVGRQRF5ubz5eLufAPWh1D+qTASUfOpw196qPTQrAYIcA 5eRELYNfa+7u2VHIVVkdL7IUWE6CZ70KQ5XK39pJpYUassUo7ZHNlVTwVqb3e4qvLVOlZ0+W1OO maMFesid278Vn3fScwRwkLm+X X-Received: by 2002:a05:6402:5008:b0:440:941a:93c3 with SMTP id p8-20020a056402500800b00440941a93c3mr11421865eda.47.1663107310593; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 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 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 =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, @@ -298,24 +297,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.3 From nobody Sun Apr 5 22:47:04 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 5FC44C54EE9 for ; Tue, 13 Sep 2022 22:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229740AbiIMWPh (ORCPT ); Tue, 13 Sep 2022 18:15:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbiIMWPR (ORCPT ); Tue, 13 Sep 2022 18:15:17 -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 321E913D65 for ; Tue, 13 Sep 2022 15:15:17 -0700 (PDT) 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hsWBexLFDVqUOZMqbhy+SL8q312glCS9Mla/+vP6MEc=; b=QMmpv40E7FJO4P7QJ/C9BJQWLnS9/r3YCDlgmFBPmiBaJkAul4rGaXpSJ7qXW9fX8GYMQu iG5SXVEl2SxyMcyjQGEA3Ve8w+Pfp9ZJCEZB8WYDbZHBehE/xiOgGPfrnVMClVD5YdA0b5 iihcHh5tN+f/10JyKkFMg8ZAiiaUXn0= 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-85-Zi2kAvXiM2eNNOaj6-n4-w-1; Tue, 13 Sep 2022 18:15:15 -0400 X-MC-Unique: Zi2kAvXiM2eNNOaj6-n4-w-1 Received: by mail-ej1-f69.google.com with SMTP id hs4-20020a1709073e8400b0073d66965277so5144661ejc.6 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=w0Gz46jIwZOJKSAqEuiQJEmm/bsezvkRd7nMzGtaUmbAzmObcJO0lSE6BUv+gZPdCt onbJFuGuBDiTBuLjjm1u+87zw30OxP7ToB82OEhb9T7NuPtIBnVkNJMb40toZ402ZCgX l/jmbyyJrimxkjn2hoHU18i33zTvmO2MIOkkhyj/TVZSB7Pw09od1LsVUree+nfsbzim asMu5xuIkZ95GJQC0zgJ36f1SvdF5cyAPfeeMJLSeDygmOo+TXvInap9/ke0UwQjgD1h BAXLKMI+OFV/z1+R4Q2HJqL87UFVUQpjOqKpys4G/xT/z2OoaaVHrSY0Fx2tuVHIDMX5 V0ZA== X-Gm-Message-State: ACgBeo1oW7UQNOL/MqAxqfHcsUzVIeCdKMBmhAChp1HiUBiJNibJdVQY fl5lSFwJk25bsgo9HbltNI5MgWFfsOQ6LKunvXS5BuqehPqytRBJ/SHVGmcJHWEAcWurQZR5AB9 ULdcntw8doNKthFqwDG06Yr1n X-Received: by 2002:aa7:da97:0:b0:452:bea2:5200 with SMTP id q23-20020aa7da97000000b00452bea25200mr68250eds.341.1663107314141; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 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.3 From nobody Sun Apr 5 22:47:04 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 971C4C54EE9 for ; Tue, 13 Sep 2022 22:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229546AbiIMWPn (ORCPT ); Tue, 13 Sep 2022 18:15:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbiIMWPW (ORCPT ); Tue, 13 Sep 2022 18:15:22 -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 09A6A1E3E6 for ; Tue, 13 Sep 2022 15:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107319; 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=F/Lhqp1JWUkXQ2yb049nFnR3BgXC5vF+mPmJxxil2YI=; b=TNPUgafaF8CV8vhXb2URh1PnUs5l2zqjTsHtE4tnhQ9uRIKN+qISzbzhsNhsHnih/3jzOc xaUgEhm5S8QlyGfTfX3sOAbMkKDWPYjp3lgFmzEiZGCMgKvfekb3RNiHK5e4GbCNru39kC phtNjFcjEthV9wlSubsjMSQDi3kxtoU= 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-256-4fTtX2yWPearACxRCwIElw-1; Tue, 13 Sep 2022 18:15:18 -0400 X-MC-Unique: 4fTtX2yWPearACxRCwIElw-1 Received: by mail-ej1-f72.google.com with SMTP id hr12-20020a1709073f8c00b0077e8371f847so3019150ejc.20 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=HObwYgOQOaiVibWgiUztmHk62N60VYObBAo2sr9wygv9VPTOwggvIRyq+ajS03uDqm L/F6sfpnafSk86gkoUIMgspRcZq/EIDy2grSb9yZHTY4F2BOV/GDPyyd9w87TZBrsqmM XpSxmsyi2Kqij2dIgWU9i0HySEawdauyQhfxRpH9ajo+6tTcQOgJdCpPIyR84f+36nfs T6hsz8AERACpWsHzpimWWoxslo0TLdLTJhctiR+7HQ9uIq3lXsIbdyGX+ZBmZpfMHvhw c0COqcY1f2ymY1cK9qMRuzwQfgJXhW6c+5ZhvwJa6hIJ2mxgUyHHH9n2sV9C2W03YsEV M28Q== X-Gm-Message-State: ACgBeo3xLpsgIseKB5+bgM2CmJxoRh/xqqkkvjMe9aruaKuhd/Vb2vUr H4pVrNrZyF/AoaHBDDEVZEZWA2yAUWgU2A3M0H0WY8hgkJFcX5hYiPgnsphWX1f3xVUmBT6ITu5 L/WyXUh1muL7Vm5wIL8/LUPcg X-Received: by 2002:a05:6402:3550:b0:451:473a:5ca3 with SMTP id f16-20020a056402355000b00451473a5ca3mr15479848edd.48.1663107317637; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 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 | 52 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_c= rtc.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 =3D crtc_to_hdlcd_priv(crtc); + int idx; + + drm_crtc_cleanup(crtc); + + if (!drm_dev_enter(crtc->dev, &idx)) + return; =20 /* stop the controller on cleanup */ hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); - drm_crtc_cleanup(crtc); + + 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; + + if (!drm_dev_enter(crtc->dev, &idx)) + return; =20 + 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 { @@ -171,21 +193,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, @@ -193,6 +227,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 */ @@ -201,6 +239,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 @@ -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; =20 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); } =20 static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs =3D { --=20 2.37.3 From nobody Sun Apr 5 22:47:04 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 10FFFC54EE9 for ; Tue, 13 Sep 2022 22:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbiIMWQE (ORCPT ); Tue, 13 Sep 2022 18:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiIMWPm (ORCPT ); Tue, 13 Sep 2022 18:15:42 -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 18FCF74B9A for ; Tue, 13 Sep 2022 15:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663107331; 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=IDL/AgTFWdm+PP/N7/EovNn2CFq5LCV9poLaDqClvoQ=; b=Swq9zW3+kK8ekgJu/MuuNmv5Q4R5+9954dWssFTghwnBOeHzeguj6I7+8L6OmPFqaoRCR9 MznQ1xkbnx6rWouEyKhPJmZ3YomvlD1uNk+gsEenP2cGqX7SrQlFHyrTFcmNLMlUg3//zV OefhiML68Lkz+P+qeno5rJXcgKzer44= 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-241-LdyeGKxnNkyn9SuCEOOmkA-1; Tue, 13 Sep 2022 18:15:22 -0400 X-MC-Unique: LdyeGKxnNkyn9SuCEOOmkA-1 Received: by mail-ej1-f71.google.com with SMTP id sc31-20020a1709078a1f00b0077ef3eec7d7so2917788ejc.16 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=e+MhXtDacNG9l8/pTNoPruSw2rKbn6HgzbIKACm+pv4rsk/5sxgOMzNrwk+052ugb1 BXJ5yD3BJ6c5+kJEyd5j+qwMkD7dLXTPiTNZLHx4Jgedx3QQE8plTDQ4qV2pl6QJW6ZG JbhRLzrhs0BeeGSou6Ojh5INeOLLp7P1H43xkAQPRXPzjtYf8j8iDwdeDESOaObv0pty +bcu/rsP+JM1h3uYOhC4W9pYNPTq8iEb4jsjPfmxmUvgbIK5bHTzF6mEaEneVY9sQmg4 LLYG+nuXKwyAzS4lnv77gDyE69WvUY8MnfeOJ2Tqj6KcdGWWCEjrVWL9TpP/nBXw1jgM LkXQ== X-Gm-Message-State: ACgBeo0f2FysTvIDofGNk1Y35PzKlAwXxGpe+nHi/7QIHA1WIUq6WABb zST7S24TNCydguQ5sHwMzcWdbWLvQPp1sGqhHv0FOQgfkNZTJWUSu6UbRRgPlTPQcOowLc1Gfdr HuVtlgjiczw5N0fxIlS+7oZM7 X-Received: by 2002:a17:907:b0e:b0:77a:d97d:9afc with SMTP id h14-20020a1709070b0e00b0077ad97d9afcmr12925513ejl.199.1663107321098; 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich 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 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.3