From patchwork Wed Nov 29 22:14:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 13473590 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 5F861C10DC1 for ; Wed, 29 Nov 2023 22:15:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9578F10E695; Wed, 29 Nov 2023 22:15:11 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id DEB6510E507; Wed, 29 Nov 2023 22:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701296105; x=1732832105; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=QycBI7Kt9PgTyJxaiH/+LWXtKXKuLCo9OVwQRLqdWtI=; b=PKq7QXCWAoXehzRdI4/izRM1GKNszSTSRgeEnztSXJkaaAwSqXWDq8mq rbU+DVX5H5FPkcotvu+Li2X0kSgbHcjtuQwV7etKK1LBk0LZ9NLhfYXAd ve8Pi1hnQPrCfMWxiEG10jtSirBtgHVnvfO1fqzmyzf932w3yypBLLVrV gMwO0y9iMArRKnCOqky6cBXJO3xKux6WyPXbvPjzF6P8CLtzr2Qe3+K23 lqYZ5uDsPlE/FC5BJPDLovirQOmKJX1nr1rnnkMpopjkeLu1OP2E0YsiW TdhjjxfgqpPNkkGvYcpyd6vR6+WPc/RcRORnxHfgG8QtlWUpUCoPJ65zn w==; X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="11935320" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="11935320" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 14:14:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="912984151" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="912984151" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 29 Nov 2023 14:14:48 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 29 Nov 2023 14:14:48 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Wed, 29 Nov 2023 14:14:48 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.100) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Wed, 29 Nov 2023 14:14:48 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IVptYmUGJp5F3k0ylP+qIo/rE+U1KK+MjvDjGGgENiYFXEX2M8G+GT12rJ5+wFQzfVr6flN6GAT3sTmOOxM1tbASBRc+0+LNsRIOsy89T+/tg709c1f+zCzeUZ9x7FpqBH1GgxI0boggeluJwrJlDj53qWTTEaSEt9dNBOl61O09fFn8Jaqbkg2cvn7AkY17IRPCjss9iEAGsNk2uisnV/DEhkhtThel7oqjlNgR/PMwkoSDGRbUYBCzGHKcqjbvMWnI9tu26QkKlL+931zmvA3fUno0dbFnuMEKHCTiJXtCIJPzXqY6sUbfid2af22ns7eHI5WpwoWC+50UWhTlkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZmFrd6XZVfmcX6t5o754wGjAQjnYdG1Cx10L3HP9BJc=; b=GeBqhSc2Q/Udmk7YaIAddHCxzY1XZReQJxVLmCKpLXFr9UiYMuZ5nt+CI5FMTYzZC6V6U6u3yr9OJQsRTTefUDPaCoEjX2fB5Kmvr4N+boYHt8QfdGT9ZRnquTQAHvBqMJVp4v5N3SHyFmwwL917AQ+PsBSisczGw1BoWwDRqgcQG4f0D+ZOldnuZB6WBl8b9VhTYPiNqOBnurhqdrIrLSEsAOuzMs2Y0+AWejEznM9QA1qEDh3NDFuD2SZhxaNHPRoTAgAMHcdkOlXEwohFE2C98o1LWivcsNBz0LIDtn+RCf3U5xz1dE+88OXB5a66EKxJZ4QRLvOnDO9mkolTEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by CYYPR11MB8432.namprd11.prod.outlook.com (2603:10b6:930:be::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.29; Wed, 29 Nov 2023 22:14:45 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821%4]) with mapi id 15.20.7046.015; Wed, 29 Nov 2023 22:14:45 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH 1/2] drm/managed: Add drmm_release_action Date: Wed, 29 Nov 2023 23:14:11 +0100 Message-ID: <20231129221412.1180549-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231129221412.1180549-1-michal.winiarski@intel.com> References: <20231129221412.1180549-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA2P291CA0044.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1f::20) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CYYPR11MB8432:EE_ X-MS-Office365-Filtering-Correlation-Id: f2a50c92-ea8f-4863-7dab-08dbf1289806 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uxMFSmOZIQJYVb+NrQ5AmIpk5hyr81KUOkQL8z020l306l2mZ9f7rboUFztSNWD+Jd02lB3OxGo/84CmvyDtJdHGjwOMgqYbDC53OXZVsFxOFvakVJRUvYTNNCCfyHtzPNw6aR3XZBb5E9qpD/G5I0SfbgSscbF/+PNF+RTYQb0eQNYXYris9oAhZK5EGIHCPWmwSh/8dXxuJX4wvSeUVJKZ0t3nJDZG8WtUmXuwImZ2FTsi8BLhuWGMulyUsr21q5+Buz80CHDYFO5ppftqs7ro6W5PntOSg7s2xD2mClnN+nUzEgt6xGD/tQKBJsP9751EIkk7a4RhsHxH4JK+L/0/vf5jz/1/us3G3V1PXqntFZ06TwMkEtN+hMUtPwNjf9ou3JPqBJa/nHxdJhpMnHdp7rHTOQGINUgzZ6l47UGnlD2FrEt8qZhZM8j2SxLBmGRO6rMa03y2qtl6T3LAz4Okr9wSEo1C8b+3PWvl1Un2AtIllc80MbvExhvfounCdTywjc01RGQpcQjY0b+at/6QHTO/GE2nltgL7qZltyGgfWcOzkDJkRKP8MF4jsJzLM5R6t98AwMWPq7ND00/tXLF1vHdn3bz/bh/M2X2Ek9zXoOTSsjj+VnMcjpCZPAB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(396003)(376002)(346002)(136003)(39860400002)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(36756003)(6506007)(41300700001)(38100700002)(2906002)(83380400001)(7416002)(82960400001)(5660300002)(26005)(86362001)(1076003)(2616005)(202311291699003)(8936002)(4326008)(8676002)(6666004)(6512007)(6486002)(478600001)(66946007)(54906003)(66556008)(66476007)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SCXV9jtpPpHGWkmaVf65MaHMeAZA?= =?utf-8?q?zttlXm8cyvpAIWepl59+q7uAHaXUiIbJj1psBH6KGBJNKJcwmP3PJf9eTaO20AlNm?= =?utf-8?q?ItJit8QAvSOyJIigyVvtvQ9ik/83dLKKi9dPS0lnkTq0kEX8GTaLClCIubieVCRdg?= =?utf-8?q?UjohVLe+Nw0xEejl32VcfRIKoIeWNkXiAiG7scvHk40SxB8fVIk4jx3sRJLYGYCYL?= =?utf-8?q?MEOhCClOylUiS3dBO7dH6qUxODSy07JgGF/Viz80iqfcyMTOIr2O05k3/jEgc8ToF?= =?utf-8?q?GieNADcHj76fGTQO0XjmIPg9U0Hi8hYHU4Om/Tc1x86kZX8BrpZbSRhzo3Qr+R918?= =?utf-8?q?zr9JHQMQXiuWMkosXgSa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2LNgWnkBQOswOB3ns0PBfDAJYbS+n51BN613/FXq3gZ?= =?utf-8?q?5hpDDIsXll45X0N3BKlksyAMk2l6QAKaH5g8XpABfgVu0P+OobML0xN742b7TY06Y?= =?utf-8?q?OsNFljgmhxh1esTCM+phA/K7A4YSeRSgaTJAKmjqla2wbYjLLaiPS7q8slMfvjzxm?= =?utf-8?q?Rv7YUb7FM5PHrdU1W7mZRli6PNolDAdsP8RZbHDJQQ4x258FdKxKe0U6WAGt4BR/n?= =?utf-8?q?tNzbdxCgx8kOI7Fhxbu2OA1pVeweY5ECEbJov62EVstJw30HqZgjrOCuoC+FqFjoH?= =?utf-8?q?sGjrdfJm2F3Zin25EMjNjNOlnY7bKAEkyA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: f2a50c92-ea8f-4863-7dab-08dbf1289806 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2023 22:14:45.5696 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lfvecdOGDugG0VjZp4LfQVMqZrDkvSJ+ZZaihKkDq19M3fpyw564pkkuatWYhJvij74ZKOtWkmYLm1vtLEZW1W/Z5+zJUEASeayKFyzVKmA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR11MB8432 X-OriginatorOrg: intel.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: =?utf-8?q?Micha=C5=82_Winiarski?= , =?utf-8?q?Ma=C3=ADra_Canal?= , Javier Martinez Canillas , Maxime Ripard , Thomas Zimmermann , Rodrigo Vivi , Michal Wajdeczko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Similar to devres equivalent, it allows to call the "release" action directly and remove the resource from the managed resources list. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/drm_managed.c | 39 +++++++++++++++++++++++++++++++++++ include/drm/drm_managed.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c index bcd111404b128..7646f67bda4e4 100644 --- a/drivers/gpu/drm/drm_managed.c +++ b/drivers/gpu/drm/drm_managed.c @@ -176,6 +176,45 @@ int __drmm_add_action_or_reset(struct drm_device *dev, } EXPORT_SYMBOL(__drmm_add_action_or_reset); +/** + * drmm_release_action - release a managed action from a &drm_device + * @dev: DRM device + * @action: function which would be called when @dev is released + * @data: opaque pointer, passed to @action + * + * This function calls the @action previously added by drmm_add_action() + * immediately. + * The @action is removed from the list of cleanup actions for @dev, + * which means that it won't be called in the final drm_dev_put(). + */ +void drmm_release_action(struct drm_device *dev, + drmres_release_t action, + void *data) +{ + struct drmres *dr_match = NULL, *dr; + unsigned long flags; + + spin_lock_irqsave(&dev->managed.lock, flags); + list_for_each_entry_reverse(dr, &dev->managed.resources, node.entry) { + if (dr->node.release == action) { + if (!data || (data && *(void **)dr->data == data)) { + dr_match = dr; + del_dr(dev, dr_match); + break; + } + } + } + spin_unlock_irqrestore(&dev->managed.lock, flags); + + if (WARN_ON(!dr_match)) + return; + + action(dev, data); + + free_dr(dr_match); +} +EXPORT_SYMBOL(drmm_release_action); + /** * drmm_kmalloc - &drm_device managed kmalloc() * @dev: DRM device diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h index ad08f834af408..f547b09ca0239 100644 --- a/include/drm/drm_managed.h +++ b/include/drm/drm_managed.h @@ -45,6 +45,10 @@ int __must_check __drmm_add_action_or_reset(struct drm_device *dev, drmres_release_t action, void *data, const char *name); +void drmm_release_action(struct drm_device *dev, + drmres_release_t action, + void *data); + void *drmm_kmalloc(struct drm_device *dev, size_t size, gfp_t gfp) __malloc; /** From patchwork Wed Nov 29 22:14:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 13473589 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 11EB6C4167B for ; Wed, 29 Nov 2023 22:15:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F10D410E507; Wed, 29 Nov 2023 22:15:04 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 72D8E10E507; Wed, 29 Nov 2023 22:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701296103; x=1732832103; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=VCUqrEvbOgfljmKuVyn/aVdpbVNBQYXk9viQlZIVKtk=; b=T49rXNG8GtSjqcd6kRtJY5Ul9k2wRV1sDaCfajTd9YBlzbxXBVaAuMSr 0v9CZ+gTPkYBhaVtCwkVA7/sWvN7FdFGpdxfoitcw5YsunPnkJ7DJ3zr4 fjSLIsQ6k/zavZissfqjcLfdlrZcEdkuXDEij5ovF2dS57pP7AZaFXUw9 D739IvjcDj2u69dRu28TKNjbTttOLKH6vHDScvfGql2m7kYh2XW+cPHLD AAQKyYdnouEfqEx45blABXgayFbNMMZPS8bwtm+owFlDZ1Q5E79Vod7kG uU6NPe4hWqKfPXaWqRtE9U3YGOjvyk8p/i7P8bHIR7YHkNpAfePZ2l7U/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="11935330" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="11935330" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 14:14:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="912984157" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="912984157" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 29 Nov 2023 14:14:52 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 29 Nov 2023 14:14:51 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Wed, 29 Nov 2023 14:14:51 -0800 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.40) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Wed, 29 Nov 2023 14:14:51 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k7cKDBLg0UIjTB7h7TlPFb4Nu17cxHupNOVD/HXtludY9nc+vMyFEvnhgOLYPuGKrc5xyhwfh9OeKzbHk8oJD1DYwCEoKtnOwDPrxdJfDgY7a+5viXf62bD0eGv6UzyH6N+zEbqUcpnJRzP+sNchGjJgYyLE4TLvLQ9rOdDSF3cpb0blZGs1RT625lUvCeIaQuiWi/ZZQeT7BACLmbvgnWQATMMKt4jAEWGSGDpS6dUkdD3L7j1BCYLv5/LWuP8zKvDMs0SNm2+U56uN7sHVr2G3IxLlCftb3+HcojuzBU/E0dRDjmG0KZ9WkwRi4lEU4ujGf+2jN0BmBC1mIJlcrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ea9DDKEx/y8I1Qv/Zpuy1E6FoPnW639S31vVs4kxS6s=; b=SH/aN2KKadBFG+t9WJ88HA+TSRg9X0o1yl8XynNqFk7+rdDAhCZqRkvrXj3S9Jn2p6dywOt2plNQ+eEncWfpYqk2wCY3y6OT3QMkrEbiMT1rUPKztuyeO8IQrSqjxSi+d9fZAu2QIdrduGOhR6TA0aWGhmGRTBhdU5rQJ5gKB3W34POAtF7YOejykLEyUe9SRIqarJ1W2fTRJaRzEHMHaRRnPaCiNNi7o8dviCIv+t0SKLBvv8xPmzmGgPOjuiUamLYLTj+PyvgaTT5OZdletV7+iMK70Pw9ivNwZ/oLov9+OCo6AExOIqyCCeZyyKEsYOkBdmg8MMSTAcq1WmLOYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DM3PR11MB8733.namprd11.prod.outlook.com (2603:10b6:0:40::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.23; Wed, 29 Nov 2023 22:14:49 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821%4]) with mapi id 15.20.7046.015; Wed, 29 Nov 2023 22:14:49 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH 2/2] drm/tests: managed: Add a simple test for drmm_managed_release Date: Wed, 29 Nov 2023 23:14:12 +0100 Message-ID: <20231129221412.1180549-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231129221412.1180549-1-michal.winiarski@intel.com> References: <20231129221412.1180549-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR4P281CA0171.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b7::18) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|DM3PR11MB8733:EE_ X-MS-Office365-Filtering-Correlation-Id: 06f13fdd-b885-4ac7-681a-08dbf1289a95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tovgHS4uobpecGFlg9wtY3e8RTaFV7s0CTevNFvdbNJQ7KQZz2Bu2DmSGOWe2g05YST+1Rmh5MAnscnWGaBHkzifzvaCMy3mQxomAnDHBW9wbT4M2lH23cyQfhoKoU17XhKddvSqPJjSd5ZGJW6O3/j9w/q1UYyfNm8W1+4N76Y+WzCuZDAOCePp1dgrxds1vmca/Ajxz+sW4KHYRFHWs5j/xy69n5jIUIryud6+yzZciEe/YZmyUQ6+imHH2WRJTJJ7M3y8DWEzz45NmESSHPO6MnsUcx8H6VP62FpsWoYhsS6NHkbtzmYmkX0hxDiEqjlD5/1XH3sGuEcS2QG8/zvj7KuQ4roypcUsyAAi6/2YlAZnato97G6oQKRgAbEqorX4NSgxJcCreOWjD3/sqq8xujU1IZelDCMZTg0XEgWhAr44j9kLKDSM2PIIzhLsZ5iv6xRBBfEiIKR2ci3KN5ePdkGd+PB/2OTkkwNhs97/wvPp4xFy5b1sRPsORgHQ+tHRNtJAB7YMTE3m6Bkq/BmIOxO6Y/1hm+fo0wtv3MemaZ9j4CBtJiMmO+o7AAc1Nt+3YHgh+UxLh3IziLSvD/7OyHLhxseuxX/GNTu6+r/tSalzxsCaxvfZ6VzQ8C0B X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(39860400002)(366004)(136003)(376002)(346002)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(1076003)(26005)(6506007)(2616005)(6512007)(36756003)(6666004)(82960400001)(83380400001)(41300700001)(66476007)(66946007)(66556008)(54906003)(316002)(5660300002)(7416002)(2906002)(202311291699003)(8936002)(86362001)(8676002)(38100700002)(4326008)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ZmwQTtpOxl8ZeORu3GdB5ZtXnVdY?= =?utf-8?q?OgAwARwzbXLYkdc3GE1vQeLoj6oBOglE+Mqm2UgVn+FKv0EIgL6gIzF7S/8lTThSN?= =?utf-8?q?Tc1588a3n7sRmyhbEdDYqnAKXJcSjk5IlgvScy7O55zwXPGpd78ns2LZKw1cPU82I?= =?utf-8?q?SVkz1m9GSkjZFapFF+3lAEF38HwERajq1GuAzWvxfQQVA/1QS0Nix+K/vg5juWlhL?= =?utf-8?q?roN0IyrW4us1aDrr1tdMYUpjk5CRok9w8NSFqzczyJryX1+yORKMu7PkSFmrsnpyY?= =?utf-8?q?xsI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HvZ8Az/Kht5I5U0PuZev8eWx/NAcHj1E0Ye2VciAH11wgbhwiVAuMDC8?= =?utf-8?q?gzz2oP0uLBt+vuZrFx48rIIlxJOZOq7skKNhDWMCNUgsH459NuJrg/sPaa1y3xIzx?= =?utf-8?q?8U1eMWm44opy5kr3UJTo2M8lMOMkiKBiAB28D/o6zjKN17ccUzmTUOYqfrBlYAKIa?= =?utf-8?q?roZnXyX5t7q4tqlDp7Yuw+IAbGXofILteQ3D8A2fYBL8NEWckHc6m0Xr181Iwp+nz?= =?utf-8?q?CrEiQaBuNrD4FMrCWwIDMl/ecgoorltO5pPaG7RC4AioCLt1ES9tkwTyUZOtgxA3I?= =?utf-8?q?n6jQIgforVNn3nQEpDvRAdojaow29tp7KOCumnQUhDGG6LVh3BTkqw9s1qCii+KX5?= =?utf-8?q?PbWtQMBUBISZgO4GACdAcn546IHkz2perQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 06f13fdd-b885-4ac7-681a-08dbf1289a95 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2023 22:14:49.8485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /6q64r6uKTL14MLPGqpNqC857I0Um+6t20RrWNlYS6y67LKNMUGvHHFWNcO837XpSResQPriBodRr+ybWmGt0sKaRCo5TFJj6eusUoPdePA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR11MB8733 X-OriginatorOrg: intel.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: =?utf-8?q?Micha=C5=82_Winiarski?= , =?utf-8?q?Ma=C3=ADra_Canal?= , Javier Martinez Canillas , Maxime Ripard , Thomas Zimmermann , Rodrigo Vivi , Michal Wajdeczko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a simple test that checks whether the action is indeed called right away and that it is not called on the final drm_dev_put(). Signed-off-by: Michał Winiarski --- drivers/gpu/drm/tests/drm_managed_test.c | 65 ++++++++++++++++++------ 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/tests/drm_managed_test.c index 1652dca11d30c..a645ea42aee56 100644 --- a/drivers/gpu/drm/tests/drm_managed_test.c +++ b/drivers/gpu/drm/tests/drm_managed_test.c @@ -12,6 +12,8 @@ #define TEST_TIMEOUT_MS 100 struct managed_test_priv { + struct drm_device *drm; + struct device *dev; bool action_done; wait_queue_head_t action_wq; }; @@ -26,42 +28,75 @@ static void drm_action(struct drm_device *drm, void *ptr) static void drm_test_managed_run_action(struct kunit *test) { - struct managed_test_priv *priv; - struct drm_device *drm; - struct device *dev; + struct managed_test_priv *priv = test->priv; int ret; - priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); - init_waitqueue_head(&priv->action_wq); + ret = drmm_add_action_or_reset(priv->drm, drm_action, priv); + KUNIT_EXPECT_EQ(test, ret, 0); - dev = drm_kunit_helper_alloc_device(test); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + ret = drm_dev_register(priv->drm, 0); + KUNIT_ASSERT_EQ(test, ret, 0); + + drm_dev_unregister(priv->drm); + drm_kunit_helper_free_device(test, priv->dev); - drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm); + ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done, + msecs_to_jiffies(TEST_TIMEOUT_MS)); + KUNIT_EXPECT_GT(test, ret, 0); +} - ret = drmm_add_action_or_reset(drm, drm_action, priv); +static void drm_test_managed_release_action(struct kunit *test) +{ + struct managed_test_priv *priv = test->priv; + int ret; + + ret = drmm_add_action_or_reset(priv->drm, drm_action, priv); KUNIT_EXPECT_EQ(test, ret, 0); - ret = drm_dev_register(drm, 0); + ret = drm_dev_register(priv->drm, 0); KUNIT_ASSERT_EQ(test, ret, 0); - drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, dev); + drmm_release_action(priv->drm, drm_action, priv); + KUNIT_EXPECT_TRUE(test, priv->action_done); + priv->action_done = false; + + drm_dev_unregister(priv->drm); + drm_kunit_helper_free_device(test, priv->dev); ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done, msecs_to_jiffies(TEST_TIMEOUT_MS)); - KUNIT_EXPECT_GT(test, ret, 0); + KUNIT_EXPECT_EQ(test, ret, 0); +} + +static int drm_managed_test_init(struct kunit *test) +{ + struct managed_test_priv *priv; + + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); + init_waitqueue_head(&priv->action_wq); + + priv->dev = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev); + + priv->drm = __drm_kunit_helper_alloc_drm_device(test, priv->dev, sizeof(*priv->drm), + 0, DRIVER_MODESET); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm); + + test->priv = priv; + + return 0; } static struct kunit_case drm_managed_tests[] = { KUNIT_CASE(drm_test_managed_run_action), + KUNIT_CASE(drm_test_managed_release_action), {} }; static struct kunit_suite drm_managed_test_suite = { .name = "drm-test-managed", + .init = drm_managed_test_init, .test_cases = drm_managed_tests };