The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Jinjie Ruan <ruanjinjie@huawei.com>
Cc: maarten.lankhorst@linux.intel.com, tzimmermann@suse.de,
	 airlied@gmail.com, simona@ffwll.ch, christian.koenig@amd.com,
	ray.huang@amd.com,  dmitry.baryshkov@linaro.org,
	dave.stevenson@raspberrypi.com, quic_jjohnson@quicinc.com,
	 mcanal@igalia.com, davidgow@google.com,
	skhan@linuxfoundation.org,  karolina.stolarek@intel.com,
	Arunpravin.PaneerSelvam@amd.com,
	 thomas.hellstrom@linux.intel.com, asomalap@amd.com,
	dri-devel@lists.freedesktop.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/4] drm/tests: helpers: Add helper for drm_display_mode_from_cea_vic()
Date: Tue, 29 Oct 2024 09:16:51 +0100	[thread overview]
Message-ID: <20241029-dancing-hissing-bullfrog-b6d0ed@houat> (raw)
In-Reply-To: <20241017063125.3080347-2-ruanjinjie@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 2583 bytes --]

On Thu, Oct 17, 2024 at 02:31:22PM +0800, Jinjie Ruan wrote:
> 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 <mripard@kernel.org>
> Suggested-by: Maxime Ripard <mripard@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
> 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 | 40 +++++++++++++++++++++++
>  include/drm/drm_kunit_helpers.h           |  4 +++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c
> index aa62719dab0e..565172990044 100644
> --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c
> +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c
> @@ -3,6 +3,7 @@
>  #include <drm/drm_atomic.h>
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_drv.h>
> +#include <drm/drm_edid.h>
>  #include <drm/drm_fourcc.h>
>  #include <drm/drm_kunit_helpers.h>
>  #include <drm/drm_managed.h>
> @@ -311,6 +312,45 @@ drm_kunit_helper_create_crtc(struct kunit *test,
>  }
>  EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc);
>  
> +static void kunit_action_drm_mode_destroy(void *ptr)
> +{
> +	struct drm_display_mode *mode = 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 = drm_display_mode_from_cea_vic(dev, video_code);

I'd rather return directly if mode is NULL here...

> +	ret = kunit_add_action_or_reset(test,
> +					kunit_action_drm_mode_destroy,
> +					mode);
> +	if (ret)
> +		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, and possibly be executed right
away.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]

  reply	other threads:[~2024-10-29  8:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17  6:31 [PATCH v3 0/4] drm/tests: Fix some memory leaks Jinjie Ruan
2024-10-17  6:31 ` [PATCH v3 1/4] drm/tests: helpers: Add helper for drm_display_mode_from_cea_vic() Jinjie Ruan
2024-10-29  8:16   ` Maxime Ripard [this message]
2024-10-30  1:48     ` Jinjie Ruan
2024-10-17  6:31 ` [PATCH v3 2/4] drm/connector: hdmi: Fix memory leak in drm_display_mode_from_cea_vic() Jinjie Ruan
2024-10-17  6:31 ` [PATCH v3 3/4] drm/ttm/tests: Fix memory leak in ttm_tt_simple_create() Jinjie Ruan
2024-10-17  6:31 ` [PATCH v3 4/4] drm/tests: hdmi: Fix memory leaks in drm_display_mode_from_cea_vic() Jinjie Ruan
2024-10-18  7:55 ` [PATCH v3 0/4] drm/tests: Fix some memory leaks Maxime Ripard
2024-10-18  8:07   ` Jinjie Ruan
2024-10-18  8:12   ` Jinjie Ruan
2024-10-23  1:35     ` Jinjie Ruan
2024-10-25 14:33       ` Maxime Ripard
2024-10-26  2:02         ` Jinjie Ruan
2024-10-29  8:15           ` Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241029-dancing-hissing-bullfrog-b6d0ed@houat \
    --to=mripard@kernel.org \
    --cc=Arunpravin.PaneerSelvam@amd.com \
    --cc=airlied@gmail.com \
    --cc=asomalap@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=davidgow@google.com \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karolina.stolarek@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mcanal@igalia.com \
    --cc=quic_jjohnson@quicinc.com \
    --cc=ray.huang@amd.com \
    --cc=ruanjinjie@huawei.com \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox