public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Brian Norris <briannorris@chromium.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kunit-dev@googlegroups.com,  David Gow <davidgow@google.com>,
	Rae Moar <rmoar@google.com>,
	linux-kselftest@vger.kernel.org,
	 "Rafael J. Wysocki" <rafael@kernel.org>,
	Rob Herring <robh@kernel.org>
Subject: Re: [PATCH v2 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests
Date: Fri, 13 Dec 2024 12:59:57 +0100	[thread overview]
Message-ID: <20241213-athletic-strong-bumblebee-bfabf1@houat> (raw)
In-Reply-To: <20241212003201.2098123-4-briannorris@chromium.org>

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

Hi,

On Wed, Dec 11, 2024 at 04:31:41PM -0800, Brian Norris wrote:
> We recently updated these device_match*() (and therefore, various
> *find_device_by*()) functions to return a consistent 'false' value when
> trying to match a NULL handle. Add tests for this.
> 
> This provides regression-testing coverage for the sorts of bugs that
> underly commit 5c8418cf4025 ("PCI/pwrctrl: Unregister platform device
> only if one actually exists").
> 
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> 
> Changes in v2:
>  * Keep "devm" and "match" tests in separate suites
> 
>  drivers/base/test/platform-device-test.c | 42 +++++++++++++++++++++++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/base/test/platform-device-test.c b/drivers/base/test/platform-device-test.c
> index ea05b8785743..c8d4b0a385f2 100644
> --- a/drivers/base/test/platform-device-test.c
> +++ b/drivers/base/test/platform-device-test.c
> @@ -3,6 +3,8 @@
>  #include <kunit/resource.h>
>  
>  #include <linux/device.h>
> +#include <linux/device/bus.h>
> +#include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  
>  #define DEVICE_NAME "test"
> @@ -217,7 +219,45 @@ static struct kunit_suite platform_device_devm_test_suite = {
>  	.test_cases = platform_device_devm_tests,
>  };
>  
> -kunit_test_suite(platform_device_devm_test_suite);
> +static void platform_device_find_by_null_test(struct kunit *test)
> +{
> +	struct platform_device *pdev;
> +	int ret;
> +
> +	pdev = platform_device_alloc(DEVICE_NAME, PLATFORM_DEVID_NONE);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
> +
> +	ret = platform_device_add(pdev);
> +	KUNIT_ASSERT_EQ(test, ret, 0);

I *think* you have a bug there: if platform_device_add fails,
KUNIT_ASSERT will stop the test execution and thus you will leak the
platform_device you just allocated.

You need to call platform_device_put in such a case, but if
platform_device_add succeeds then you need to call
platform_device_unregister instead.

It would be better to use kunit_platform_device_alloc and
kunit_platform_device_add that already deal with this.

The rest looks good to me, once fixed:
Reviewed-by: Maxime Ripard <mripard@kernel.org>

Maxime

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

  reply	other threads:[~2024-12-13 11:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-12  0:31 [PATCH v2 0/3] drivers: base: Don't match device with NULL of_node/fwnode/etc + tests Brian Norris
2024-12-12  0:31 ` [PATCH v2 1/3] drivers: base: Don't match devices with NULL of_node/fwnode/etc Brian Norris
2024-12-13 14:38   ` Rafael J. Wysocki
2024-12-12  0:31 ` [PATCH v2 2/3] drivers: base: test: Enable device model tests with KUNIT_ALL_TESTS Brian Norris
2024-12-12  0:31 ` [PATCH v2 3/3] drivers: base: test: Add ...find_device_by...(... NULL) tests Brian Norris
2024-12-13 11:59   ` Maxime Ripard [this message]
2024-12-13 20:13     ` Brian Norris

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=20241213-athletic-strong-bumblebee-bfabf1@houat \
    --to=mripard@kernel.org \
    --cc=briannorris@chromium.org \
    --cc=davidgow@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rmoar@google.com \
    --cc=robh@kernel.org \
    /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