From nobody Mon Nov 25 07:26:33 2024 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86D235914C for ; Wed, 30 Oct 2024 02:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730255742; cv=none; b=ZyL3DtKL+M8VHgZQL1xehMBC3YNb+CZqrXwwSWBb3bQ1HUwMEvyQbcRwmS0D6WfMnw638rt8YegXYWLFDklr8r8ttnNdV5N/0PCNyevqfzr2I0tuVOjy42okbw7JGh8J+WhXYGkhw/EnoVZkhLo/APL6u/StjSZ1RFgrFwNkMTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730255742; c=relaxed/simple; bh=9dcIP93BiePbzq4pbcBadR0ez4bUj+6FWvB7SDdKC6o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MExzREq2oTxPstDeppct5O7MueWDbffIhMt/Bg4szPnOfV4V+P9ugJDrpLvsLGaMNpEa+j8iNCc5VicZr9IV29KsOro2IS2t/S4xPqEuoisRsxjdewFOd+Gn9eqGaA5J+ke25AVGAVbsSWVGS+LLH/ZAGGZBpPLc/Y1L9vnNe+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4XdWRd0Fq9z20qyn; Wed, 30 Oct 2024 10:34:37 +0800 (CST) Received: from kwepemg200008.china.huawei.com (unknown [7.202.181.35]) by mail.maildlp.com (Postfix) with ESMTPS id 020C81A0188; Wed, 30 Oct 2024 10:35:36 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemg200008.china.huawei.com (7.202.181.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 30 Oct 2024 10:35:35 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , CC: Subject: [PATCH v4 1/3] drm/tests: helpers: Add helper for drm_display_mode_from_cea_vic() Date: Wed, 30 Oct 2024 10:35:02 +0800 Message-ID: <20241030023504.530425-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241030023504.530425-1-ruanjinjie@huawei.com> References: <20241030023504.530425-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemg200008.china.huawei.com (7.202.181.35) Content-Type: text/plain; charset="utf-8" As Maxime suggested, add a new helper drm_kunit_display_mode_from_cea_vic(), it can replace the direct call of drm_display_mode_from_cea_vic(), and it will help solving the `mode` memory leaks. Acked-by: Maxime Ripard Suggested-by: Maxime Ripard Signed-off-by: Jinjie Ruan --- v4: - Return NULL early if drm_display_mode_from_cea_vic() return NULL, because it doesn't really make much sense to register a cleanup action if we know that it's going to be useless. v3: - Adjust drm/drm_edid.h header to drm_kunit_helpers.c. - Drop the "helper" in the helper name. - Add Acked-by. --- drivers/gpu/drm/tests/drm_kunit_helpers.c | 42 +++++++++++++++++++++++ include/drm/drm_kunit_helpers.h | 4 +++ 2 files changed, 46 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/te= sts/drm_kunit_helpers.c index aa62719dab0e..04a6b8cc62ac 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,47 @@ drm_kunit_helper_create_crtc(struct kunit *test, } EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc); =20 +static void kunit_action_drm_mode_destroy(void *ptr) +{ + struct drm_display_mode *mode =3D ptr; + + drm_mode_destroy(NULL, mode); +} + +/** + * drm_kunit_display_mode_from_cea_vic() - return a mode for CEA VIC + for a KUnit test + * @test: The test context object + * @dev: DRM device + * @video_code: CEA VIC of the mode + * + * Creates a new mode matching the specified CEA VIC for a KUnit test. + * + * Resources will be cleaned up automatically. + * + * Returns: A new drm_display_mode on success or NULL on failure + */ +struct drm_display_mode * +drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device = *dev, + u8 video_code) +{ + struct drm_display_mode *mode; + int ret; + + mode =3D drm_display_mode_from_cea_vic(dev, video_code); + if (!mode) + return NULL; + + ret =3D kunit_add_action_or_reset(test, + kunit_action_drm_mode_destroy, + mode); + if (ret) + return NULL; + + return mode; +} +EXPORT_SYMBOL_GPL(drm_kunit_display_mode_from_cea_vic); + MODULE_AUTHOR("Maxime Ripard "); MODULE_DESCRIPTION("KUnit test suite helper functions"); MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_kunit_helpers.h b/include/drm/drm_kunit_helper= s.h index e7cc17ee4934..afdd46ef04f7 100644 --- a/include/drm/drm_kunit_helpers.h +++ b/include/drm/drm_kunit_helpers.h @@ -120,4 +120,8 @@ drm_kunit_helper_create_crtc(struct kunit *test, const struct drm_crtc_funcs *funcs, const struct drm_crtc_helper_funcs *helper_funcs); =20 +struct drm_display_mode * +drm_kunit_display_mode_from_cea_vic(struct kunit *test, struct drm_device = *dev, + u8 video_code); + #endif // DRM_KUNIT_HELPERS_H_ --=20 2.34.1