From patchwork Thu Sep 15 00:32:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976728 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 CA5F0C6FA82 for ; Thu, 15 Sep 2022 00:33:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F2B189B48; Thu, 15 Sep 2022 00:32:59 +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 3583E10E201 for ; Thu, 15 Sep 2022 00:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201963; 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=d5wQaZFEzn9uIXApEc4pGB3KbziveTZ08VHPOZH9w9g=; b=FjzrWvHequNapLqSJz3eq92OZSNmTRAqTEXJsBfkBiRSjP82XOlEB+dRsyzd4LARyao4dM rWlUz3jp5lHFkaBh6K5fcWbd6jxVH6Jp1ZnvFkoI3SONQGS7pesF3iX/Z44hcolsbda63i NcsLqH7FVaLJcfhKjSid7naTrLmoljE= 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-53-WevPWljsOhWIOJoqGYxnGg-1; Wed, 14 Sep 2022 20:32:42 -0400 X-MC-Unique: WevPWljsOhWIOJoqGYxnGg-1 Received: by mail-ed1-f70.google.com with SMTP id s17-20020a056402521100b004511c8d59e3so11486955edd.11 for ; Wed, 14 Sep 2022 17:32:41 -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=d5wQaZFEzn9uIXApEc4pGB3KbziveTZ08VHPOZH9w9g=; b=GLVIroIlvCJ0PgLPxk4QMuRm9LQqqqQG05/nupngn9E9nwVtBmQtYV8CkP1iYHh+nZ a/FYC+YhwBIYQDrtrlqAUoZr1RC25ogDM7GdqqX1Kn8MkabYr37p0XtSaIgvv7qzY0ks ua21ea9w3tFDrZKYITHIy1h6P/Je6yvV+UeGbBKoKBaEuwuVsoUqZ2AZK0LdHA4XnYiK C63bBTP5FxnzR+09OSds2fg0SsID8QZTCp5erZSD7VyWr1VtM06w5ca68xvJ+krVqhAC QCvlM6K4EaqAGy41hyYZyV1kAvTa3JGnL55kkpEYOwVW1l0XHmUwNdh13qGQfI3NBeeZ hDyQ== X-Gm-Message-State: ACgBeo3WWHCPi70dlbwqmQANc4ARLdPxlXtA8a37ETvXR/h6FnGQXiNb VZ8FwIcqHdKFLWK9DYWnoR8mjpTMD7twUhDp5FTVdhUz/C9cGZNxDCoVtA+3RfmCHxMP/qDGjWQ 715YZl+6A3Wyu9ELWwFFEzUGOFT6g X-Received: by 2002:a05:6402:22b6:b0:452:2682:a97d with SMTP id cx22-20020a05640222b600b004522682a97dmr11882534edb.309.1663201961083; Wed, 14 Sep 2022 17:32:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/3UapABdzNolXQ2vgP3OvvIR9P2YBUWHPoDcwqjn2120CzBCoHv/jPhXemxEraXSszKCo4w== X-Received: by 2002:a05:6402:22b6:b0:452:2682:a97d with SMTP id cx22-20020a05640222b600b004522682a97dmr11882521edb.309.1663201960830; Wed, 14 Sep 2022 17:32:40 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id i5-20020a170906698500b007081282cbd8sm8185342ejr.76.2022.09.14.17.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:32:39 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 1/8] drm/fsl-dcu: use drmm_* to allocate driver structures Date: Thu, 15 Sep 2022 02:32:24 +0200 Message-Id: <20220915003231.363447-2-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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/fsl-dcu/fsl_dcu_drm_crtc.c | 7 ++--- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 30 +++++++++------------- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h | 2 +- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c | 19 +++++++------- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c | 8 +++--- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index 2af60d98f48f..a1b8ce70928a 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -171,15 +171,16 @@ int fsl_dcu_drm_crtc_create(struct fsl_dcu_drm_device *fsl_dev) { struct drm_plane *primary; struct drm_crtc *crtc = &fsl_dev->crtc; + struct drm_device *drm = &fsl_dev->base; int ret; - fsl_dcu_drm_init_planes(fsl_dev->drm); + fsl_dcu_drm_init_planes(drm); - primary = fsl_dcu_drm_primary_create_plane(fsl_dev->drm); + primary = fsl_dcu_drm_primary_create_plane(drm); if (!primary) return -ENOMEM; - ret = drm_crtc_init_with_planes(fsl_dev->drm, crtc, primary, NULL, + ret = drm_crtc_init_with_planes(drm, crtc, primary, NULL, &fsl_dcu_drm_crtc_funcs, NULL); if (ret) { primary->funcs->destroy(primary); diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c index b4acc3422ba4..a47b72995fcf 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c @@ -168,6 +168,7 @@ static const struct drm_driver fsl_dcu_drm_driver = { static int fsl_dcu_drm_pm_suspend(struct device *dev) { struct fsl_dcu_drm_device *fsl_dev = dev_get_drvdata(dev); + struct drm_device *drm = &fsl_dev->base; int ret; if (!fsl_dev) @@ -175,7 +176,7 @@ static int fsl_dcu_drm_pm_suspend(struct device *dev) disable_irq(fsl_dev->irq); - ret = drm_mode_config_helper_suspend(fsl_dev->drm); + ret = drm_mode_config_helper_suspend(drm); if (ret) { enable_irq(fsl_dev->irq); return ret; @@ -189,6 +190,7 @@ static int fsl_dcu_drm_pm_suspend(struct device *dev) static int fsl_dcu_drm_pm_resume(struct device *dev) { struct fsl_dcu_drm_device *fsl_dev = dev_get_drvdata(dev); + struct drm_device *drm = &fsl_dev->base; int ret; if (!fsl_dev) @@ -202,10 +204,10 @@ static int fsl_dcu_drm_pm_resume(struct device *dev) if (fsl_dev->tcon) fsl_tcon_bypass_enable(fsl_dev->tcon); - fsl_dcu_drm_init_planes(fsl_dev->drm); + fsl_dcu_drm_init_planes(drm); enable_irq(fsl_dev->irq); - drm_mode_config_helper_resume(fsl_dev->drm); + drm_mode_config_helper_resume(drm); return 0; } @@ -255,9 +257,10 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev) int ret; u8 div_ratio_shift = 0; - fsl_dev = devm_kzalloc(dev, sizeof(*fsl_dev), GFP_KERNEL); - if (!fsl_dev) - return -ENOMEM; + fsl_dev = devm_drm_dev_alloc(dev, &fsl_dcu_drm_driver, + typeof(*fsl_dev), base); + if (IS_ERR(fsl_dev)) + return PTR_ERR(fsl_dev); id = of_match_node(fsl_dcu_of_match, pdev->dev.of_node); if (!id) @@ -317,28 +320,19 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev) fsl_dev->tcon = fsl_tcon_init(dev); - drm = drm_dev_alloc(&fsl_dcu_drm_driver, dev); - if (IS_ERR(drm)) { - ret = PTR_ERR(drm); - goto unregister_pix_clk; - } - fsl_dev->dev = dev; - fsl_dev->drm = drm; fsl_dev->np = dev->of_node; drm->dev_private = fsl_dev; dev_set_drvdata(dev, fsl_dev); ret = drm_dev_register(drm, 0); if (ret < 0) - goto put; + goto unregister_pix_clk; drm_fbdev_generic_setup(drm, legacyfb_depth); return 0; -put: - drm_dev_put(drm); unregister_pix_clk: clk_unregister(fsl_dev->pix_clk); disable_clk: @@ -349,9 +343,9 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev) static int fsl_dcu_drm_remove(struct platform_device *pdev) { struct fsl_dcu_drm_device *fsl_dev = platform_get_drvdata(pdev); + struct drm_device *drm = &fsl_dev->base; - drm_dev_unregister(fsl_dev->drm); - drm_dev_put(fsl_dev->drm); + drm_dev_unregister(drm); clk_disable_unprepare(fsl_dev->clk); clk_unregister(fsl_dev->pix_clk); diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h index e2049a0e8a92..20ca13ff618a 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h @@ -177,6 +177,7 @@ struct fsl_dcu_soc_data { }; struct fsl_dcu_drm_device { + struct drm_device base; struct device *dev; struct device_node *np; struct regmap *regmap; @@ -186,7 +187,6 @@ struct fsl_dcu_drm_device { struct fsl_tcon *tcon; /*protects hardware register*/ spinlock_t irq_lock; - struct drm_device *drm; struct drm_crtc crtc; struct drm_encoder encoder; struct fsl_dcu_drm_connector connector; diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c index 5b47000738e4..c3d55c0aca9f 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c @@ -20,15 +20,16 @@ static const struct drm_mode_config_funcs fsl_dcu_drm_mode_config_funcs = { int fsl_dcu_drm_modeset_init(struct fsl_dcu_drm_device *fsl_dev) { + struct drm_device *drm = &fsl_dev->base; int ret; - drm_mode_config_init(fsl_dev->drm); + drm_mode_config_init(drm); - fsl_dev->drm->mode_config.min_width = 0; - fsl_dev->drm->mode_config.min_height = 0; - fsl_dev->drm->mode_config.max_width = 2031; - fsl_dev->drm->mode_config.max_height = 2047; - fsl_dev->drm->mode_config.funcs = &fsl_dcu_drm_mode_config_funcs; + drm->mode_config.min_width = 0; + drm->mode_config.min_height = 0; + drm->mode_config.max_width = 2031; + drm->mode_config.max_height = 2047; + drm->mode_config.funcs = &fsl_dcu_drm_mode_config_funcs; ret = fsl_dcu_drm_crtc_create(fsl_dev); if (ret) @@ -42,12 +43,12 @@ int fsl_dcu_drm_modeset_init(struct fsl_dcu_drm_device *fsl_dev) if (ret) goto err; - drm_mode_config_reset(fsl_dev->drm); - drm_kms_helper_poll_init(fsl_dev->drm); + drm_mode_config_reset(drm); + drm_kms_helper_poll_init(drm); return 0; err: - drm_mode_config_cleanup(fsl_dev->drm); + drm_mode_config_cleanup(drm); return ret; } diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c index 4d4a715b429d..b9b02f617cd2 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c @@ -22,6 +22,7 @@ int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev, struct drm_crtc *crtc) { struct drm_encoder *encoder = &fsl_dev->encoder; + struct drm_device *drm = &fsl_dev->base; int ret; encoder->possible_crtcs = 1; @@ -30,8 +31,7 @@ int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev, if (fsl_dev->tcon) fsl_tcon_bypass_enable(fsl_dev->tcon); - ret = drm_simple_encoder_init(fsl_dev->drm, encoder, - DRM_MODE_ENCODER_LVDS); + ret = drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_LVDS); if (ret < 0) return ret; @@ -79,12 +79,12 @@ static int fsl_dcu_attach_panel(struct fsl_dcu_drm_device *fsl_dev, { struct drm_encoder *encoder = &fsl_dev->encoder; struct drm_connector *connector = &fsl_dev->connector.base; + struct drm_device *drm = &fsl_dev->base; int ret; fsl_dev->connector.encoder = encoder; - ret = drm_connector_init(fsl_dev->drm, connector, - &fsl_dcu_drm_connector_funcs, + ret = drm_connector_init(drm, connector, &fsl_dcu_drm_connector_funcs, DRM_MODE_CONNECTOR_LVDS); if (ret < 0) return ret; From patchwork Thu Sep 15 00:32:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976727 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 5ABA6C6FA82 for ; Thu, 15 Sep 2022 00:33:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C72E510E1F8; Thu, 15 Sep 2022 00:32:58 +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 83BD110E207 for ; Thu, 15 Sep 2022 00:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201967; 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=H68P8iepWfLJpYbHEar6qJMBNCk2+2oF4KGUobttlNs=; b=aj0kUje5kLQ0wii/FYzCEtLisxXrYRKLK4/OPQM4R2qf/fvo3eHuBl8RxPRnh5HMSzXaJf GgoHwiLc2sk9RfC9DFuvO0Qj4jPurcVC/ERFAOVLgB7dEDNggOd1WkW9Bq22K3L6+16D6p o2j5rZww8pTR4V+cLSWa3Q6dBhIXYn0= 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-446-Es73KfFgOX--sM-zx8Yvxg-1; Wed, 14 Sep 2022 20:32:46 -0400 X-MC-Unique: Es73KfFgOX--sM-zx8Yvxg-1 Received: by mail-ed1-f72.google.com with SMTP id v11-20020a056402348b00b004516e0b7eedso9091834edc.8 for ; Wed, 14 Sep 2022 17:32:46 -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=H68P8iepWfLJpYbHEar6qJMBNCk2+2oF4KGUobttlNs=; b=BLa+CF+yhfHwm+KOjE07anYV5itflQqldFOakWOQ8E9cCP5HYJUGXoJBo5/80MhqZ5 fJ46bt5WmBmtu0CnuAj39UJre5ae2XLo3UZnDeHUDcVfYVX1B8akkTZTiOF2qI2cqAPm uyQ7FlVw41gPO2w4FGaklXS5Lk1ZWzX1Qh6OyPh4RFkGg0VlMeZ5tAoUIBkovZHOTKKt RG/h0WQZ8QJZYDCNaUNcdsaPwpFmWng/mhZXm4A3mWBbwPRWSNmAirxevrpCgAY1IkwQ IBjdUY1JImeP8Ek1RDrdTE8Kkacz3BEtRgYE5ZeM8ZkFT31ZgzLqyKjgFpjTxh9agr8x frPA== X-Gm-Message-State: ACgBeo399rWZ0coCW9ZWZP5duTCx6js/nLe+WwspFotDiUmNSS8fDj1M x9BTHuaGde7/5k+J0ulepHY/2/8U2jonEx/b6MF2UO6vOcUi31K1oc7Dg987sLR53jmsv5gHhca 1Bya+dGvi4H/vEkTuaHDVNwWL7Kzc X-Received: by 2002:a05:6402:4449:b0:445:cdb6:2de9 with SMTP id o9-20020a056402444900b00445cdb62de9mr32642913edb.59.1663201964989; Wed, 14 Sep 2022 17:32:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XNJXfGvj3h4Jld1qFi2NofTMl3y+rFRcL6dz+AggRntBTERzg0GqzFfVhJIIbLhDdTFEEtw== X-Received: by 2002:a05:6402:4449:b0:445:cdb6:2de9 with SMTP id o9-20020a056402444900b00445cdb62de9mr32642901edb.59.1663201964831; Wed, 14 Sep 2022 17:32:44 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id s15-20020aa7c54f000000b004466f5375a5sm10786760edr.53.2022.09.14.17.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:32:44 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 2/8] drm/fsl-dcu: replace drm->dev_private with drm_to_fsl_dcu_drm_dev() Date: Thu, 15 Sep 2022 02:32:25 +0200 Message-Id: <20220915003231.363447-3-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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 malidp_drm, hence we can use container_of() to get the struct drm_device instance instead. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 12 ++++++------ drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 13 ++++--------- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h | 2 ++ drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 8 ++++---- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index a1b8ce70928a..e05311e2b0e0 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -24,7 +24,7 @@ static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct drm_device *dev = crtc->dev; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); struct drm_pending_vblank_event *event = crtc->state->event; regmap_write(fsl_dev->regmap, @@ -48,7 +48,7 @@ static void fsl_dcu_drm_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc); struct drm_device *dev = crtc->dev; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); /* always disable planes on the CRTC */ drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, true); @@ -67,7 +67,7 @@ static void fsl_dcu_drm_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct drm_device *dev = crtc->dev; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); clk_prepare_enable(fsl_dev->pix_clk); regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE, @@ -82,7 +82,7 @@ static void fsl_dcu_drm_crtc_atomic_enable(struct drm_crtc *crtc, static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); struct drm_connector *con = &fsl_dev->connector.base; struct drm_display_mode *mode = &crtc->state->mode; unsigned int pol = 0; @@ -135,7 +135,7 @@ static const struct drm_crtc_helper_funcs fsl_dcu_drm_crtc_helper_funcs = { static int fsl_dcu_drm_crtc_enable_vblank(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); unsigned int value; regmap_read(fsl_dev->regmap, DCU_INT_MASK, &value); @@ -148,7 +148,7 @@ static int fsl_dcu_drm_crtc_enable_vblank(struct drm_crtc *crtc) static void fsl_dcu_drm_crtc_disable_vblank(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); unsigned int value; regmap_read(fsl_dev->regmap, DCU_INT_MASK, &value); diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c index a47b72995fcf..4139f674c5de 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c @@ -52,7 +52,7 @@ static const struct regmap_config fsl_dcu_regmap_config = { static void fsl_dcu_irq_reset(struct drm_device *dev) { - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); regmap_write(fsl_dev->regmap, DCU_INT_STATUS, ~0); regmap_write(fsl_dev->regmap, DCU_INT_MASK, ~0); @@ -61,7 +61,7 @@ static void fsl_dcu_irq_reset(struct drm_device *dev) static irqreturn_t fsl_dcu_drm_irq(int irq, void *arg) { struct drm_device *dev = arg; - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); unsigned int int_status; int ret; @@ -91,7 +91,7 @@ static int fsl_dcu_irq_install(struct drm_device *dev, unsigned int irq) static void fsl_dcu_irq_uninstall(struct drm_device *dev) { - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); fsl_dcu_irq_reset(dev); free_irq(fsl_dev->irq, dev); @@ -99,7 +99,7 @@ static void fsl_dcu_irq_uninstall(struct drm_device *dev) static int fsl_dcu_load(struct drm_device *dev, unsigned long flags) { - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); int ret; ret = fsl_dcu_drm_modeset_init(fsl_dev); @@ -133,8 +133,6 @@ static int fsl_dcu_load(struct drm_device *dev, unsigned long flags) drm_mode_config_cleanup(dev); done_vblank: - dev->dev_private = NULL; - return ret; } @@ -145,8 +143,6 @@ static void fsl_dcu_unload(struct drm_device *dev) drm_mode_config_cleanup(dev); fsl_dcu_irq_uninstall(dev); - - dev->dev_private = NULL; } DEFINE_DRM_GEM_DMA_FOPS(fsl_dcu_drm_fops); @@ -322,7 +318,6 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev) fsl_dev->dev = dev; fsl_dev->np = dev->of_node; - drm->dev_private = fsl_dev; dev_set_drvdata(dev, fsl_dev); ret = drm_dev_register(drm, 0); diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h index 20ca13ff618a..5b61d443da96 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.h @@ -193,6 +193,8 @@ struct fsl_dcu_drm_device { const struct fsl_dcu_soc_data *soc; }; +#define drm_to_fsl_dcu_drm_dev(x) container_of(x, struct fsl_dcu_drm_device, base) + int fsl_dcu_drm_modeset_init(struct fsl_dcu_drm_device *fsl_dev); #endif /* __FSL_DCU_DRM_DRV_H__ */ diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c index 794a87d16f88..91865956da02 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c @@ -22,7 +22,7 @@ static int fsl_dcu_drm_plane_index(struct drm_plane *plane) { - struct fsl_dcu_drm_device *fsl_dev = plane->dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(plane->dev); unsigned int total_layer = fsl_dev->soc->total_layer; unsigned int index; @@ -63,7 +63,7 @@ static int fsl_dcu_drm_plane_atomic_check(struct drm_plane *plane, static void fsl_dcu_drm_plane_atomic_disable(struct drm_plane *plane, struct drm_atomic_state *state) { - struct fsl_dcu_drm_device *fsl_dev = plane->dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(plane->dev); unsigned int value; int index; @@ -80,7 +80,7 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, struct drm_atomic_state *state) { - struct fsl_dcu_drm_device *fsl_dev = plane->dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(plane->dev); struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane); struct drm_framebuffer *fb = plane->state->fb; @@ -194,7 +194,7 @@ static const u32 fsl_dcu_drm_plane_formats[] = { void fsl_dcu_drm_init_planes(struct drm_device *dev) { - struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; + struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); int i, j; for (i = 0; i < fsl_dev->soc->total_layer; i++) { From patchwork Thu Sep 15 00:32:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976731 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 4654AC6FA82 for ; Thu, 15 Sep 2022 00:33:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 785BC10E1ED; Thu, 15 Sep 2022 00:33:31 +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 6DFB310E204 for ; Thu, 15 Sep 2022 00:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201971; 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=Xaw3iUtMLKwH2xCvo5P17z6DGidg5D+TvENUAVXK2ek=; b=XEbb+I7w96LMbTyQXBzgZcTblT0fiPuOnkFBlc7gu9Z8uxjsyogd/3WbX91kM+AR/oBQKX tfoT+qkgCMik5Pp8dyj5gwbKu2XwoPr1vZxkkEIe78nSr05iBNC09nuNI8OXaHaSo9hH4F JTPpRhYx7JdnuQHL429T8cxcDz3qZSY= 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-507-ypy6MadaNPqCiOO1mqG2BQ-1; Wed, 14 Sep 2022 20:32:50 -0400 X-MC-Unique: ypy6MadaNPqCiOO1mqG2BQ-1 Received: by mail-ed1-f71.google.com with SMTP id x5-20020a05640226c500b00451ec193793so7145742edd.16 for ; Wed, 14 Sep 2022 17:32:50 -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=Xaw3iUtMLKwH2xCvo5P17z6DGidg5D+TvENUAVXK2ek=; b=2uh90J/j7ynpuH5T2io5focUTn5torM1MFocIfVaJj7WbbAjHqsU/nWusmh+6VNtim N0HV61fBxI5LilR9ssQeZEKYuH0+kh5AC5ODgh06j/N6w5Z1U4s39JaPXDTiwlFTQd/G uV8dOm2/4n4klPeMdq760xYHZcXVcao8Z8sWsGg+fmK9NUaBtWzFNqiazFTVuxXZtBH4 qFbChK0IowtGsDOlgVtMqrZgT2DO2SvuJPm5RsWpMTwFBZY/U65y1aXAIsiUOoQV2rvy Od4jcuOjAS3vzguObdUsTDj3w8vlc3g3e8NSnGqQ5048NqM3cx4JHUnnbLwRaFOY8KiL fWzw== X-Gm-Message-State: ACgBeo2ZyUAIxEHK91h5+PRcl3uwW9ZCjX3laN/A012zZY2DOnT5vGN7 RF/PUJD3D75rNtKw2xrMe7wuVzx/cBzVFRgf35M1u+PYXMu9P3PlB16+psdexXVJAJmfQq1ii+T GJSBQb7DzGLXE5jm4ibFEwZAcNdoc X-Received: by 2002:a17:907:6293:b0:769:9dfc:10eb with SMTP id nd19-20020a170907629300b007699dfc10ebmr28017391ejc.191.1663201969521; Wed, 14 Sep 2022 17:32:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR76AUHZP7TSM1OI8rVca0sDWA90ENPNmx7n18UfSpYDwhdtincdX9d/3H678m4vxuSNRmwafw== X-Received: by 2002:a17:907:6293:b0:769:9dfc:10eb with SMTP id nd19-20020a170907629300b007699dfc10ebmr28017377ejc.191.1663201969380; Wed, 14 Sep 2022 17:32:49 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id s1-20020a056402014100b0044e8d0682b2sm10672079edu.71.2022.09.14.17.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:32:48 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 3/8] drm/fsl-dcu: crtc: use drmm_crtc_init_with_planes() Date: Thu, 15 Sep 2022 02:32:26 +0200 Message-Id: <20220915003231.363447-4-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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 destroy hook in struct drm_plane_funcs. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index e05311e2b0e0..0b70624260fc 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -159,7 +159,6 @@ static void fsl_dcu_drm_crtc_disable_vblank(struct drm_crtc *crtc) static const struct drm_crtc_funcs fsl_dcu_drm_crtc_funcs = { .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, - .destroy = drm_crtc_cleanup, .page_flip = drm_atomic_helper_page_flip, .reset = drm_atomic_helper_crtc_reset, .set_config = drm_atomic_helper_set_config, @@ -180,8 +179,8 @@ int fsl_dcu_drm_crtc_create(struct fsl_dcu_drm_device *fsl_dev) if (!primary) return -ENOMEM; - ret = drm_crtc_init_with_planes(drm, crtc, primary, NULL, - &fsl_dcu_drm_crtc_funcs, NULL); + ret = drmm_crtc_init_with_planes(drm, crtc, primary, NULL, + &fsl_dcu_drm_crtc_funcs, NULL); if (ret) { primary->funcs->destroy(primary); return ret; From patchwork Thu Sep 15 00:32:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976732 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 19D62ECAAD3 for ; Thu, 15 Sep 2022 00:33:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8F8510E207; Thu, 15 Sep 2022 00:33:32 +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 4581A10E204 for ; Thu, 15 Sep 2022 00:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201976; 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=OuGypoVnJNhzQ829OSUgv+IQ/uot1AKSMTgWYQGrHy8=; b=HmB4kmLvyxwKAarsFeYnePQw6jbAonFBKCFQ4l1Lg8tGfJWtgbIvOq/usFJUeKSRXzBXgD joHhlzW+jIbh5q02J5Ug5/OBD8pAOMuoEktb4AKurppqKBet1+IHDtjR32fY6n8614TKfL bJvgCwk9tVH9UexkVO6KlAfoZPJEJec= 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-380-YYCAyfpSNe-Qx-bNBqDxCQ-1; Wed, 14 Sep 2022 20:32:55 -0400 X-MC-Unique: YYCAyfpSNe-Qx-bNBqDxCQ-1 Received: by mail-ej1-f72.google.com with SMTP id hs4-20020a1709073e8400b0073d66965277so6689203ejc.6 for ; Wed, 14 Sep 2022 17:32:55 -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=OuGypoVnJNhzQ829OSUgv+IQ/uot1AKSMTgWYQGrHy8=; b=XcCgI/Q5qIHjBwFwXUbHxymvVSwWZFPBB7dxgZw+8la6/DY+BFN2PEQWKuCwfA3gt+ pcvMfumC2Hgn7PtsRLgPcDsxd2ihajPEXXnwRQ1q0HR7gjGrDD5zsjOLRWeUXOvTuFWD mBtHrumS8v/0R5JCT0gpS0kcIf45cHe5iFQdpN0CrCeJwefhDofC/6ZJWoymAl/MFsCz 4a60EUzCmw/yMBMgm3qaFJHGWwzBJhtLF4Ib8Y+kP6zPvAV3M0cChxr8viFuwxhlS7Kk 6J4Ka3H2KuQ/jUybufP69EvxP6S+8eYAMi/c6T+Jh5ZjeQBGlRHYXUtntkqvW/ejEe0H rf8Q== X-Gm-Message-State: ACgBeo35s3rZmi/axXno49iuua92COnLOrr/H0xZIyNXbv2lvEdAJGRF i7XHgOk6/mId2i0DLJo5mzUk3W5s9RnsnZAPtQAXhJQbFdID7cgsIKbvf+zks6IyFO7dxRUlneJ /jP0JywRfgG17EUBOIq1N7aaKXWEI X-Received: by 2002:a17:907:75d4:b0:77a:fcb7:a2cc with SMTP id jl20-20020a17090775d400b0077afcb7a2ccmr17036612ejc.480.1663201974087; Wed, 14 Sep 2022 17:32:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR4MNS6XjdMbm8wBWysxd/Ofibg9IanT71clyMWCRa2Ji1qtA7+ijOuAd2lmEatpGLIF+B5n7Q== X-Received: by 2002:a17:907:75d4:b0:77a:fcb7:a2cc with SMTP id jl20-20020a17090775d400b0077afcb7a2ccmr17036608ejc.480.1663201973936; Wed, 14 Sep 2022 17:32:53 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id o22-20020a056402039600b00450d23d40besm10663787edv.82.2022.09.14.17.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:32:52 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 4/8] drm/fsl-dcu: plane: use drm managed resources Date: Thu, 15 Sep 2022 02:32:27 +0200 Message-Id: <20220915003231.363447-5-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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/fsl-dcu/fsl_dcu_drm_crtc.c | 4 ++-- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 25 ++++++++------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index 0b70624260fc..1dad90f701c8 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -176,8 +176,8 @@ int fsl_dcu_drm_crtc_create(struct fsl_dcu_drm_device *fsl_dev) fsl_dcu_drm_init_planes(drm); primary = fsl_dcu_drm_primary_create_plane(drm); - if (!primary) - return -ENOMEM; + if (IS_ERR(primary)) + return PTR_ERR(primary); ret = drmm_crtc_init_with_planes(drm, crtc, primary, NULL, &fsl_dcu_drm_crtc_funcs, NULL); diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c index 91865956da02..23ff285da477 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c @@ -174,7 +174,6 @@ static const struct drm_plane_helper_funcs fsl_dcu_drm_plane_helper_funcs = { static const struct drm_plane_funcs fsl_dcu_drm_plane_funcs = { .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, - .destroy = drm_plane_helper_destroy, .disable_plane = drm_atomic_helper_disable_plane, .reset = drm_atomic_helper_plane_reset, .update_plane = drm_atomic_helper_update_plane, @@ -206,24 +205,18 @@ void fsl_dcu_drm_init_planes(struct drm_device *dev) struct drm_plane *fsl_dcu_drm_primary_create_plane(struct drm_device *dev) { struct drm_plane *primary; - int ret; - - primary = kzalloc(sizeof(*primary), GFP_KERNEL); - if (!primary) { - DRM_DEBUG_KMS("Failed to allocate primary plane\n"); - return NULL; - } /* possible_crtc's will be filled in later by crtc_init */ - ret = drm_universal_plane_init(dev, primary, 0, - &fsl_dcu_drm_plane_funcs, - fsl_dcu_drm_plane_formats, - ARRAY_SIZE(fsl_dcu_drm_plane_formats), - NULL, DRM_PLANE_TYPE_PRIMARY, NULL); - if (ret) { - kfree(primary); - primary = NULL; + primary = drmm_universal_plane_alloc(dev, struct drm_plane, dev, 0, + &fsl_dcu_drm_plane_funcs, + fsl_dcu_drm_plane_formats, + ARRAY_SIZE(fsl_dcu_drm_plane_formats), + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); + if (IS_ERR(primary)) { + DRM_DEBUG_KMS("Failed to create primary plane\n"); + return primary; } + drm_plane_helper_add(primary, &fsl_dcu_drm_plane_helper_funcs); return primary; From patchwork Thu Sep 15 00:32:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976729 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 5B4EFC6FA82 for ; Thu, 15 Sep 2022 00:33:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0A4710E1CA; Thu, 15 Sep 2022 00:33:18 +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 365EE10E1CA for ; Thu, 15 Sep 2022 00:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201983; 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=AJ+r++kfC5cLOYGbcZ2ityl6Btvuyg0jJylQkWmqY/s=; b=Xyoo3f83xrzjAH6ui2S1TFeaLuOxxE5B9zHbABjpOcVtep54h8/Ym3jOrFl+RZPXEGk3qc JJhvvxtOWQvRUHyiXqZ1IdT1fOq7xRTLxlPKFlPaNbuyPxdseuv7l19/JU5XrjwtAtRv1U hME+vrfZtHXMsDBN+2Ig3kBKFkMIjPc= 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-639-298Yn5PoOsaAo0qgkZJPTg-1; Wed, 14 Sep 2022 20:32:59 -0400 X-MC-Unique: 298Yn5PoOsaAo0qgkZJPTg-1 Received: by mail-ed1-f70.google.com with SMTP id e15-20020a056402190f00b0044f41e776a0so11775548edz.0 for ; Wed, 14 Sep 2022 17:32:59 -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=AJ+r++kfC5cLOYGbcZ2ityl6Btvuyg0jJylQkWmqY/s=; b=yDIerrNdvAoCC6ojJ4/FeOw0QP9pM3MPytbAYt/8BHlY0TZiB1/1FXNKEhCIj5Kf3/ FvSuCqOnYL8TMFS9GWEyghDTLPNZMRv+CBvrRbtWd78pNtm5pCClxNZhF2MwlJl1Ajo2 WtF/zwoGulDlRkIxXPRTVQk6XmPYbyEn2+M9JQJA1lSdeHST3EcG9sUOJDGQsR970L8w A8VEZtYxj5g7HpNdlWz/pNNxJbiAtgq6YNnglQj8Lm+7ZjraaGIi5NuWHqlPglySVvGq JNLKsMCs8CyOqp4tFllzffl2BqTAKKloAxiFKiu4xqiHUdSh7ySRWEX0ijbnHWBKcTtV 74KQ== X-Gm-Message-State: ACgBeo1QbB4K7N7LlkeDJITUJQTLIk/knqK3EjXddVBwWIlXddeDw4NE 1D5+2PMkzgQ3rfWz5RM9Q1CslqqLLoioPkhVK7SupZWyg/RGLT/sjig79nEpOzDQWCSSBvNYYKF DSNHyOLq9GeVnHbUuKHLUlWoGhkeo X-Received: by 2002:a17:907:a05:b0:77b:b538:6476 with SMTP id bb5-20020a1709070a0500b0077bb5386476mr15229463ejc.324.1663201978453; Wed, 14 Sep 2022 17:32:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR6aUx7J56s8B+MvIs3ZSkyOZ3rDzmk5K47Dc+uS1kdk6njw7e3KJEUrvUuZKRX+25BjZL8S0w== X-Received: by 2002:a17:907:a05:b0:77b:b538:6476 with SMTP id bb5-20020a1709070a0500b0077bb5386476mr15229452ejc.324.1663201978310; Wed, 14 Sep 2022 17:32:58 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id c18-20020a17090618b200b00773f3ccd989sm8240828ejf.68.2022.09.14.17.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:32:57 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 5/8] drm/fsl-dcu: use drm_dev_unplug() Date: Thu, 15 Sep 2022 02:32:28 +0200 Message-Id: <20220915003231.363447-6-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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/fsl-dcu/fsl_dcu_drm_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c index 4139f674c5de..3ac57516c3fe 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c @@ -340,7 +340,7 @@ static int fsl_dcu_drm_remove(struct platform_device *pdev) struct fsl_dcu_drm_device *fsl_dev = platform_get_drvdata(pdev); struct drm_device *drm = &fsl_dev->base; - drm_dev_unregister(drm); + drm_dev_unplug(drm); clk_disable_unprepare(fsl_dev->clk); clk_unregister(fsl_dev->pix_clk); From patchwork Thu Sep 15 00:32:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976730 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 B4077C6FA82 for ; Thu, 15 Sep 2022 00:33:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D641010E1EC; Thu, 15 Sep 2022 00:33:30 +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 3012210E1CA for ; Thu, 15 Sep 2022 00:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201984; 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=FtNtNsp7OqPqPE1l1U/CkF2qeKiAYQ9N67dyPKGWxE4=; b=NFRA1HixXuyiH1k1mEJN1760nRAq1XWrWpwlIsLHBiJGPf+OEyCd8HY8dk+0CQtXdt3FWh JXmpI1N8JV+XyXDDu9exEmeog/xIAEVICVW2NILG8m+KgzG6kxQWdSDM+2n4ut2k94MhoD CAxVi5XOWFWWUlJl4XLPsRlnbnMy+pQ= 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-448-INoZHRXANmWK0unhB7TI8g-1; Wed, 14 Sep 2022 20:33:03 -0400 X-MC-Unique: INoZHRXANmWK0unhB7TI8g-1 Received: by mail-ed1-f72.google.com with SMTP id z13-20020a05640240cd00b0045276a79364so4340723edb.2 for ; Wed, 14 Sep 2022 17:33:03 -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=FtNtNsp7OqPqPE1l1U/CkF2qeKiAYQ9N67dyPKGWxE4=; b=oQM4PJINQrGhbELkikmywrfqWZDzEbR3+3F+1JHE3u4VAYookbCgHAqCV8Ad3v756z KpvWU6ZC/oyRtsFaHH7hoN3C7Z8SAYcyyb4WBw/8cjkDfKa6aLEfNXrwsa1j/JZYN03Q qJ6hVVZ1dETaPrts59xFVFnYeKaa47zWMG+OJZZ+EUiya6DVdhmPTvxmiMlpM7Xukx7s BIfMvJDCPY3t9T7y+Tx9P/hua0kTrtCBEaDtc6kb5kEk04iB4jy+kO2MW5pUt6ZjOcQ1 Lkp67rFAWGWP/Ix3YygiuGZh9rC6+7EoxEwmqjLY4ReuA2hA/S3QAphMO48o2mopkqhx LTng== X-Gm-Message-State: ACgBeo3WyRe76mSkn4XcFAKo2K9Q/hAtGVaLmGv+PmBiP97Eo6MqLHVb 5bdkRSXOHQf0mvg6A4X3Rp6AwjT9U6ptONKz01MzFZsvyFpPCX7/QI7G/rtUo3Zq2ixyFIE0+xl 8bzC+nWZkjA344AVSLgmW2pYgIyAx X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr9587300ejc.208.1663201982189; Wed, 14 Sep 2022 17:33:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ZRBZU53BRdNeyOhVVcill9G3iLRkCUJ/jYRhr4Dk+1M2YpVqKN5hH2aUWRV4Wra1YNWfF2A== X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr9587289ejc.208.1663201981992; Wed, 14 Sep 2022 17:33:01 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id kx25-20020a170907775900b0073d70df6e56sm8240280ejc.138.2022.09.14.17.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:33:01 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 6/8] drm/fsl-dcu: plane: protect device resources after removal Date: Thu, 15 Sep 2022 02:32:29 +0200 Message-Id: <20220915003231.363447-7-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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/fsl-dcu/fsl_dcu_drm_plane.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c index 23ff285da477..1be3062a95df 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,10 @@ static void fsl_dcu_drm_plane_atomic_disable(struct drm_plane *plane, { struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(plane->dev); unsigned int value; - int index; + int index, idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; index = fsl_dcu_drm_plane_index(plane); if (index < 0) @@ -74,6 +78,8 @@ static void fsl_dcu_drm_plane_atomic_disable(struct drm_plane *plane, regmap_read(fsl_dev->regmap, DCU_CTRLDESCLN(index, 4), &value); value &= ~DCU_LAYER_EN; regmap_write(fsl_dev->regmap, DCU_CTRLDESCLN(index, 4), value); + + drm_dev_exit(idx); } static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, @@ -86,7 +92,10 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, struct drm_framebuffer *fb = plane->state->fb; struct drm_gem_dma_object *gem; unsigned int alpha = DCU_LAYER_AB_NONE, bpp; - int index; + int index, idx; + + if (!drm_dev_enter(plane->dev, &idx)) + return; if (!fb) return; @@ -162,6 +171,7 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, DCU_LAYER_PRE_SKIP(0)); } + drm_dev_exit(idx); return; } From patchwork Thu Sep 15 00:32:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976734 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 36ADFECAAD3 for ; Thu, 15 Sep 2022 00:34:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C773510E1F6; Thu, 15 Sep 2022 00:34:09 +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 EDF2310E1DA for ; Thu, 15 Sep 2022 00:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201999; 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=IqWM55e5x02znRK55veSvbQ977VUM5OMWrptzYqj4WI=; b=NtktI002Nl+r2dBUggvD9uJmVJDh6s8KWNlKrsQU5lSZSQ9RMs7mHOxn/RO6K/sB7iL/Ng 5hEiKZMb+9rpMMIREu/CWcxUZCcC1vNpknXPs8RrqN9itPt1eah6t35bVzGFtCtL+aV9ZO 1tCwZtS3jnYVpL6leXmRZMsQmEvzEr0= 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-453-9z6cB3AqOFqY1LCyLAtR9g-1; Wed, 14 Sep 2022 20:33:07 -0400 X-MC-Unique: 9z6cB3AqOFqY1LCyLAtR9g-1 Received: by mail-ed1-f70.google.com with SMTP id v11-20020a056402348b00b004516e0b7eedso9092190edc.8 for ; Wed, 14 Sep 2022 17:33:07 -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=IqWM55e5x02znRK55veSvbQ977VUM5OMWrptzYqj4WI=; b=cF+axPueS8szVqCAwJO+tUVX04ZeOYJa8CfXJzZ3OZL+dssi1u74vM4pGOmdUSMY9S zN3hXHuueJ0oXhOauO8OwyYQaf8PQruPuo0gfmC6aIBItUg5q60066XUZQLeSYclcyMv +My9bbCnA0P0R6p7p1zxoweW+fq8Ym6qBGYJpEbSkHjA072XnkO0S7PySuUlVuU4VlgE Aj6u+TSk8SUOb0cla5s9vhLOqZO40ykOJNcQ2sKv/aIaiNmMYUrHi1Io9ApvB3w3tnj+ lYhXd5RMmwmVtgfsnxME88hTnjj08msS6ViAPeST7oPDmZtQPwFkxwFnyfnwa6pwLxtS n/Cg== X-Gm-Message-State: ACgBeo32CotGa66ZVl0NKyZDR4DiTuZqmot6Z2uE/hOqm++mDpX3EEdB qmv4g7z3LeHPF+gtrK0Gweq710JRIYGKASUIhmeRHae0t575TIfa0+lo+a1U2CzEAIlME0Wlr/F cSt8DmpdxwlQKRbfXFeelAuTjPYyN X-Received: by 2002:a17:907:94d4:b0:77f:d0c9:573f with SMTP id dn20-20020a17090794d400b0077fd0c9573fmr8146052ejc.98.1663201986322; Wed, 14 Sep 2022 17:33:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR6iVRAQ1Z8stFf5ouzhJoapY1r+dUfoumzBdmir+QwjM/bFap5BDDwaSqryltzmVKD37aquAA== X-Received: by 2002:a17:907:94d4:b0:77f:d0c9:573f with SMTP id dn20-20020a17090794d400b0077fd0c9573fmr8146041ejc.98.1663201986181; Wed, 14 Sep 2022 17:33:06 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id p20-20020a056402155400b004479cec6496sm10715506edx.75.2022.09.14.17.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:33:05 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 7/8] drm/fsl-dcu: crtc: protect device resources after removal Date: Thu, 15 Sep 2022 02:32:30 +0200 Message-Id: <20220915003231.363447-8-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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/fsl-dcu/fsl_dcu_drm_crtc.c | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index 1dad90f701c8..c77df9b7893f 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,10 @@ static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_device *dev = crtc->dev; struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); struct drm_pending_vblank_event *event = crtc->state->event; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE, DCU_UPDATE_MODE_READREG); @@ -40,6 +45,8 @@ static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc, drm_crtc_send_vblank_event(crtc, event); spin_unlock_irq(&crtc->dev->event_lock); } + + drm_dev_exit(idx); } static void fsl_dcu_drm_crtc_atomic_disable(struct drm_crtc *crtc, @@ -49,6 +56,10 @@ static void fsl_dcu_drm_crtc_atomic_disable(struct drm_crtc *crtc, crtc); struct drm_device *dev = crtc->dev; struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; /* always disable planes on the CRTC */ drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, true); @@ -61,6 +72,8 @@ static void fsl_dcu_drm_crtc_atomic_disable(struct drm_crtc *crtc, regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE, DCU_UPDATE_MODE_READREG); clk_disable_unprepare(fsl_dev->pix_clk); + + drm_dev_exit(idx); } static void fsl_dcu_drm_crtc_atomic_enable(struct drm_crtc *crtc, @@ -68,6 +81,10 @@ static void fsl_dcu_drm_crtc_atomic_enable(struct drm_crtc *crtc, { struct drm_device *dev = crtc->dev; struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; clk_prepare_enable(fsl_dev->pix_clk); regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE, @@ -77,6 +94,8 @@ static void fsl_dcu_drm_crtc_atomic_enable(struct drm_crtc *crtc, DCU_UPDATE_MODE_READREG); drm_crtc_vblank_on(crtc); + + drm_dev_exit(idx); } static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) @@ -87,6 +106,10 @@ static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) struct drm_display_mode *mode = &crtc->state->mode; unsigned int pol = 0; struct videomode vm; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; clk_set_rate(fsl_dev->pix_clk, mode->clock * 1000); @@ -122,6 +145,8 @@ static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) DCU_THRESHOLD_LS_BF_VS(BF_VS_VAL) | DCU_THRESHOLD_OUT_BUF_HIGH(BUF_MAX_VAL) | DCU_THRESHOLD_OUT_BUF_LOW(BUF_MIN_VAL)); + + drm_dev_exit(idx); return; } @@ -137,11 +162,17 @@ static int fsl_dcu_drm_crtc_enable_vblank(struct drm_crtc *crtc) struct drm_device *dev = crtc->dev; struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); unsigned int value; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return -ENODEV; regmap_read(fsl_dev->regmap, DCU_INT_MASK, &value); value &= ~DCU_INT_MASK_VBLANK; regmap_write(fsl_dev->regmap, DCU_INT_MASK, value); + drm_dev_exit(idx); + return 0; } @@ -150,10 +181,16 @@ static void fsl_dcu_drm_crtc_disable_vblank(struct drm_crtc *crtc) struct drm_device *dev = crtc->dev; struct fsl_dcu_drm_device *fsl_dev = drm_to_fsl_dcu_drm_dev(dev); unsigned int value; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return; regmap_read(fsl_dev->regmap, DCU_INT_MASK, &value); value |= DCU_INT_MASK_VBLANK; regmap_write(fsl_dev->regmap, DCU_INT_MASK, value); + + drm_dev_exit(idx); } static const struct drm_crtc_funcs fsl_dcu_drm_crtc_funcs = { From patchwork Thu Sep 15 00:32:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 12976733 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 C044DC6FA82 for ; Thu, 15 Sep 2022 00:33:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B4C8B10E204; Thu, 15 Sep 2022 00:33:32 +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 CA31610E1CA for ; Thu, 15 Sep 2022 00:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663201997; 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=UrTT7QwQof63VN7IDSDKfIt2sJtV3+I3xYSNcLHiNaY=; b=PLmwqX4Ondb9XXP8bgGkAavS7iKIOx3u9JVtuHYxfay9K/3swa74R7wIcG25tfqGV+Y8ZM 9CZ+O4fhWSikFJyczTPi7c2R1OFvzQepdwii/w3GELpIKrBpv7kKC+faVIbsOhz6/8vUzM gpfkefgHh0eBbLe99V4NSh5sj+fhOrw= 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-386-T9IMHNAiNOSOC80KQJ1qMA-1; Wed, 14 Sep 2022 20:33:11 -0400 X-MC-Unique: T9IMHNAiNOSOC80KQJ1qMA-1 Received: by mail-ed1-f69.google.com with SMTP id m13-20020a056402510d00b004519332f0b1so8313480edd.7 for ; Wed, 14 Sep 2022 17:33: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=UrTT7QwQof63VN7IDSDKfIt2sJtV3+I3xYSNcLHiNaY=; b=4R4Ca0V0Iqp4yhS77yx/xwK3OyVkrFQrs77t8yyz7SyMFmSn7fu+45QHMWiQvgeusc 7F+3dHccnLtfqjjTHf3LkrJltSyUdgDQIiq0AbmzHbl6DGvE82dEHVpJ0gpCo8gPX4el uHPocwNIT1xpkA4NwA9KpsGcHGIQuFqmiKZczOJ57PMphO6+YfHxMiN1xPEXla2wbqQJ z4cNjGrpVQKZShyuj9BqEfyFVSGBQjsJB5h6feuadylgypXoofSS1zV0nYfps+IULd2e vCOIfxTRpchEu71BVvQ9CMTwEuwlLoUhPzIRJugo86v2XiT6XjN2/qMeM0IIIYJA8GPq v/SA== X-Gm-Message-State: ACgBeo1GFbfFHGJUx7V/WmTS2Us0DyP3kaflCf7R3UmTPwpYaKy8U3HQ hgmjv7hs1cTyk4JXfobw3LyM1CLhVtzkB7vH7axpO227pEfHC/oFnAFUv/jLdApxs4GXVJedubG UFmXXw+tIZBRmKAf+mVLfg/gcEtkf X-Received: by 2002:a17:907:b09:b0:76f:99cc:81cd with SMTP id h9-20020a1709070b0900b0076f99cc81cdmr26426927ejl.530.1663201990445; Wed, 14 Sep 2022 17:33:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR5g8V/nPxzHQDJZl0DRT92LXzhiR3i8YcPsXKLctBnnQWAlIwXPYox1IBRFR7Ze6l8SXhLAKA== X-Received: by 2002:a17:907:b09:b0:76f:99cc:81cd with SMTP id h9-20020a1709070b0900b0076f99cc81cdmr26426916ejl.530.1663201990310; Wed, 14 Sep 2022 17:33:10 -0700 (PDT) Received: from pollux.redhat.com ([2a02:810d:4b40:2ee8:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id p5-20020a50cd85000000b0043ba7df7a42sm10701852edi.26.2022.09.14.17.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 17:33:09 -0700 (PDT) From: Danilo Krummrich To: daniel@ffwll.ch, airlied@linux.ie, tzimmermann@suse.de, mripard@kernel.org, stefan@agner.ch, alison.wang@nxp.com Subject: [PATCH drm-misc-next 8/8] drm/fsl-dcu: remove trailing return statements Date: Thu, 15 Sep 2022 02:32:31 +0200 Message-Id: <20220915003231.363447-9-dakr@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220915003231.363447-1-dakr@redhat.com> References: <20220915003231.363447-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" Remove the trailing return statements at the end of void functions. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c | 1 - drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c index c77df9b7893f..23687551c831 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c @@ -147,7 +147,6 @@ static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc *crtc) DCU_THRESHOLD_OUT_BUF_LOW(BUF_MIN_VAL)); drm_dev_exit(idx); - return; } static const struct drm_crtc_helper_funcs fsl_dcu_drm_crtc_helper_funcs = { diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c index 1be3062a95df..d0a14b5b506e 100644 --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c @@ -172,7 +172,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane, } drm_dev_exit(idx); - return; } static const struct drm_plane_helper_funcs fsl_dcu_drm_plane_helper_funcs = {