From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E74BC43466 for ; Fri, 18 Sep 2020 20:00:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 42F872067D for ; Fri, 18 Sep 2020 20:00:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="SYldkyYd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42F872067D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DE44F6ED84; Fri, 18 Sep 2020 20:00:32 +0000 (UTC) Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id 989516ED80 for ; Fri, 18 Sep 2020 20:00:31 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id d4so6395772wmd.5 for ; Fri, 18 Sep 2020 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YQjfx1dlb8AV3hvmklM8AXojRWEWsKETVPO8LS2leI8=; b=SYldkyYd1CBCqWWNOGAgru1KRufRNnCSgvmff391HiV2gNn4mEltKpr7B23Z+WAfpe 3jcaSEkkAWL0kYfmmjtg0tKYRAXuGeJFLQs1l0ynYYsWnWPNcpURAqtVTL5BuXxs6s+H divv0bcIgal0TMAzpcr+a9AMX9QchoZcUfQFc= 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=YQjfx1dlb8AV3hvmklM8AXojRWEWsKETVPO8LS2leI8=; b=mhOfKhg0Uf0NZAgQrS6nOG/mM/hc9O/4JxJ+D96hf5KwaM/GLL5YqwI/G8qSSgJ2nu WrrvPAH97zjy3r3ZKmI2df7ckqUVqdljSU5Jd2ax5caAdDJe5XA4jMz2rN1m89zG2q9u CqrpI1Tlx8ZUD3e6BiLrtUcnwcTFEBs8/Ivw0SKBWRKZe9RT88XwjqEDD+rYW+denkGK 9eX4ItB9XCOQFN/BHluw1TiZaxaU4mSgTbFHlpeUcUtYIBtxev0zv4oHSLCvyANYbURi LqnUBLTiJJLBJeUVgzE44qTNOd+G4OeNBfCwLvAHEgQS+G+y4ttZyd+VDbT1Z2xQB2hw +2Gw== X-Gm-Message-State: AOAM530kqyhmsgQKakm4wQ8bVzDqgL0jkFLTWF8FyU/VZVETVXksgzgR L0Jfgdh4yczfoWIC4TeeYugEhhA2xSqxzm9T X-Google-Smtp-Source: ABdhPJzSiplAkUIwO3Yl7gtgMxbtAxYnYHNrI3sm7sIjYgyAKSL2NgU6kO9Z44Lc3Sr1AoRryrv1Zw== X-Received: by 2002:a1c:7e90:: with SMTP id z138mr16974535wmc.122.1600459229923; Fri, 18 Sep 2020 13:00:29 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id e18sm7492006wra.36.2020.09.18.13.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 13:00:28 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm/i915/selftests: align more to real device lifetimes Date: Fri, 18 Sep 2020 22:00:24 +0200 Message-Id: <20200918200024.2414549-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918132505.2316382-3-daniel.vetter@ffwll.ch> References: <20200918132505.2316382-3-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: Daniel Vetter , Intel Graphics Development , amd-gfx@lists.freedesktop.org, Daniel Vetter , Matthew Auld Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To avoid having to create all the device and driver scaffolding we just manually create and destroy a devres_group. v2: Rebased v3: use devres_open/release_group so we can use devm without real hacks in the driver core or having to create an entire fake bus for testing drivers. Might want to extract this into helpers eventually, maybe as a mock_drm_dev_alloc or test_drm_dev_alloc. v4: - Fix IS_ERR handling (Matt) - Delete surplus put_device() in mock_device_release (intel-gfx-ci) v5: - do not switch to device_add - it breaks runtime pm in the tests and with the devres_group_add/release no longer needed for automatic cleanup (CI). Update commit message to match. - print correct error in pr_err (Matt) Cc: Matthew Auld Reviewed-by: Maarten Lankhorst (v3) Cc: Maarten Lankhorst Reviewed-by: Matthew Auld (v4) Signed-off-by: Daniel Vetter --- .../gpu/drm/i915/selftests/mock_gem_device.c | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c index ac600d395c8f..3b574597cd7f 100644 --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c @@ -79,8 +79,6 @@ static void mock_device_release(struct drm_device *dev) out: i915_params_free(&i915->params); - put_device(&i915->drm.pdev->dev); - i915->drm.pdev = NULL; } static struct drm_driver mock_driver = { @@ -128,12 +126,6 @@ struct drm_i915_private *mock_gem_device(void) pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); if (!pdev) return NULL; - i915 = kzalloc(sizeof(*i915), GFP_KERNEL); - if (!i915) { - kfree(pdev); - return NULL; - } - device_initialize(&pdev->dev); pdev->class = PCI_BASE_CLASS_DISPLAY << 16; pdev->dev.release = release_dev; @@ -144,8 +136,23 @@ struct drm_i915_private *mock_gem_device(void) /* HACK to disable iommu for the fake device; force identity mapping */ pdev->dev.iommu = &fake_iommu; #endif + if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { + put_device(&pdev->dev); + return NULL; + } + + i915 = devm_drm_dev_alloc(&pdev->dev, &mock_driver, + struct drm_i915_private, drm); + if (IS_ERR(i915)) { + pr_err("Failed to allocate mock GEM device: err=%d\n", PTR_ERR(i915)); + devres_release_group(&pdev->dev, NULL); + put_device(&pdev->dev); + + return NULL; + } pci_set_drvdata(pdev, i915); + i915->drm.pdev = pdev; dev_pm_domain_set(&pdev->dev, &pm_domain); pm_runtime_enable(&pdev->dev); @@ -153,16 +160,6 @@ struct drm_i915_private *mock_gem_device(void) if (pm_runtime_enabled(&pdev->dev)) WARN_ON(pm_runtime_get_sync(&pdev->dev)); - err = drm_dev_init(&i915->drm, &mock_driver, &pdev->dev); - if (err) { - pr_err("Failed to initialise mock GEM device: err=%d\n", err); - put_device(&pdev->dev); - kfree(i915); - - return NULL; - } - i915->drm.pdev = pdev; - drmm_add_final_kfree(&i915->drm, i915); i915_params_copy(&i915->params, &i915_modparams); @@ -229,5 +226,8 @@ struct drm_i915_private *mock_gem_device(void) void mock_destroy_device(struct drm_i915_private *i915) { - drm_dev_put(&i915->drm); + struct device *dev = i915->drm.dev; + + devres_release_group(dev, NULL); + put_device(dev); } -- 2.28.0 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49D37C43463 for ; Fri, 18 Sep 2020 20:00:36 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 34BF82067D for ; Fri, 18 Sep 2020 20:00:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="SYldkyYd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34BF82067D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 41DA36ED80; Fri, 18 Sep 2020 20:00:32 +0000 (UTC) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5330F6ED80 for ; Fri, 18 Sep 2020 20:00:31 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id b79so6714125wmb.4 for ; Fri, 18 Sep 2020 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YQjfx1dlb8AV3hvmklM8AXojRWEWsKETVPO8LS2leI8=; b=SYldkyYd1CBCqWWNOGAgru1KRufRNnCSgvmff391HiV2gNn4mEltKpr7B23Z+WAfpe 3jcaSEkkAWL0kYfmmjtg0tKYRAXuGeJFLQs1l0ynYYsWnWPNcpURAqtVTL5BuXxs6s+H divv0bcIgal0TMAzpcr+a9AMX9QchoZcUfQFc= 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=YQjfx1dlb8AV3hvmklM8AXojRWEWsKETVPO8LS2leI8=; b=oVv61j7bZ/2LW/1uGu5+tvgVp4cVEr0UiVc0LLfZGDRoS24/OYMk8J0iI0jv01l4+w APRnYi/Dl7bLNlKatBq+fz35/iqbe/G33m1sXqczSJz8CPTOLmJAACqsrHcEM98o8Wg9 xKW2m2aJZtMm6zgusFQiu/aX2m/F+Mcc4MxlJnUP7770yPsffAilLUDRItwGapBKij06 c4HmGW9dz0UhBNFdcJgvKgA3ch29wpO82RfwFnlMJHGqd7RUetdn9sHwV9UOhVE3H0Sh mby8aiLH1zGIKTg8V1wCloC4HFHv/OUgdeFlL5v1NL1opBo23IAQCFRUpqRm4SMUTqfq kQeg== X-Gm-Message-State: AOAM530o7bRD3+VFjnwnbMPtAbh5cD+u8uFxx6PXycubnAYSQFTyqJfD q+VcCMO7srKjXzD1pxODiWiHBg== X-Google-Smtp-Source: ABdhPJzSiplAkUIwO3Yl7gtgMxbtAxYnYHNrI3sm7sIjYgyAKSL2NgU6kO9Z44Lc3Sr1AoRryrv1Zw== X-Received: by 2002:a1c:7e90:: with SMTP id z138mr16974535wmc.122.1600459229923; Fri, 18 Sep 2020 13:00:29 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id e18sm7492006wra.36.2020.09.18.13.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 13:00:28 -0700 (PDT) From: Daniel Vetter To: DRI Development Date: Fri, 18 Sep 2020 22:00:24 +0200 Message-Id: <20200918200024.2414549-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918132505.2316382-3-daniel.vetter@ffwll.ch> References: <20200918132505.2316382-3-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH] drm/i915/selftests: align more to real device lifetimes X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Intel Graphics Development , amd-gfx@lists.freedesktop.org, Daniel Vetter Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To avoid having to create all the device and driver scaffolding we just manually create and destroy a devres_group. v2: Rebased v3: use devres_open/release_group so we can use devm without real hacks in the driver core or having to create an entire fake bus for testing drivers. Might want to extract this into helpers eventually, maybe as a mock_drm_dev_alloc or test_drm_dev_alloc. v4: - Fix IS_ERR handling (Matt) - Delete surplus put_device() in mock_device_release (intel-gfx-ci) v5: - do not switch to device_add - it breaks runtime pm in the tests and with the devres_group_add/release no longer needed for automatic cleanup (CI). Update commit message to match. - print correct error in pr_err (Matt) Cc: Matthew Auld Reviewed-by: Maarten Lankhorst (v3) Cc: Maarten Lankhorst Reviewed-by: Matthew Auld (v4) Signed-off-by: Daniel Vetter --- .../gpu/drm/i915/selftests/mock_gem_device.c | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c index ac600d395c8f..3b574597cd7f 100644 --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c @@ -79,8 +79,6 @@ static void mock_device_release(struct drm_device *dev) out: i915_params_free(&i915->params); - put_device(&i915->drm.pdev->dev); - i915->drm.pdev = NULL; } static struct drm_driver mock_driver = { @@ -128,12 +126,6 @@ struct drm_i915_private *mock_gem_device(void) pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); if (!pdev) return NULL; - i915 = kzalloc(sizeof(*i915), GFP_KERNEL); - if (!i915) { - kfree(pdev); - return NULL; - } - device_initialize(&pdev->dev); pdev->class = PCI_BASE_CLASS_DISPLAY << 16; pdev->dev.release = release_dev; @@ -144,8 +136,23 @@ struct drm_i915_private *mock_gem_device(void) /* HACK to disable iommu for the fake device; force identity mapping */ pdev->dev.iommu = &fake_iommu; #endif + if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { + put_device(&pdev->dev); + return NULL; + } + + i915 = devm_drm_dev_alloc(&pdev->dev, &mock_driver, + struct drm_i915_private, drm); + if (IS_ERR(i915)) { + pr_err("Failed to allocate mock GEM device: err=%d\n", PTR_ERR(i915)); + devres_release_group(&pdev->dev, NULL); + put_device(&pdev->dev); + + return NULL; + } pci_set_drvdata(pdev, i915); + i915->drm.pdev = pdev; dev_pm_domain_set(&pdev->dev, &pm_domain); pm_runtime_enable(&pdev->dev); @@ -153,16 +160,6 @@ struct drm_i915_private *mock_gem_device(void) if (pm_runtime_enabled(&pdev->dev)) WARN_ON(pm_runtime_get_sync(&pdev->dev)); - err = drm_dev_init(&i915->drm, &mock_driver, &pdev->dev); - if (err) { - pr_err("Failed to initialise mock GEM device: err=%d\n", err); - put_device(&pdev->dev); - kfree(i915); - - return NULL; - } - i915->drm.pdev = pdev; - drmm_add_final_kfree(&i915->drm, i915); i915_params_copy(&i915->params, &i915_modparams); @@ -229,5 +226,8 @@ struct drm_i915_private *mock_gem_device(void) void mock_destroy_device(struct drm_i915_private *i915) { - drm_dev_put(&i915->drm); + struct device *dev = i915->drm.dev; + + devres_release_group(dev, NULL); + put_device(dev); } -- 2.28.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3B09C43464 for ; Fri, 18 Sep 2020 20:00:36 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C2C1421D42 for ; Fri, 18 Sep 2020 20:00:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="SYldkyYd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2C1421D42 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B3BC76ED83; Fri, 18 Sep 2020 20:00:32 +0000 (UTC) Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 571E06ED82 for ; Fri, 18 Sep 2020 20:00:31 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id l9so6720838wme.3 for ; Fri, 18 Sep 2020 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YQjfx1dlb8AV3hvmklM8AXojRWEWsKETVPO8LS2leI8=; b=SYldkyYd1CBCqWWNOGAgru1KRufRNnCSgvmff391HiV2gNn4mEltKpr7B23Z+WAfpe 3jcaSEkkAWL0kYfmmjtg0tKYRAXuGeJFLQs1l0ynYYsWnWPNcpURAqtVTL5BuXxs6s+H divv0bcIgal0TMAzpcr+a9AMX9QchoZcUfQFc= 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=YQjfx1dlb8AV3hvmklM8AXojRWEWsKETVPO8LS2leI8=; b=He4U14/Vc3M7ncwQQkwkz3sePs4tlqF9hzr4LViQMc+0JlKjk/g+WrxVdmd+8tIN2S R9Cr0I6aLF2mZUQ8IC+499Qtx7XjRVzon/yvSXP2iwQgki2bzNXlspv9DgqUq4Oh8Qs8 7qR6sO9v+VHOewsLG1tiKOqUKQ/my2cxnYETXYCvxHqb6UEqcpHKnDnT+UfMH4QRIRes OSpVPm81aBtLd/+u7tBgdJGictlxvwmJ1Ex/lwqaYY97SZ+4w4Mej2eww4I2QcWWQjbm k/Rp/nxQv1ROtouPVcFs7ezt5ptyqauMnBtqpQmfVLnNLy48PuFyFP0g3b0COnFPJcvo znVw== X-Gm-Message-State: AOAM533AB/NB+DA0ZbRdWVemwmB8dqj5I4uBCVF18/wp4wGy81quBeIX zkQazuV6efT03XylxOKYMhRFuQ== X-Google-Smtp-Source: ABdhPJzSiplAkUIwO3Yl7gtgMxbtAxYnYHNrI3sm7sIjYgyAKSL2NgU6kO9Z44Lc3Sr1AoRryrv1Zw== X-Received: by 2002:a1c:7e90:: with SMTP id z138mr16974535wmc.122.1600459229923; Fri, 18 Sep 2020 13:00:29 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id e18sm7492006wra.36.2020.09.18.13.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 13:00:28 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm/i915/selftests: align more to real device lifetimes Date: Fri, 18 Sep 2020 22:00:24 +0200 Message-Id: <20200918200024.2414549-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918132505.2316382-3-daniel.vetter@ffwll.ch> References: <20200918132505.2316382-3-daniel.vetter@ffwll.ch> MIME-Version: 1.0 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Intel Graphics Development , Maarten Lankhorst , amd-gfx@lists.freedesktop.org, Daniel Vetter , Matthew Auld Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" To avoid having to create all the device and driver scaffolding we just manually create and destroy a devres_group. v2: Rebased v3: use devres_open/release_group so we can use devm without real hacks in the driver core or having to create an entire fake bus for testing drivers. Might want to extract this into helpers eventually, maybe as a mock_drm_dev_alloc or test_drm_dev_alloc. v4: - Fix IS_ERR handling (Matt) - Delete surplus put_device() in mock_device_release (intel-gfx-ci) v5: - do not switch to device_add - it breaks runtime pm in the tests and with the devres_group_add/release no longer needed for automatic cleanup (CI). Update commit message to match. - print correct error in pr_err (Matt) Cc: Matthew Auld Reviewed-by: Maarten Lankhorst (v3) Cc: Maarten Lankhorst Reviewed-by: Matthew Auld (v4) Signed-off-by: Daniel Vetter --- .../gpu/drm/i915/selftests/mock_gem_device.c | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c index ac600d395c8f..3b574597cd7f 100644 --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c @@ -79,8 +79,6 @@ static void mock_device_release(struct drm_device *dev) out: i915_params_free(&i915->params); - put_device(&i915->drm.pdev->dev); - i915->drm.pdev = NULL; } static struct drm_driver mock_driver = { @@ -128,12 +126,6 @@ struct drm_i915_private *mock_gem_device(void) pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); if (!pdev) return NULL; - i915 = kzalloc(sizeof(*i915), GFP_KERNEL); - if (!i915) { - kfree(pdev); - return NULL; - } - device_initialize(&pdev->dev); pdev->class = PCI_BASE_CLASS_DISPLAY << 16; pdev->dev.release = release_dev; @@ -144,8 +136,23 @@ struct drm_i915_private *mock_gem_device(void) /* HACK to disable iommu for the fake device; force identity mapping */ pdev->dev.iommu = &fake_iommu; #endif + if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { + put_device(&pdev->dev); + return NULL; + } + + i915 = devm_drm_dev_alloc(&pdev->dev, &mock_driver, + struct drm_i915_private, drm); + if (IS_ERR(i915)) { + pr_err("Failed to allocate mock GEM device: err=%d\n", PTR_ERR(i915)); + devres_release_group(&pdev->dev, NULL); + put_device(&pdev->dev); + + return NULL; + } pci_set_drvdata(pdev, i915); + i915->drm.pdev = pdev; dev_pm_domain_set(&pdev->dev, &pm_domain); pm_runtime_enable(&pdev->dev); @@ -153,16 +160,6 @@ struct drm_i915_private *mock_gem_device(void) if (pm_runtime_enabled(&pdev->dev)) WARN_ON(pm_runtime_get_sync(&pdev->dev)); - err = drm_dev_init(&i915->drm, &mock_driver, &pdev->dev); - if (err) { - pr_err("Failed to initialise mock GEM device: err=%d\n", err); - put_device(&pdev->dev); - kfree(i915); - - return NULL; - } - i915->drm.pdev = pdev; - drmm_add_final_kfree(&i915->drm, i915); i915_params_copy(&i915->params, &i915_modparams); @@ -229,5 +226,8 @@ struct drm_i915_private *mock_gem_device(void) void mock_destroy_device(struct drm_i915_private *i915) { - drm_dev_put(&i915->drm); + struct device *dev = i915->drm.dev; + + devres_release_group(dev, NULL); + put_device(dev); } -- 2.28.0 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx