Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp947051pxb; Thu, 5 Nov 2020 18:21:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJysrrWQ6G5LkyrsnD74DjoYxDW0B/7h7Noz7Az4brLoQTS2s4Q7OF8HIjoWGgi8lyZ4lSXa X-Received: by 2002:a17:906:4748:: with SMTP id j8mr5102537ejs.22.1604629302832; Thu, 05 Nov 2020 18:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604629302; cv=none; d=google.com; s=arc-20160816; b=mL9L097y46N7AT512l7Vzoxfk3y7xDslSf+iy44QdtxTibvZsvyDH/pRqj7FHK8fCY ZC/8F+TKM48TceCTgnKGlLdNNr/aEzWi03q7TBG7zUIxC9oI4JCBpFGgzaTGEcC/fi3h G060wExSs7ipmL9mFLpgGu1Xsxmjr8j+ZpuDJ3qL+KyXANr5MKAJnI9ZyXLMaKfmKNPR /p5WnNJdFqgybnXRukpp9yTBRTNOeiiXSkoK+5dOM2iDovCeWWuG+OoyJHC9um/jmL0p 4wR1wd1O63rTH1spsF/mhUlDlZ6eQIJasqTQPORwexHTxAJcoTBzTPBUWwQgoEZZwPqw 1C7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hkWonUI6QAjKhs8ezdt4KReWYH2K8M+YMQvYNsUkFyw=; b=IZYsvZdsAYUiRbh96WVQrLs5uRXh9P804xqFoHh8lGvmjrjGidQ0fr64ggbgEZ6XDX G8S0G7mJPO8IgXmnuXJfmkI53aG+ReU1jhpJhp1vNTOvmAy0FPRaewlfJAXu6fwHro7z TuXLdGMOvbgzgaqysnAOrGnEN8oQhhNnJ0Z/6z1T7CU1NqzOtrh2xjSvIdL4aP+ONE8/ P5rdgSnl1OiNRtOqdvrhejmzW5o6mdSi0flDHktERRkbTfww6b14g1tnip/8UvM/NrwR TyYBt4WOBdK5dcIzkFicJWWsgkEC4sAWf6UeKbvMpZifWkEw/uzcPS9AJVt7n/Uwz9J2 DiIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BJOT5mSD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x18si3143750ejd.193.2020.11.05.18.21.20; Thu, 05 Nov 2020 18:21:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BJOT5mSD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725894AbgKFCRn (ORCPT + 99 others); Thu, 5 Nov 2020 21:17:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36179 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbgKFCRl (ORCPT ); Thu, 5 Nov 2020 21:17:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604629059; 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=hkWonUI6QAjKhs8ezdt4KReWYH2K8M+YMQvYNsUkFyw=; b=BJOT5mSDukHQlpn4m2qNUcJFivtV8uF+VoUh77ahUKM0oWEnLDn06oBAukzKk5xxLD+7DC k6k5n7AynnBHQjFVhqsCLAX4Kku4oTP51sF9euQJm+xqvb+A0E8dKaZreZ9zNWOhkNfhzi j5HAT0PIGzu8Ko4iCL/A0HJ5evKCTV4= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-oOAvU_SaO0OoSaCBsxfgrg-1; Thu, 05 Nov 2020 21:17:38 -0500 X-MC-Unique: oOAvU_SaO0OoSaCBsxfgrg-1 Received: by mail-qt1-f199.google.com with SMTP id 22so2181901qtp.9 for ; Thu, 05 Nov 2020 18:17:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hkWonUI6QAjKhs8ezdt4KReWYH2K8M+YMQvYNsUkFyw=; b=Yw1jsL1qaWvn9PoLNaP4B9+w0QxP1MnPLhrpKOD+MaiYlSd21Igli5JwLQCnEayOeL 8MONaR3Wtfuq0Lv5yJ+FMsJQCXiQMOZTySRAcr0p5lUy5lbvKfCGI5lGIhUur8x//i2f NT4BrR9oRu9S0yFWWKuEd/4Tpq9myro52RcLxLAVN7OM8lf2KO/s//bZkHvG29qJY0C0 PBcpiLo7Wdv9fe/ZjEnYqqmWdOYBI3ZU1i30jcQP4CsDOahKlq6gfgw4Fcr9W220yPAK IUv4FNWdCM/P7DKcawfeD6PjiyUMeBvzZgKQ9MQa5FVPKiiO7m/bBkcYIRAFCLydInaV AJhQ== X-Gm-Message-State: AOAM532a9RUqr+5l8pAPFWCooGY4tq5mvI/ET53iQxh6D7zI7wXMfBU8 D/5C3ER+ePtK+JBvkULUWe5WbHTZcHoaBEz1y+wk5+WDXhsS/Cc4eiu+AHEbtlXr1pMbELBnB5d mDYbTV6F6RNMktELAPldKhPu+ X-Received: by 2002:ae9:e314:: with SMTP id v20mr5187250qkf.93.1604629057899; Thu, 05 Nov 2020 18:17:37 -0800 (PST) X-Received: by 2002:ae9:e314:: with SMTP id v20mr5187242qkf.93.1604629057714; Thu, 05 Nov 2020 18:17:37 -0800 (PST) Received: from xps13.jcline.org ([2605:a601:a639:f01:1ac8:8e0c:f1cc:7a29]) by smtp.gmail.com with ESMTPSA id q20sm2195301qtn.80.2020.11.05.18.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 18:17:37 -0800 (PST) From: Jeremy Cline To: Ben Skeggs Cc: David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jeremy Cline Subject: [PATCH 2/3] drm/nouveau: manage nouveau_drm lifetime with devres Date: Thu, 5 Nov 2020 21:16:55 -0500 Message-Id: <20201106021656.40743-3-jcline@redhat.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201106021656.40743-1-jcline@redhat.com> References: <20201106021656.40743-1-jcline@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the devm_drm_dev_alloc() API to bind the lifetime of nouveau_drm structure to the drm_device. This is important because a reference to nouveau_drm is accessible from drm_device, which is provided to a number of DRM layer callbacks that can run after the deallocation of nouveau_drm currently occurs. Signed-off-by: Jeremy Cline --- drivers/gpu/drm/nouveau/nouveau_drm.c | 44 ++++++++++++--------------- drivers/gpu/drm/nouveau/nouveau_drv.h | 10 ++++-- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index bc6f51bf23b7..f750c25e92f9 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -30,9 +30,11 @@ #include #include +#include #include #include #include +#include #include #include @@ -532,13 +534,8 @@ nouveau_parent = { static int nouveau_drm_device_init(struct drm_device *dev) { - struct nouveau_drm *drm; int ret; - - if (!(drm = kzalloc(sizeof(*drm), GFP_KERNEL))) - return -ENOMEM; - dev->dev_private = drm; - drm->dev = dev; + struct nouveau_drm *drm = nouveau_drm(dev); nvif_parent_ctor(&nouveau_parent, &drm->parent); drm->master.base.object.parent = &drm->parent; @@ -620,7 +617,6 @@ nouveau_drm_device_init(struct drm_device *dev) nouveau_cli_fini(&drm->master); fail_alloc: nvif_parent_dtor(&drm->parent); - kfree(drm); return ret; } @@ -654,7 +650,6 @@ nouveau_drm_device_fini(struct drm_device *dev) nouveau_cli_fini(&drm->client); nouveau_cli_fini(&drm->master); nvif_parent_dtor(&drm->parent); - kfree(drm); } /* @@ -720,6 +715,7 @@ static int nouveau_drm_probe(struct pci_dev *pdev, { struct nvkm_device *device; struct drm_device *drm_dev; + struct nouveau_drm *nv_dev; int ret; if (vga_switcheroo_client_probe_defer(pdev)) @@ -750,15 +746,16 @@ static int nouveau_drm_probe(struct pci_dev *pdev, if (nouveau_atomic) driver_pci.driver_features |= DRIVER_ATOMIC; - drm_dev = drm_dev_alloc(&driver_pci, &pdev->dev); - if (IS_ERR(drm_dev)) { - ret = PTR_ERR(drm_dev); + nv_dev = devm_drm_dev_alloc(&pdev->dev, &driver_stub, typeof(*nv_dev), drm_dev); + if (IS_ERR(nv_dev)) { + ret = PTR_ERR(nv_dev); goto fail_nvkm; } + drm_dev = nouveau_to_drm_dev(nv_dev); ret = pci_enable_device(pdev); if (ret) - goto fail_drm; + goto fail_nvkm; drm_dev->pdev = pdev; pci_set_drvdata(pdev, drm_dev); @@ -778,8 +775,6 @@ static int nouveau_drm_probe(struct pci_dev *pdev, nouveau_drm_device_fini(drm_dev); fail_pci: pci_disable_device(pdev); -fail_drm: - drm_dev_put(drm_dev); fail_nvkm: nvkm_device_del(&device); return ret; @@ -799,7 +794,6 @@ nouveau_drm_device_remove(struct drm_device *dev) device = nvkm_device_find(client->device); nouveau_drm_device_fini(dev); - drm_dev_put(dev); nvkm_device_del(&device); } @@ -1285,7 +1279,8 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func, struct platform_device *pdev, struct nvkm_device **pdevice) { - struct drm_device *drm; + struct nouveau_drm *nv_dev; + struct drm_device *drm_dev; int err; err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug, @@ -1293,22 +1288,21 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func, if (err) goto err_free; - drm = drm_dev_alloc(&driver_platform, &pdev->dev); - if (IS_ERR(drm)) { - err = PTR_ERR(drm); + nv_dev = devm_drm_dev_alloc(&pdev->dev, &driver_platform, typeof(*nv_dev), drm_dev); + if (IS_ERR(nv_dev)) { + err = PTR_ERR(nv_dev); goto err_free; } + drm_dev = nouveau_to_drm_dev(nv_dev); - err = nouveau_drm_device_init(drm); + err = nouveau_drm_device_init(drm_dev); if (err) - goto err_put; + goto err_free; - platform_set_drvdata(pdev, drm); + platform_set_drvdata(pdev, drm_dev); - return drm; + return drm_dev; -err_put: - drm_dev_put(drm); err_free: nvkm_device_del(pdevice); diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index 3e2920a10099..cf6c33e52a5c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -137,7 +137,11 @@ struct nouveau_drm { struct nvif_parent parent; struct nouveau_cli master; struct nouveau_cli client; - struct drm_device *dev; + + /** + * @drm_dev: The parent DRM device object. + */ + struct drm_device drm_dev; struct list_head clients; @@ -237,7 +241,7 @@ struct nouveau_drm { static inline struct nouveau_drm * nouveau_drm(struct drm_device *dev) { - return dev->dev_private; + return container_of(dev, struct nouveau_drm, drm_dev); } /** @@ -251,7 +255,7 @@ nouveau_drm(struct drm_device *dev) */ static inline struct drm_device * nouveau_to_drm_dev(struct nouveau_drm *nv_dev) { - return nv_dev->dev; + return &nv_dev->drm_dev; } /** -- 2.28.0