On Sun, 12 Jul 2026 18:59:04 +0200, Danilo Krummrich <[email protected]> said:
> On Fri Jul 10, 2026 at 3:51 PM CEST, Bartosz Golaszewski wrote:
>> Bartosz Golaszewski (5):
>>       kunit: provide a set of fwnode-oriented helpers
>>       software node: add fw_devlink support
>>       software node: add kunit tests for fw_devlink support
>>       MAINTAINERS: add myself as reviewer of software node support
>>       gpio: kunit: add test cases verifying swnode devlink support
>
> Overall looks good, but I think the two issues pointed out by Sashiko are 
> valid.
> In addition, I also found a memory leak in the gpiolib kunit test:
>
>       unreferenced object 0xffff88810296b2c0 (size 32):
>         comm "kunit_try_catch", pid 1096, jiffies 4294694235
>         hex dump (first 32 bytes):
>           00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>           66 6f 6f 00 00 00 00 00 00 00 00 00 00 00 00 00  foo.............
>         backtrace (crc a62f59c2):
>           __kmalloc_noprof+0x216/0x510
>           desc_set_label+0x46/0xc0
>           gpiod_request_commit+0xd5/0x140
>           gpiod_request+0x49/0x170
>           gpiod_find_and_request+0x2be/0x520
>           gpiod_get_index+0x56/0x70
>           devm_gpiod_get+0x1b/0x90
>           0xffffffffc0401ff8
>           platform_probe+0x58/0x90
>           really_probe+0x1bc/0x490
>           __driver_probe_device+0xa2/0x140
>           driver_probe_device+0x1e/0x110
>           __device_attach_driver+0xc2/0x140
>           bus_for_each_drv+0x117/0x170
>           __device_attach+0xd5/0x1c0
>           device_initial_probe+0x34/0x50
>
> I came up with the following diff to resolve those issues.
>
> diff --git a/drivers/base/test/swnode-devlink-test.c 
> b/drivers/base/test/swnode-devlink-test.c
> index 6f59f13214fc..143b9c4047a0 100644
> --- a/drivers/base/test/swnode-devlink-test.c
> +++ b/drivers/base/test/swnode-devlink-test.c
> @@ -17,6 +17,10 @@
>  #include <kunit/platform_device.h>
>  #include <kunit/test.h>
>
> +KUNIT_DEFINE_ACTION_WRAPPER(device_remove_software_node_wrapper,
> +                           device_remove_software_node,
> +                           struct device *);
> +
>  static int swnode_count_suppliers(struct fwnode_handle *fwnode)
>  {
>         struct fwnode_link *link;
> @@ -294,6 +298,9 @@ static void swnode_devlink_test_probe_order(struct kunit 
> *test)
>
>         ret = device_add_software_node(&supplier->dev, &supplier_swnode);
>         KUNIT_ASSERT_EQ(test, ret, 0);
> +       ret = kunit_add_action_or_reset(test, 
> device_remove_software_node_wrapper,
> +                                       &supplier->dev);
> +       KUNIT_ASSERT_EQ(test, ret, 0);
>         ret = device_create_managed_software_node(&consumer->dev,
>                                                   consumer_props, NULL);
>         KUNIT_ASSERT_EQ(test, ret, 0);
> @@ -313,8 +320,6 @@ static void swnode_devlink_test_probe_order(struct kunit 
> *test)
>
>         /* Tear down the consumer (and its device link) before the supplier. 
> */
>         kunit_platform_device_unregister(test, consumer);
> -
> -       device_remove_software_node(&supplier->dev);
>  }
>
>  static struct kunit_case swnode_test_cases[] = {
> diff --git a/drivers/gpio/gpiolib-kunit.c b/drivers/gpio/gpiolib-kunit.c
> index ad961cf97aee..7798f8a8e602 100644
> --- a/drivers/gpio/gpiolib-kunit.c
> +++ b/drivers/gpio/gpiolib-kunit.c
> @@ -449,6 +449,9 @@ static void 
> gpio_swnode_probe_defer_on_unregistered(struct kunit *test)
>
>         pdata = dev_get_platdata(&cons->dev);
>         KUNIT_ASSERT_EQ(test, pdata->gpio_err, 0);
> +
> +       /* Tear down the consumer before the provider to free the GPIO. */
> +       kunit_platform_device_unregister(test, cons);
>  }
>
>  static int gpio_swnode_probe_order_test_init(struct kunit *test)
> @@ -614,9 +617,17 @@ static struct kunit_case 
> gpio_unbind_with_consumers_tests[] = {
>         { }
>  };
>
> +static int gpio_unbind_test_init(struct kunit *test)
> +{
> +       device_link_wait_removal();

Interestingly I noticed this in the GPIO test cases but not here...

I also think that we should call device_link_wait_removal() *before* and
*after* these cases to not affect other test suites - as pointed out by
sashiko too.

Let me send a v4.

Bart

> +
> +       return 0;
> +}
> +
>  static struct kunit_suite gpio_unbind_with_consumers_test_suite = {
>         .name = "gpio-unbind-with-consumers",
>         .test_cases = gpio_unbind_with_consumers_tests,
> +       .init = gpio_unbind_test_init,
>  };
>
>  kunit_test_suites(
>

Reply via email to